public Object invoke(Object thisArg, Object[] args) throws Exception {
Context cx = Context.enter();
try {
Object result;
Scriptable thisObj = !(thisArg instanceof Scriptable) ?
Context.toObject(thisArg, scope) : (Scriptable)thisArg;
result = ScriptableObject.getProperty(thisObj, name);
Object[] newArgs = null;
if (args != null) {
newArgs = new Object[args.length];
int len = args.length;
for (int i = 0; i < len; i++) {
newArgs[i] = args[i];
if (args[i] != null &&
!(args[i] instanceof Number) &&
!(args[i] instanceof Boolean) &&
!(args[i] instanceof String) &&
!(args[i] instanceof Scriptable)) {
newArgs[i] = Context.toObject(args[i], scope);
}
}
}
result = ScriptRuntime.call(cx, result, thisObj, newArgs, scope);
return unwrap(result);
} catch (JavaScriptException e) {
throw new java.lang.reflect.InvocationTargetException(e);
} finally {
Context.exit();
}
}