use of org.mozilla.javascript.Undefined in project neo4j by neo4j.
the class JavascriptExecutor method execute.
@Override
public Object execute(Map<String, Object> variables) throws EvaluationException {
Context cx = Context.enter();
try {
Scriptable scope = cx.newObject(prototype);
scope.setPrototype(prototype);
if (variables != null) {
for (String k : variables.keySet()) {
scope.put(k, scope, variables.get(k));
}
}
Object out = compiledScript.exec(cx, scope);
if (out instanceof NativeJavaObject) {
return ((NativeJavaObject) out).unwrap();
} else if (out instanceof Undefined) {
return null;
} else {
return out;
}
} catch (RhinoException e) {
throw new EvaluationException("Failed to execute script, see nested exception.", e);
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Undefined in project stetho by facebook.
the class JsRuntimeReplFactoryBuilder method importVariables.
private void importVariables(@NonNull ScriptableObject scope) throws StethoJsException {
// Define the variables
for (Map.Entry<String, Object> entrySet : mVariables.entrySet()) {
String varName = entrySet.getKey();
Object varValue = entrySet.getValue();
try {
Object jsValue;
if (varValue instanceof Scriptable || varValue instanceof Undefined) {
jsValue = varValue;
} else {
jsValue = Context.javaToJS(varValue, scope);
}
ScriptableObject.putProperty(scope, varName, jsValue);
} catch (Exception e) {
throw new StethoJsException(e, "Failed to setup variable: %s", varName);
}
}
}
use of org.mozilla.javascript.Undefined in project jslint4java by happygiraffe.
the class Util method listValue.
/**
* Convert a JavaScript array into a Java {@link List}. You must provide a
* converter which will be called on each value in order to convert it to a
* Java object.
*
* @param <T>
* The type of every array member.
* @param name
* The name of the array.
* @param scope
* The scope which contains the array.
* @param c
* A {@link Converter} instance to change the JavaScript object
* into a Java one.
* @return A {@link List} of Java objects.
*/
static <T> List<T> listValue(String name, Scriptable scope, Converter<T> c) {
Object val = scope.get(name, scope);
if (val == UniqueTag.NOT_FOUND || val instanceof Undefined) {
return new ArrayList<T>();
}
Scriptable ary = (Scriptable) val;
int count = intValue("length", ary);
List<T> list = new ArrayList<T>(count);
for (int i = 0; i < count; i++) {
list.add(c.convert(ary.get(i, ary)));
}
return list;
}
Aggregations