@Override public Bindings getBindings(int scope) { return engine.getBindings(scope); }
@Override public Bindings getBindings(int scope) { return engine.getBindings(scope); }
@Override public Bindings getBindings(int scope) { return engine.getBindings(scope); }
@Override public Bindings getBindings(int scope) { return engine.getBindings(scope); }
private static void retrieveBindingVars(ScriptEngine self, Binding binding) { Set<Map.Entry<String, Object>> returnVars = self.getBindings(ScriptContext.ENGINE_SCOPE).entrySet(); for (Map.Entry<String, Object> me : returnVars) { binding.setVariable(me.getKey(), me.getValue()); } }
ScriptEngine createScriptEngine(String engine) { ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(engine); if (scriptEngine == null) { scriptEngine = scriptEngineManager.getEngineByExtension(engine); } if (scriptEngine == null) { scriptEngine = scriptEngineManager.getEngineByMimeType(engine); } Preconditions.notNull(scriptEngine, () -> "Script engine not found: " + engine); Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); bindings.put(Script.BIND_SYSTEM_PROPERTY, systemPropertyAccessor); bindings.put(Script.BIND_SYSTEM_ENVIRONMENT, environmentVariableAccessor); return scriptEngine; }
Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE); if (bindings == null) { bindings = new SimpleBindings();
Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE); if (bindings == null) { bindings = new SimpleBindings();
jsscope = jscx.getBindings( ScriptContext.ENGINE_SCOPE );
public class JS { public static void main(String args[]) throws Exception { ScriptEngine js = new ScriptEngineManager().getEngineByName("javascript"); Bindings bindings = js.getBindings(ScriptContext.ENGINE_SCOPE); bindings.put("stdout", System.out); js.eval("stdout.println(Math.cos(Math.PI));"); // Prints "-1.0" to the standard output stream. } }
data.scope = data.cx.getBindings( ScriptContext.ENGINE_SCOPE );
protected String toSvg(final String dotSource, int jsEngineMemorySize) { String fixed = fixPathsAndUrls(dotSource); try { scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("dotSource", fixed); return (String) scriptEngine.eval("Viz(dotSource,options = { totalMemory: "+jsEngineMemorySize +" , images: [" + "{ path: \"../../images/foreignKeys.png\"" + ICON_SIZE + " }," + "{ path: \"../../images/primaryKeys.png\"" + ICON_SIZE + " }]})"); } catch (ScriptException e) { throw new IllegalArgumentException(e); } }
private static void retrieveBindingVars(ScriptEngine self, Binding binding) { Set<Map.Entry<String, Object>> returnVars = self.getBindings(ScriptContext.ENGINE_SCOPE).entrySet(); for (Map.Entry<String, Object> me : returnVars) { binding.setVariable(me.getKey(), me.getValue()); } }
import java.util.*; import javax.script.*; public class TestBindings { public static void main(String args[]) throws Exception { String script = "function doSomething() {var d = date}"; ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); Compilable compilingEngine = (Compilable) engine; CompiledScript cscript = compilingEngine.compile(script); //Bindings bindings = cscript.getEngine().createBindings(); Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); for(Map.Entry me : bindings.entrySet()) { System.out.printf("%s: %s\n",me.getKey(),String.valueOf(me.getValue())); } bindings.put("date", new Date()); //cscript.eval(); cscript.eval(bindings); Invocable invocable = (Invocable) cscript.getEngine(); invocable.invokeFunction("doSomething"); } }
Bindings b = engine.getBindings(ScriptContext.ENGINE_SCOPE); putConnector(b, shellState.getAccumuloClient()); b.put("client", shellState.getAccumuloClient());
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
private List<String> engineVariablesCompleter(final String code, @SuppressWarnings("unused") final int index, final ScriptEngine engine) { final List<String> matches = new ArrayList<>(); final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); for (final String key : bindings.keySet()) { if (key.toLowerCase().startsWith(code.toLowerCase())) { matches.add(key); } } return matches; }
/** * {@inheritDoc} */ public Bindings getBindings(int scope) { return getScriptEngine().getBindings(scope); }
NashornRuntimeImpl( final ScriptEngine engine ) { this.engine = engine; final Bindings bindings = this.engine.getBindings( ScriptContext.ENGINE_SCOPE ); this.arrayProto = (ScriptObjectMirror) bindings.get( "Array" ); this.objectProto = (ScriptObjectMirror) bindings.get( "Object" ); this.jsonProto = (ScriptObjectMirror) bindings.get( "JSON" ); }
public Object eval(Bindings bindings) throws ScriptException { Bindings oldBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE); try { return eval(engine.getContext()); } finally { engine.setBindings(oldBindings, ScriptContext.ENGINE_SCOPE); } }