/** * Creates a new require() function. You are still responsible for invoking * either {@link Require#install(Scriptable)} or * {@link Require#requireMain(Context, String)} to effectively make it * available to its JavaScript program. * @param cx the current context * @param globalScope the global scope containing the JS standard natives. * @return a new Require instance. */ public Require createRequire(Context cx, Scriptable globalScope) { return new Require(cx, globalScope, moduleScriptProvider, preExec, postExec, sandboxed); } }
/** * Creates a new require() function. You are still responsible for invoking * either {@link Require#install(Scriptable)} or * {@link Require#requireMain(Context, String)} to effectively make it * available to its JavaScript program. * @param cx the current context * @param globalScope the global scope containing the JS standard natives. * @return a new Require instance. */ public Require createRequire(Context cx, Scriptable globalScope) { return new Require(cx, globalScope, moduleScriptProvider, preExec, postExec, sandboxed); } }
/** * Creates a new require() function. You are still responsible for invoking * either {@link Require#install(Scriptable)} or * {@link Require#requireMain(Context, String)} to effectively make it * available to its JavaScript program. * @param cx the current context * @param globalScope the global scope containing the JS standard natives. * @return a new Require instance. */ public Require createRequire(Context cx, Scriptable globalScope) { return new Require(cx, globalScope, moduleScriptProvider, preExec, postExec, sandboxed); } }
/** * Creates a new require() function. You are still responsible for invoking * either {@link Require#install(Scriptable)} or * {@link Require#requireMain(Context, String)} to effectively make it * available to its JavaScript program. * @param cx the current context * @param globalScope the global scope containing the JS standard natives. * @return a new Require instance. */ public Require createRequire(Context cx, Scriptable globalScope) { return new Require(cx, globalScope, moduleScriptProvider, preExec, postExec, sandboxed); } }
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, sandboxed); }
private void init(final Class<?> clazz) { final Context context = Context.enter(); context.setOptimizationLevel(this.optimizationLevel); context.setLanguageVersion(Context.VERSION_1_7); final ScriptableObject scope = context.initStandardObjects(); final Require require = new Require(Context.getCurrentContext(), scope, getModuleScriptProvider(clazz), null, null, false); require.install(scope); try { this.moduleScope = new ModuleScope(scope, new URI("./" + this.name), null); } catch (final URISyntaxException e) { throw new SmallerException("Failed to create moduleScope", e); } addGlobalFunction("print", LOGGER, "info"); }