use of javax.script.ScriptContext in project zaproxy by zaproxy.
the class ScriptVarsUnitTest method shouldClearScriptVariableWithNullValueUsingScriptContext.
@Test
void shouldClearScriptVariableWithNullValueUsingScriptContext() {
// Given
String key = createKey();
String value = createValue();
String scriptName = "ScriptName";
ScriptContext scriptContext = createScriptContextWithName(scriptName);
ScriptVars.setScriptVar(scriptContext, key, value);
// When
ScriptVars.setScriptVar(scriptContext, key, null);
// Then
assertThat(ScriptVars.getScriptVars(scriptName), not(hasEntry(key, value)));
assertThat(ScriptVars.getScriptVar(scriptContext, key), is(nullValue()));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class CompilableTest method compileStringWithContextAndSimpleBindings.
@Test
public void compileStringWithContextAndSimpleBindings() throws ScriptException {
CompiledScript script = compilable.compile("numberVal * 2");
ScriptContext context = new SimpleScriptContext();
Bindings bindings = new SimpleBindings();
bindings.put("numberVal", 9);
context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
assertThat(script.eval(context), instanceOfWith(Number.class, is(numberCloseTo(18))));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class ScriptEngineTest method evalExplicitContext.
@Test
public void evalExplicitContext() throws ScriptException {
ScriptContext context = engine.getContext();
assertThat(context, notNullValue());
Object value = engine.eval("function f() { return 'vvv' } f()", context);
assertThat(value, instanceOfWith(String.class, is("vvv")));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class ScriptEngineTest method contextAndBindings.
@Test
public void contextAndBindings() {
ScriptContext context = engine.getContext();
assertThat(context, notNullValue());
assertThat(context, sameInstance(engine.getContext()));
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
assertThat(globalScope, notNullValue());
assertThat(globalScope, sameInstance(engine.getBindings(ScriptContext.GLOBAL_SCOPE)));
assertThat(globalScope, sameInstance(context.getBindings(ScriptContext.GLOBAL_SCOPE)));
assertThat(globalScope, sameInstance(manager.getBindings()));
Bindings engineScope = engine.getBindings(ScriptContext.ENGINE_SCOPE);
assertThat(engineScope, notNullValue());
assertThat(engineScope, sameInstance(engine.getBindings(ScriptContext.ENGINE_SCOPE)));
assertThat(engineScope, sameInstance(context.getBindings(ScriptContext.ENGINE_SCOPE)));
assertThat(engineScope, not(sameInstance(manager.getBindings())));
}
use of javax.script.ScriptContext in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessWithOverrideNewContext.
@Test
public void globalScopeAccessWithOverrideNewContext() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Canopus");
ScriptContext context = new SimpleScriptContext();
context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
context.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
context.getBindings(ScriptContext.ENGINE_SCOPE).put("globalVar", "Acrux");
assertThat(engine.eval("globalVar", context), instanceOfWith(String.class, is("Acrux")));
engine.getBindings(ScriptContext.ENGINE_SCOPE).remove("globalVar");
assertThat(engine.eval("globalVar"), instanceOfWith(String.class, is("Canopus")));
}
Aggregations