use of javax.script.SimpleBindings in project es6draft by anba.
the class ScriptEngineScopeTest method simpleBindingsRetrieval.
@Test
public void simpleBindingsRetrieval() throws ScriptException {
Bindings bindings = new SimpleBindings();
engine.eval("var a = 0; b = 3", bindings);
assertThat(bindings.get("a"), instanceOfWith(Number.class, is(numberCloseTo(0))));
assertThat(bindings.get("b"), nullValue());
}
use of javax.script.SimpleBindings in project es6draft by anba.
the class ScriptEngineScopeTest method accessToBuiltinsNonSharedSimpleBindings.
@Test
public void accessToBuiltinsNonSharedSimpleBindings() throws ScriptException {
Object defaultObject = engine.eval("Object");
Object bindingsObject = engine.eval("Object", new SimpleBindings());
assertThat(defaultObject, notNullValue());
assertThat(bindingsObject, notNullValue());
assertThat(defaultObject, Matchers.not(sameInstance(bindingsObject)));
}
use of javax.script.SimpleBindings in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedBindingsWithContext.
@Test
public void isolatedBindingsWithContext() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
Bindings binding = engine.createBindings();
context.setBindings(binding, ScriptContext.ENGINE_SCOPE);
engine.eval("var value = 'Alnilam'", context);
assertThat(engine.eval("value", context), instanceOfWith(String.class, is("Alnilam")));
context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
assertThat(engine.eval("typeof value", context), instanceOfWith(String.class, is("undefined")));
context.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
assertThat(engine.eval("typeof value", context), instanceOfWith(String.class, is("undefined")));
context.setBindings(binding, ScriptContext.ENGINE_SCOPE);
assertThat(engine.eval("value", context), instanceOfWith(String.class, is("Alnilam")));
}
use of javax.script.SimpleBindings in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessNewContextWithGlobalSimpleBindings.
@Test
public void globalScopeAccessNewContextWithGlobalSimpleBindings() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Sigma Sagittarii");
ScriptContext context = new SimpleScriptContext();
context.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
context.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
assertThat(engine.eval("globalVar", context), instanceOfWith(String.class, is("Sigma Sagittarii")));
}
use of javax.script.SimpleBindings in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedBindingsAndSimpleBindings.
@Test
public void isolatedBindingsAndSimpleBindings() throws ScriptException {
Bindings binding = new SimpleBindings();
engine.eval("var value = 'Alnitak'", binding);
assertThat(engine.eval("value", binding), instanceOfWith(String.class, is("Alnitak")));
assertThat(engine.eval("typeof value"), instanceOfWith(String.class, is("undefined")));
assertThat(engine.eval("typeof value", engine.createBindings()), instanceOfWith(String.class, is("undefined")));
assertThat(engine.eval("typeof value", new SimpleBindings()), instanceOfWith(String.class, is("undefined")));
}
Aggregations