use of org.mozilla.javascript.Scriptable in project backstage by zepheira.
the class Context method generateLens.
public Scriptable generateLens(String itemID) {
_logger.debug("> generateLens");
String key = "lens-rendering:" + itemID;
_logger.debug("itemID: " + key);
Scriptable result = (Scriptable) getDatabase().cacheAndRun(key, new LensRenderingCacheableQuery(itemID));
_logger.debug("< generateLens");
return result;
}
use of org.mozilla.javascript.Scriptable in project OpenAM by OpenRock.
the class RhinoScriptEngine method getScope.
/**
* Builds a Rhino variable scope that includes all of the scopes defined in the given script context as well as
* the standard Rhino top-level environment. Also binds the variable {@code context} to point to the JSR 223
* ScriptContext object, as per the JSR 223 spec.
*
* @param context the Rhino context to build the scope for.
* @param scriptContext the JSR 223 script context.
* @return a Rhino scope containing the given ScriptContext bindings and standard Rhino top-level bindings.
*/
private Scriptable getScope(final Context context, final ScriptContext scriptContext) {
final Scriptable scope = new ScriptContextScope(scriptContext);
final ScriptableObject topLevel = context.initStandardObjects();
scope.setPrototype(topLevel);
scope.put("context", scope, scriptContext);
return scope;
}
use of org.mozilla.javascript.Scriptable in project Activiti by Activiti.
the class SecureJavascriptUtil method evaluateScript.
// exposes beans
public static Object evaluateScript(VariableScope variableScope, String script, Map<Object, Object> beans) {
Context context = Context.enter();
try {
Scriptable scope = context.initStandardObjects();
SecureScriptScope secureScriptScope = new SecureScriptScope(variableScope, beans);
scope.setPrototype(secureScriptScope);
return context.evaluateString(scope, script, "<script>", 0, null);
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Scriptable in project jmeter by apache.
the class JavaScript method executeWithRhino.
/**
* @param previousResult {@link SampleResult}
* @param currentSampler {@link Sampler}
* @param jmctx {@link JMeterContext}
* @param vars {@link JMeterVariables}
* @param script Javascript code
* @param varName variable name
* @return result as String
* @throws InvalidVariableException
*/
private String executeWithRhino(SampleResult previousResult, Sampler currentSampler, JMeterContext jmctx, JMeterVariables vars, String script, String varName) throws InvalidVariableException {
Context cx = Context.enter();
String resultStr = null;
try {
Scriptable scope = cx.initStandardObjects(null);
// Set up some objects for the script to play with
//$NON-NLS-1$
scope.put("log", scope, log);
//$NON-NLS-1$
scope.put("ctx", scope, jmctx);
//$NON-NLS-1$
scope.put("vars", scope, vars);
//$NON-NLS-1$
scope.put("props", scope, JMeterUtils.getJMeterProperties());
// Previously mis-spelt as theadName
//$NON-NLS-1$
scope.put("threadName", scope, Thread.currentThread().getName());
//$NON-NLS-1$
scope.put("sampler", scope, currentSampler);
//$NON-NLS-1$
scope.put("sampleResult", scope, previousResult);
//$NON-NLS-1$
Object result = cx.evaluateString(scope, script, "<cmd>", 1, null);
resultStr = Context.toString(result);
if (varName != null && vars != null) {
// vars can be null if run from TestPlan
vars.put(varName, resultStr);
}
} catch (RhinoException e) {
log.error("Error processing Javascript: [" + script + "]\n", e);
throw new InvalidVariableException("Error processing Javascript: [" + script + "]", e);
} finally {
Context.exit();
}
return resultStr;
}
use of org.mozilla.javascript.Scriptable in project jmeter by apache.
the class BSFJavaScriptEngine method initialize.
/**
* Initialize the engine.
* Put the manager into the context-manager
* map hashtable too.
*/
@Override
public void initialize(BSFManager mgr, String lang, // superclass does not support types
@SuppressWarnings("rawtypes") Vector declaredBeans) throws BSFException {
super.initialize(mgr, lang, declaredBeans);
// Initialize context and global scope object
try {
Context cx = Context.enter();
global = new ImporterTopLevel(cx);
Scriptable bsf = Context.toObject(new BSFFunctions(mgr, this), global);
global.put("bsf", global, bsf);
// superclass does not support types
@SuppressWarnings("unchecked") final Vector<BSFDeclaredBean> beans = declaredBeans;
for (BSFDeclaredBean declaredBean : beans) {
declareBean(declaredBean);
}
} catch (Throwable t) {
// NOSONAR We handle correctly Error case in function
handleError(t);
} finally {
Context.exit();
}
}
Aggregations