use of javax.script.SimpleBindings 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.SimpleBindings in project es6draft by anba.
the class ScriptEngineScopeTest method isolatedBindingsWithContextAndSimpleBindings.
@Test
public void isolatedBindingsWithContextAndSimpleBindings() throws ScriptException {
ScriptContext context = new SimpleScriptContext();
Bindings binding = new SimpleBindings();
context.setBindings(binding, ScriptContext.ENGINE_SCOPE);
engine.eval("var value = 'Zeta Scorpii'", context);
assertThat(engine.eval("value", context), instanceOfWith(String.class, is("Zeta Scorpii")));
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("Zeta Scorpii")));
}
use of javax.script.SimpleBindings 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.SimpleBindings in project es6draft by anba.
the class ScriptEngineScopeTest method globalScopeAccessWithOverrideNewContextSimpleBindings.
@Test
public void globalScopeAccessWithOverrideNewContextSimpleBindings() throws ScriptException {
Bindings globalScope = engine.getBindings(ScriptContext.GLOBAL_SCOPE);
globalScope.put("globalVar", "Becrux");
ScriptContext context = new SimpleScriptContext();
context.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
context.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
context.getBindings(ScriptContext.ENGINE_SCOPE).put("globalVar", "Antares");
assertThat(engine.eval("globalVar", context), instanceOfWith(String.class, is("Antares")));
engine.getBindings(ScriptContext.ENGINE_SCOPE).remove("globalVar");
assertThat(engine.eval("globalVar"), instanceOfWith(String.class, is("Becrux")));
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class Scripted method process.
/**
* {@inheritDoc}
*/
@Override
public int process(Callback[] callbacks, int state) throws LoginException {
switch(state) {
case ISAuthConstants.LOGIN_START:
substituteUIStrings();
return STATE_RUN_SCRIPT;
case STATE_RUN_SCRIPT:
Bindings scriptVariables = new SimpleBindings();
scriptVariables.put(REQUEST_DATA_VARIABLE_NAME, getScriptHttpRequestWrapper());
String clientScriptOutputData = getClientScriptOutputData(callbacks);
scriptVariables.put(CLIENT_SCRIPT_OUTPUT_DATA_VARIABLE_NAME, clientScriptOutputData);
scriptVariables.put(LOGGER_VARIABLE_NAME, DEBUG);
scriptVariables.put(STATE_VARIABLE_NAME, state);
scriptVariables.put(SHARED_STATE, sharedState);
scriptVariables.put(USERNAME_VARIABLE_NAME, userName);
scriptVariables.put(SUCCESS_ATTR_NAME, SUCCESS_VALUE);
scriptVariables.put(FAILED_ATTR_NAME, FAILURE_VALUE);
scriptVariables.put(HTTP_CLIENT_VARIABLE_NAME, httpClient);
scriptVariables.put(IDENTITY_REPOSITORY, identityRepository);
try {
scriptEvaluator.evaluateScript(getServerSideScript(), scriptVariables);
} catch (ScriptException e) {
DEBUG.message("Error running server side scripts", e);
throw new AuthLoginException("Error running script", e);
}
state = ((Number) scriptVariables.get(STATE_VARIABLE_NAME)).intValue();
userName = (String) scriptVariables.get(USERNAME_VARIABLE_NAME);
sharedState.put(CLIENT_SCRIPT_OUTPUT_DATA_VARIABLE_NAME, clientScriptOutputData);
if (state != SUCCESS_VALUE) {
throw new AuthLoginException("Authentication failed");
}
return state;
default:
throw new AuthLoginException("Invalid state");
}
}
Aggregations