use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedContextsEvalContextWithDefaults.
@Test
public void isolatedContextsEvalContextWithDefaults() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
engine.eval("var value = 'Arcturus'", context);
assertThat(engine.eval("value", context), instanceOfWith(String.class, is("Arcturus")));
assertThat(engine.eval("typeof value"), instanceOfWith(String.class, is("undefined")));
assertThat(engine.eval("typeof value", new SimpleScriptContext()), instanceOfWith(String.class, is("undefined")));
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method accessToBuiltinsNonSharedContext.
@Test
public void accessToBuiltinsNonSharedContext() throws ScriptException {
Object defaultObject = engine.eval("Object");
Object contextObject = engine.eval("Object", new SimpleScriptContext());
assertThat(defaultObject, notNullValue());
assertThat(contextObject, notNullValue());
assertThat(defaultObject, Matchers.not(sameInstance(contextObject)));
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessNewEmptyContext.
@Test
public void globalScopeAccessNewEmptyContext() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Gacrux");
assertThat(engine.eval("typeof globalVar", new SimpleScriptContext()), instanceOfWith(String.class, is("undefined")));
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessNewContextWithGlobal.
@Test
public void globalScopeAccessNewContextWithGlobal() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Achernar");
ScriptContext context = new SimpleScriptContext();
context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
context.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
assertThat(engine.eval("globalVar", context), instanceOfWith(String.class, is("Achernar")));
}
use of javax.script.SimpleScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method scopeInteractionNewContextPropertyAssignment.
@Test
public void scopeInteractionNewContextPropertyAssignment() 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("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")));
}
Aggregations