use of javax.script.Bindings in project es6draft by anba.
the class CompilableTest method compileStringWithContextAndSimpleBindings.
@Test
public void compileStringWithContextAndSimpleBindings() throws ScriptException {
CompiledScript script = compilable.compile("numberVal * 2");
ScriptContext context = new SimpleScriptContext();
Bindings bindings = new SimpleBindings();
bindings.put("numberVal", 9);
context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
assertThat(script.eval(context), instanceOfWith(Number.class, is(numberCloseTo(18))));
}
use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineScopeTest method explicitDefaultBindingsRetrieval.
@Test
public void explicitDefaultBindingsRetrieval() throws ScriptException {
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
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 bindingValueWithThisExplicitSimpleBinding.
@Test
public void bindingValueWithThisExplicitSimpleBinding() throws ScriptException {
Bindings binding = new SimpleBindings();
binding.put("value", "Sabik");
assertThat(engine.eval("this.value", binding), nullValue());
}
use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedBindings.
@Test
public void isolatedBindings() throws ScriptException {
Bindings binding = engine.createBindings();
engine.eval("var value = 'Betelgeuse'", binding);
assertThat(engine.eval("value", binding), instanceOfWith(String.class, is("Betelgeuse")));
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")));
}
use of javax.script.Bindings in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedBindingsWithContextAndSimpleBindings.
@Test
public void isolatedBindingsWithContextAndSimpleBindings() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
Bindings binding = new SimpleBindings();
context.setBindings(binding, ScriptContext.ENGINE_SCOPE);
engine.eval("var value = 'Zeta Scorpii'", context);
assertThat(engine.eval("value", context), instanceOfWith(String.class, is("Zeta Scorpii")));
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("Zeta Scorpii")));
}
Aggregations