use of javax.script.SimpleBindings 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.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 simpleBindingsAndEval.
@Test
public void simpleBindingsAndEval() throws ScriptException {
Bindings bindings = new SimpleBindings();
assertThat(bindings, notNullValue());
assertThat(bindings.entrySet(), is(empty()));
bindings.put("nullValue", null);
bindings.put("intValue", 1);
bindings.put("doubleValue", 1.5);
bindings.put("booleanValue", true);
bindings.put("stringValue", "Cepheus");
Object nullValue = engine.eval("nullValue", bindings);
Object intValue = engine.eval("intValue", bindings);
Object doubleValue = engine.eval("doubleValue", bindings);
Object stringValue = engine.eval("stringValue", bindings);
Object booleanValue = engine.eval("booleanValue", bindings);
assertThat(nullValue, nullValue());
assertThat(intValue, instanceOfWith(Number.class, is(numberCloseTo(1))));
assertThat(doubleValue, instanceOfWith(Number.class, is(numberCloseTo(1.5))));
assertThat(stringValue, instanceOfWith(String.class, is("Cepheus")));
assertThat(booleanValue, instanceOfWith(Boolean.class, sameInstance(Boolean.TRUE)));
}
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 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