use of javax.script.Bindings in project es6draft by anba.
the class CompilableTest method compileStringWithContextAndBindings.
@Test
public void compileStringWithContextAndBindings() throws ScriptException {
CompiledScript script = compilable.compile("numberVal * 2");
ScriptContext context = new SimpleScriptContext();
Bindings bindings = engine.createBindings();
bindings.put("numberVal", 8);
context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
assertThat(script.eval(context), instanceOfWith(Number.class, is(numberCloseTo(16))));
}
use of javax.script.Bindings in project es6draft by anba.
the class CompilableTest method compileStringWithBindings.
@Test
public void compileStringWithBindings() throws ScriptException {
CompiledScript script = compilable.compile("numberVal * 2");
Bindings bindings = engine.createBindings();
bindings.put("numberVal", 5);
assertThat(script.eval(bindings), instanceOfWith(Number.class, is(numberCloseTo(10))));
}
use of javax.script.Bindings in project es6draft by anba.
the class CompilableTest method compileStringWithSimpleBindings.
@Test
public void compileStringWithSimpleBindings() throws ScriptException {
CompiledScript script = compilable.compile("numberVal * 2");
Bindings bindings = new SimpleBindings();
bindings.put("numberVal", 6);
assertThat(script.eval(bindings), instanceOfWith(Number.class, is(numberCloseTo(12))));
}
use of javax.script.Bindings 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.Bindings in project es6draft by anba.
the class TypeConversionTest method testUnsupportedWithBindings.
@Test
public void testUnsupportedWithBindings() throws ScriptException {
// Unsupported Java classes end up as `null` in default bindings
Bindings bindings = engine.createBindings();
Object javaObject = new JavaObject();
bindings.put("javaObject", javaObject);
assertThat(bindings.get("javaObject"), nullValue());
assertThat(engine.eval("javaObject", bindings), nullValue());
assertThat(engine.eval("typeof javaObject", bindings), instanceOfWith(String.class, is("object")));
assertThat(engine.eval("javaObject == null", bindings), instanceOfWith(Boolean.class, sameInstance(Boolean.TRUE)));
assertThat(engine.eval("javaObject === void 0", bindings), instanceOfWith(Boolean.class, sameInstance(Boolean.FALSE)));
assertThat(engine.eval("javaObject === null", bindings), instanceOfWith(Boolean.class, sameInstance(Boolean.TRUE)));
}
Aggregations