use of org.mozilla.javascript.Wrapper in project scriptographer by scriptographer.
the class RhinoScript method execute.
public Object execute(Scope scope) throws ScriptException {
try {
Context cx = Context.getCurrentContext();
Object result;
// TODO: Typecast to RhinoScope can be wrong, e.g. when calling
// from another language
result = script.exec(cx, ((RhinoScope) scope).getScope());
if (result instanceof Wrapper)
result = ((Wrapper) result).unwrap();
return result;
} catch (Throwable t) {
throw new RhinoScriptException(engine, t);
}
}
use of org.mozilla.javascript.Wrapper in project scriptographer by scriptographer.
the class MapAdapter method get.
public Object get(Object key) {
Object value;
if (key instanceof Integer)
value = ScriptableObject.getProperty(object, ((Integer) key).intValue());
else if (key instanceof String)
value = ScriptableObject.getProperty(object, (String) key);
else
value = null;
if (value instanceof Wrapper)
value = ((Wrapper) value).unwrap();
else if (value == ScriptableObject.NOT_FOUND)
value = null;
else if (value instanceof NativeArray) {
// Convert to a normal array
// TODO: see if we need to convert the other way in put?
NativeArray array = (NativeArray) value;
int length = (int) array.getLength();
Object[] list = new Object[length];
for (int i = 0; i < length; i++) {
Object obj = array.get(i, array);
if (obj instanceof Wrapper)
obj = ((Wrapper) obj).unwrap();
list[i] = obj;
}
return list;
}
return value;
}
use of org.mozilla.javascript.Wrapper in project jmeter by apache.
the class BSFJavaScriptEngine method call.
/**
* Return an object from an extension.
* @param object Object on which to make the call (ignored).
* @param method The name of the method to call.
* @param args an array of arguments to be
* passed to the extension, which may be either
* Vectors of Nodes, or Strings.
*/
@Override
public Object call(Object object, String method, Object[] args) throws BSFException {
Object retval = null;
Context cx;
try {
cx = Context.enter();
// REMIND: convert arg list Vectors here?
Object fun = global.get(method, global);
// Any way to make these arguments *sensible?
if (fun == Scriptable.NOT_FOUND) {
throw new EvaluatorException("function " + method + " not found.", "none", 0);
}
cx.setOptimizationLevel(-1);
cx.setGeneratingDebug(false);
cx.setGeneratingSource(false);
cx.setOptimizationLevel(0);
cx.setDebugger(null, null);
retval = ((Function) fun).call(cx, global, global, args);
if (retval instanceof Wrapper) {
retval = ((Wrapper) retval).unwrap();
}
} catch (Throwable t) {
// NOSONAR We handle correctly Error case in function
handleError(t);
} finally {
Context.exit();
}
return retval;
}
Aggregations