Examples of Require


Examples of org.mozilla.javascript.commonjs.module.Require

    private Require getSandboxedRequire(final Context cx) throws URISyntaxException {
        return getSandboxedRequire(cx, cx.initStandardObjects(), true);
    }

    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);
    }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

                ExitCallbackExecutor exitCallbackExecutor = new ExitCallbackExecutor();

                Scriptable envAsScriptable = mapToScriptable(ctx, global, env);

                Require require = global.installNodeJsRequire(ctx, envAsScriptable, nodeModuleProvider,
                        new NodeRequireBuilder(asyncFunctionQueue, exitCallbackExecutor), false);

                //TODO Get a real buffer here...
                ScriptableObject.putProperty(global, "Buffer", Context.javaToJS(ctx.newObject(global), global));
                Scriptable buffer = (Scriptable) require.call(ctx, global, global, new Object[]{Context.javaToJS("buffer", global)});
                ScriptableObject.putProperty(global, "Buffer", ScriptableObject.getProperty(buffer,"Buffer"));

                Scriptable console = consoleProvider.getConsoleAsScriptable(global);
                ScriptableObject.putProperty(global, "console", console);
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

        NodeJsUrlModuleSourceProvider moduleSourceProvider = new NodeJsUrlModuleSourceProvider(uris);
        rb.setModuleScriptProvider(
                new SoftCachingModuleScriptProvider(
                        moduleSourceProvider));

        Require require = rb.createRequire(cx, env, this);
        require.install(this);
        return require;
    }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

public class RequireTest extends TestCase
{
    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
        }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

    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");
    }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

    }

    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);
    }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

    }

    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");
        }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

    }
   
    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);
    }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

    }
   
    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);
    }
View Full Code Here

Examples of org.mozilla.javascript.commonjs.module.Require

            }
        }
        rb.setModuleScriptProvider(
                new SoftCachingModuleScriptProvider(
                        new UrlModuleSourceProvider(uris, null)));
        Require require = rb.createRequire(cx, this);
        require.install(this);
        return require;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.