public static Module enable(NashornScriptEngine engine, Folder folder, Bindings bindings) throws ScriptException { Bindings module = engine.createBindings(); Bindings exports = engine.createBindings(); Module created = new Module(engine, folder, new ModuleCache(), "<main>", module, exports, null, null); created.setLoaded(); bindings.put("require", created); bindings.put("module", module); bindings.put("exports", exports); return created; } }
public static Module enable(NashornScriptEngine engine, Folder folder, Bindings bindings) throws ScriptException { Bindings module = engine.createBindings(); Bindings exports = engine.createBindings(); Module created = new Module(engine, folder, new ModuleCache(), "<main>", module, exports, null, null); created.setLoaded(); bindings.put("require", created); bindings.put("module", module); bindings.put("exports", exports); return created; } }
protected Bindings initEvalBindings(Map<String,Object> vars) throws ScriptException { Bindings bindings = engine.createBindings(); //global bindings.put("$global", globalVars); bindings.putAll(globalVars); //engine bindings.put("$engine", engineVars); bindings.putAll(engineVars); //context Map<String, Object> context = contextVariables.get(); if(null != context) { bindings.put("$context", context); bindings.putAll(context); } //provider for(JsVariableProvider vp : variableProviders) { vp.initScriptVariables(this, bindings); } //variables if(null != vars) { bindings.putAll(vars); } return bindings; }
/** * Public only for tests */ public void initSpaceGlobal() { Bindings bindings = SCRIPT_ENGINE.createBindings(); scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE); try { setSpace(Space.this); try { scriptContext.setAttribute(ScriptEngine.FILENAME, INTERNALS_MODULENAME, ScriptContext.ENGINE_SCOPE); SCRIPT_ENGINE.eval(new URLReader(internalsUrl), scriptContext); } finally { setSpace(null); } } catch (ScriptException ex) { Logger.getLogger(Scripts.class.getName()).log(Level.SEVERE, null, ex); } }