use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineTest method contextAndBindings.
@Test
public void contextAndBindings() {
ScriptContext context = engine.getContext();
assertThat(context, notNullValue());
assertThat(context, sameInstance(engine.getContext()));
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
assertThat(globalScope, notNullValue());
assertThat(globalScope, sameInstance(engine.getBindings(ScriptContext.GLOBAL_SCOPE)));
assertThat(globalScope, sameInstance(context.getBindings(ScriptContext.GLOBAL_SCOPE)));
assertThat(globalScope, sameInstance(manager.getBindings()));
Bindings engineScope = engine.getBindings(ScriptContext.ENGINE_SCOPE);
assertThat(engineScope, notNullValue());
assertThat(engineScope, sameInstance(engine.getBindings(ScriptContext.ENGINE_SCOPE)));
assertThat(engineScope, sameInstance(context.getBindings(ScriptContext.ENGINE_SCOPE)));
assertThat(engineScope, not(sameInstance(manager.getBindings())));
}
use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessWithOverrideNewContextSimpleBindings.
@Test
public void globalScopeAccessWithOverrideNewContextSimpleBindings() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Becrux");
ScriptContext context = new SimpleScriptContext();
context.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
context.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
context.getBindings(ScriptContext.ENGINE_SCOPE).put("globalVar", "Antares");
assertThat(engine.eval("globalVar", context), instanceOfWith(String.class, is("Antares")));
engine.getBindings(ScriptContext.ENGINE_SCOPE).remove("globalVar");
assertThat(engine.eval("globalVar"), instanceOfWith(String.class, is("Becrux")));
}
use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineScopeTest method createBindingsRetrieval.
@Test
public void createBindingsRetrieval() throws ScriptException {
Bindings bindings = engine.createBindings();
engine.eval("var a = 0; b = 1", bindings);
assertThat(bindings.get("a"), instanceOfWith(Number.class, is(numberCloseTo(0))));
assertThat(bindings.get("b"), instanceOfWith(Number.class, is(numberCloseTo(1))));
}
use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessWithOverrideNewContext.
@Test
public void globalScopeAccessWithOverrideNewContext() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Canopus");
ScriptContext context = new SimpleScriptContext();
context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
context.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
context.getBindings(ScriptContext.ENGINE_SCOPE).put("globalVar", "Acrux");
assertThat(engine.eval("globalVar", context), instanceOfWith(String.class, is("Acrux")));
engine.getBindings(ScriptContext.ENGINE_SCOPE).remove("globalVar");
assertThat(engine.eval("globalVar"), instanceOfWith(String.class, is("Canopus")));
}
use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessWithOverride.
@Test
public void globalScopeAccessWithOverride() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Bellatrix");
engine.getBindings(ScriptContext.ENGINE_SCOPE).put("globalVar", "Eta Centauri");
assertThat(engine.eval("globalVar"), instanceOfWith(String.class, is("Eta Centauri")));
engine.getBindings(ScriptContext.ENGINE_SCOPE).remove("globalVar");
assertThat(engine.eval("globalVar"), instanceOfWith(String.class, is("Bellatrix")));
}
Aggregations