use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method scopeInteractionNewContextSimpleBindingsPropertyAssignment.
@Test
public void scopeInteractionNewContextSimpleBindingsPropertyAssignment() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
context.setBindings(engine.getBindings(ScriptContext.GLOBAL_SCOPE), ScriptContext.GLOBAL_SCOPE);
context.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
context.setAttribute("value", "Phecda", ScriptContext.ENGINE_SCOPE);
context.setAttribute("value", "Scheat", ScriptContext.GLOBAL_SCOPE);
engine.eval("this.value = 'Aludra'", context);
assertThat(engine.eval("this.value", context), nullValue());
assertThat(engine.eval("value", context), instanceOfWith(String.class, is("Phecda")));
assertThat(context.getAttribute("value", ScriptContext.ENGINE_SCOPE), instanceOfWith(String.class, is("Phecda")));
assertThat(context.getAttribute("value", ScriptContext.GLOBAL_SCOPE), instanceOfWith(String.class, is("Scheat")));
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method bindingValueWithThisExplicitContextSimpleBindings.
@Test
public void bindingValueWithThisExplicitContextSimpleBindings() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
context.setAttribute("value", "Markeb", ScriptContext.ENGINE_SCOPE);
assertThat(engine.eval("this.value", context), nullValue());
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedContextsNoVarEvalDefault.
@Test
public void isolatedContextsNoVarEvalDefault() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
engine.eval("value = 'Rigel'");
assertThat(engine.eval("value"), instanceOfWith(String.class, is("Rigel")));
assertThat(engine.eval("typeof value", context), instanceOfWith(String.class, is("undefined")));
assertThat(engine.getContext().getAttribute("value"), instanceOfWith(String.class, is("Rigel")));
assertThat(context.getAttribute("value"), nullValue());
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedContextsEvalDefault.
@Test
public void isolatedContextsEvalDefault() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
engine.eval("var value = 'Sirius'");
assertThat(engine.eval("value"), instanceOfWith(String.class, is("Sirius")));
assertThat(engine.eval("typeof value", context), instanceOfWith(String.class, is("undefined")));
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method scopeInteractionNewContextGlobalAssignment.
@Test
public void scopeInteractionNewContextGlobalAssignment() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
context.setBindings(engine.getBindings(ScriptContext.GLOBAL_SCOPE), ScriptContext.GLOBAL_SCOPE);
context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
context.setAttribute("value", "Phecda", ScriptContext.ENGINE_SCOPE);
context.setAttribute("value", "Scheat", ScriptContext.GLOBAL_SCOPE);
engine.eval("value = 'Aludra'", context);
assertThat(engine.eval("this.value", context), instanceOfWith(String.class, is("Aludra")));
assertThat(engine.eval("value", context), instanceOfWith(String.class, is("Aludra")));
assertThat(context.getAttribute("value", ScriptContext.ENGINE_SCOPE), instanceOfWith(String.class, is("Aludra")));
assertThat(context.getAttribute("value", ScriptContext.GLOBAL_SCOPE), instanceOfWith(String.class, is("Scheat")));
}
Aggregations