当前位置: 首页>>代码示例>>Java>>正文


Java Require类代码示例

本文整理汇总了Java中org.mozilla.javascript.commonjs.module.Require的典型用法代码示例。如果您正苦于以下问题:Java Require类的具体用法?Java Require怎么用?Java Require使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Require类属于org.mozilla.javascript.commonjs.module包,在下文中一共展示了Require类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSandboxed

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void testSandboxed() throws Exception
{
    final Context cx = createContext();
    final Require require = getSandboxedRequire(cx);
    require.requireMain(cx, "testSandboxed");
    // Also, test idempotent double-require of same main:
    require.requireMain(cx, "testSandboxed");
    // Also, test failed require of different main:
    try {
        require.requireMain(cx, "blah");
        fail();
    }
    catch(IllegalStateException e) {
        // Expected, success
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:17,代码来源:RequireTest.java

示例2: testSandboxed

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
@Override
public void testSandboxed() throws Exception
{
    final Context cx = createContext();
    final Require require = getSandboxedRequire(cx);
    require.requireMain(cx, "testSandboxed");
    // Also, test idempotent double-require of same main:
    require.requireMain(cx, "testSandboxed");
    // Also, test failed require of different main:
    try {
        require.requireMain(cx, "blah");
        fail();
    }
    catch(IllegalStateException e) {
        // Expected, success
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:18,代码来源:RequireJarTest.java

示例3: testSetMainForAlreadyLoadedModule

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
@Override
public void testSetMainForAlreadyLoadedModule() throws Exception {
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    require.install(scope);
    cx.evaluateReader(scope, getReader("testSetMainForAlreadyLoadedModule.js"), 
            "testSetMainForAlreadyLoadedModule.js", 1, null);
    try {
        require.requireMain(cx, "assert");
        fail();
    }
    catch(IllegalStateException e) {
        assertEquals(e.getMessage(), "Attempt to set main module after it was loaded");
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:17,代码来源:RequireJarTest.java

示例4: runfile

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public static void runfile(File file,
                           String filename,
                           boolean enableRetry,
                           String retryFile) throws Exception {
    Context ctx = Context.enter();
    ctx.putThreadLocal("SCRIPT_PATH", file.getAbsoluteFile().getParent());

    ScriptableObject scope = ctx.initStandardObjects();

    NativeExecutionContext executionContext = initializeNativeExecutionContext(
            file,
            enableRetry,
            retryFile,
            ctx);

    scope.putConst("context", scope, javaToJS(executionContext, scope));

    ctx.setLanguageVersion(VERSION_1_8);
    Require require = new RequireBuilder()
            .setModuleScriptProvider(new SoftCachingModuleScriptProvider(new NativeModuleSourceProvider()))
            .createRequire(ctx, scope);
    require.install(scope);
    require.requireMain(ctx, filename);
}
 
开发者ID:rec-framework,项目名称:rec-core,代码行数:25,代码来源:Scripting.java

示例5: loadModulesFromIncludeDirs

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
private static void loadModulesFromIncludeDirs(Context cx, Scriptable scope, List<File> requireDirList)
{
    List<URI> uris = new ArrayList<URI>();
    for (File dir : requireDirList) {
        URI uri = dir.toURI();
        uris.add(uri);
        continue;
    }
    if (uris.isEmpty()) {
        return;
    }
    RequireBuilder rb = new RequireBuilder();
    rb.setModuleScriptProvider(new SoftCachingModuleScriptProvider(
            new UrlModuleSourceProvider(uris, null)));
    Require require = rb.createRequire(cx, scope);
    require.install(scope);
    return;
}
 
开发者ID:gmrodrigues,项目名称:JsSandbox,代码行数:19,代码来源:JsSandboxEvaluators.java

示例6: init

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void init() throws URISyntaxException {
	ctx = Context.enter();
	try {
		RequireBuilder builder = new RequireBuilder();
		builder.setModuleScriptProvider(new SoftCachingModuleScriptProvider(
				new UrlModuleSourceProvider(buildModulePaths(), null)));

		topLevelScope = ctx.initStandardObjects();
		builder.setSandboxed(false); // allows this to load scripts
		Require require = builder.createRequire(ctx, topLevelScope);

		exports = require.requireMain(ctx, jsxTransformerJS);
		transform = (Function) exports.get("transform", topLevelScope);
	} finally {
		Context.exit();
	}
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:18,代码来源:JSXTransformer.java

示例7: installRequire

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public Require installRequire(Context cx, List<String> modulePath,
                              boolean sandboxed) {
    RequireBuilder rb = new RequireBuilder();
    rb.setSandboxed(sandboxed);
    List<URI> uris = new ArrayList<URI>();
    if (modulePath != null) {
        for (String path : modulePath) {
            try {
                URI uri = new URI(path);
                if (!uri.isAbsolute()) {
                    // call resolve("") to canonify the path
                    uri = new File(path).toURI().resolve("");
                }
                if (!uri.toString().endsWith("/")) {
                    // make sure URI always terminates with slash to
                    // avoid loading from unintended locations
                    uri = new URI(uri + "/");
                }
                uris.add(uri);
            } catch (URISyntaxException usx) {
                throw new RuntimeException(usx);
            }
        }
    }
    rb.setModuleScriptProvider(
            new SoftCachingModuleScriptProvider(
                    new UrlModuleSourceProvider(uris, null)));
    Require require = rb.createRequire(cx, this);
    require.install(this);
    return require;
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:32,代码来源:Global.java

示例8: testNonSandboxed

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void testNonSandboxed() throws Exception
{
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm();
    ScriptableObject.putProperty(scope, "moduleUri", jsFile);
    require.requireMain(cx, "testNonSandboxed");
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:10,代码来源:RequireTest.java

示例9: testRelativeId

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void testRelativeId() throws Exception {
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    require.install(scope);
    cx.evaluateReader(scope, getReader("testRelativeId.js"), 
            "testRelativeId.js", 1, null);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:9,代码来源:RequireTest.java

示例10: testSetMainForAlreadyLoadedModule

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void testSetMainForAlreadyLoadedModule() throws Exception {
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    require.install(scope);
    cx.evaluateReader(scope, getReader("testSetMainForAlreadyLoadedModule.js"), 
            "testSetMainForAlreadyLoadedModule.js", 1, null);
    try {
        require.requireMain(cx, "assert");
        fail();
    }
    catch(IllegalStateException e) {
        assertEquals(e.getMessage(), "Attempt to set main module after it was loaded");
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:16,代码来源:RequireTest.java

示例11: getSandboxedRequire

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
private Require getSandboxedRequire(Context cx, Scriptable scope, boolean sandboxed)
        throws URISyntaxException
{
    return new Require(cx, cx.initStandardObjects(), 
            new StrongCachingModuleScriptProvider(
                    new UrlModuleSourceProvider(Collections.singleton(
                            getDirectory()), null)), null, null, true);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:9,代码来源:RequireTest.java

示例12: createRequire

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
private static Require createRequire(File dir, Context cx, Scriptable scope) 
throws URISyntaxException 
{
    return new Require(cx, scope, new StrongCachingModuleScriptProvider(
            new UrlModuleSourceProvider(Collections.singleton(new URI(
                    "file:" + dir.getAbsolutePath().replace(File.separatorChar,'/') + "/")), 
                    Collections.singleton(new URI(ComplianceTest.class.getResource(".").toExternalForm() + "/")))),
                    null, null, false);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:10,代码来源:ComplianceTest.java

示例13: testSandboxed

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void testSandboxed() throws Exception {
    final Context cx = createContext();
    final Require require = getSandboxedRequire(cx);
    require.requireMain(cx, "testSandboxed");
    // Also, test idempotent double-require of same main:
    require.requireMain(cx, "testSandboxed");
    // Also, test failed require of different main:
    try {
        require.requireMain(cx, "blah");
        fail();
    } catch (IllegalStateException e) {
        // Expected, success
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:15,代码来源:RequireTest.java

示例14: testNonSandboxed

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void testNonSandboxed() throws Exception {
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    final String jsFile = TestUtils.readAsset(dir + File.separator + "testNonSandboxed.js");
    ScriptableObject.putProperty(scope, "moduleUri", jsFile);
    require.requireMain(cx, "testNonSandboxed");
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:9,代码来源:RequireTest.java

示例15: testRelativeId

import org.mozilla.javascript.commonjs.module.Require; //导入依赖的package包/类
public void testRelativeId() throws Exception {
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    require.install(scope);
    cx.evaluateString(scope, TestUtils.readAsset(dir + File.separator + "testRelativeId.js"),
            "testRelativeId.js", 1, null);
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:9,代码来源:RequireTest.java


注:本文中的org.mozilla.javascript.commonjs.module.Require类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。