use of javax.script.ScriptContext 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")));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method scopeInteractionDefaultContextGlobalAssignment.
@Test
public void scopeInteractionDefaultContextGlobalAssignment() throws ScriptException {
ScriptContext context = engine.getContext();
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")));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method scopeInteractionNewContextSimpleBindingsGlobalAssignment.
@Test
public void scopeInteractionNewContextSimpleBindingsGlobalAssignment() 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("value = 'Aludra'", context);
assertThat(engine.eval("this.value", context), nullValue());
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")));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method scopeInteractionDefaultContextPropertyAssignment.
@Test
public void scopeInteractionDefaultContextPropertyAssignment() throws ScriptException {
ScriptContext context = engine.getContext();
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), 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")));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method bindingValueWithThisExplicitContext.
@Test
public void bindingValueWithThisExplicitContext() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
context.setAttribute("value", "Markab", ScriptContext.ENGINE_SCOPE);
assertThat(engine.eval("this.value", context), instanceOfWith(String.class, is("Markab")));
}
Aggregations