/** * Prepare for calling obj.property(...): return function corresponding to * obj.property and make obj properly converted to Scriptable available * as ScriptRuntime.lastStoredScriptable() for consumption as thisObj. * The caller must call ScriptRuntime.lastStoredScriptable() immediately * after calling this method. * Warning: this doesn't allow to resolve primitive prototype properly when * many top scopes are involved. * * @deprecated Use {@link #getPropFunctionAndThis(Object, String, Context, Scriptable)} instead */ @Deprecated public static Callable getPropFunctionAndThis(Object obj, String property, Context cx) { return getPropFunctionAndThis(obj, property, cx, getTopCallScope(cx)); }
/** * Method used to run a command through the Rhino engine. Allows to have a single generic executeCommand * public static method (signature needed by Rhino) for all the commands. * The command function registered to the top-level contains a reference to the actual command to be run, * which is a {@link Command} object annotated with the {@link ExecutableCommand} annotation. * @param cx the Rhino context * @param thisObj the current scope * @param args The arguments provided when running the command as a javascript function * @param funObj The function invoked through the shell * @return the result of the command execution */ @SuppressWarnings("unused") public static Object executeCommand(Context cx, Scriptable thisObj, Object[] args, Function funObj) { if (funObj instanceof RhinoCommandFunctionObject) { RhinoCommandFunctionObject rhinoCommandFunctionObject = (RhinoCommandFunctionObject) funObj; Scriptable parentScope = rhinoCommandFunctionObject.getParentScope(); Command command = rhinoCommandFunctionObject.getCommand(); ExecutableCommand annotation = command.getClass().getAnnotation(ExecutableCommand.class); Callable callable = ScriptRuntime.getPropFunctionAndThis(command, annotation.executeMethod(), cx, parentScope); return callable.call(cx, parentScope, ScriptRuntime.lastStoredScriptable(cx), args); } throw new RuntimeException("Unable to determine the command to run"); } }
fun = ScriptRuntime.getPropFunctionAndThis( elem, "toLocaleString", cx); funThis = ScriptRuntime.lastStoredScriptable(cx);
fun = ScriptRuntime.getPropFunctionAndThis( elem, "toLocaleString", cx); funThis = ScriptRuntime.lastStoredScriptable(cx);
Callable fun; Scriptable funThis; fun = ScriptRuntime.getPropFunctionAndThis( elem, "toLocaleString", cx); funThis = ScriptRuntime.lastStoredScriptable(cx);
Callable fun; Scriptable funThis; fun = ScriptRuntime.getPropFunctionAndThis( elem, "toLocaleString", cx); funThis = ScriptRuntime.lastStoredScriptable(cx);
Callable fun; Scriptable funThis; fun = ScriptRuntime.getPropFunctionAndThis( elem, "toLocaleString", cx); funThis = ScriptRuntime.lastStoredScriptable(cx);
Callable fun; Scriptable funThis; fun = ScriptRuntime.getPropFunctionAndThis( elem, "toLocaleString", cx, scope); funThis = ScriptRuntime.lastStoredScriptable(cx);
else definer = "__defineSetter__"; fun = getPropFunctionAndThis(object, definer, cx);
else definer = "__defineSetter__"; fun = getPropFunctionAndThis(object, definer, cx);
/** * Prepare for calling obj[id](...): return function corresponding to * obj[id] and make obj properly converted to Scriptable available * as ScriptRuntime.lastStoredScriptable() for consumption as thisObj. * The caller must call ScriptRuntime.lastStoredScriptable() immediately * after calling this method. */ public static Callable getElemFunctionAndThis(Object obj, Object elem, Context cx, Scriptable scope) { String str = toStringIdOrIndex(cx, elem); if (str != null) { return getPropFunctionAndThis(obj, str, cx, scope); } int index = lastIndexResult(cx); Scriptable thisObj = toObjectOrNull(cx, obj, scope); if (thisObj == null) { throw undefCallError(obj, String.valueOf(index)); } Object value = ScriptableObject.getProperty(thisObj, index); if (!(value instanceof Callable)) { throw notFunctionError(value, elem); } storeScriptable(cx, thisObj); return (Callable)value; }
/** * Prepare for calling obj[id](...): return function corresponding to * obj[id] and make obj properly converted to Scriptable available * as ScriptRuntime.lastStoredScriptable() for consumption as thisObj. * The caller must call ScriptRuntime.lastStoredScriptable() immediately * after calling this method. */ public static Callable getElemFunctionAndThis(Object obj, Object elem, Context cx) { String str = toStringIdOrIndex(cx, elem); if (str != null) { return getPropFunctionAndThis(obj, str, cx); } int index = lastIndexResult(cx); Scriptable thisObj = toObjectOrNull(cx, obj); if (thisObj == null) { throw undefCallError(obj, String.valueOf(index)); } Object value = ScriptableObject.getProperty(thisObj, index); if (!(value instanceof Callable)) { throw notFunctionError(value, elem); } storeScriptable(cx, thisObj); return (Callable)value; }
/** * Prepare for calling obj[id](...): return function corresponding to * obj[id] and make obj properly converted to Scriptable available * as ScriptRuntime.lastStoredScriptable() for consumption as thisObj. * The caller must call ScriptRuntime.lastStoredScriptable() immediately * after calling this method. */ public static Callable getElemFunctionAndThis(Object obj, Object elem, Context cx) { String str = toStringIdOrIndex(cx, elem); if (str != null) { return getPropFunctionAndThis(obj, str, cx); } int index = lastIndexResult(cx); Scriptable thisObj = toObjectOrNull(cx, obj); if (thisObj == null) { throw undefCallError(obj, String.valueOf(index)); } Object value = ScriptableObject.getProperty(thisObj, index); if (!(value instanceof Callable)) { throw notFunctionError(value, elem); } storeScriptable(cx, thisObj); return (Callable)value; }
/** * Prepare for calling obj[id](...): return function corresponding to * obj[id] and make obj properly converted to Scriptable available * as ScriptRuntime.lastStoredScriptable() for consumption as thisObj. * The caller must call ScriptRuntime.lastStoredScriptable() immediately * after calling this method. */ public static Callable getElemFunctionAndThis(Object obj, Object elem, Context cx) { String str = toStringIdOrIndex(cx, elem); if (str != null) { return getPropFunctionAndThis(obj, str, cx); } int index = lastIndexResult(cx); Scriptable thisObj = toObjectOrNull(cx, obj); if (thisObj == null) { throw undefCallError(obj, String.valueOf(index)); } Object value = ScriptableObject.getProperty(thisObj, index); if (!(value instanceof Callable)) { throw notFunctionError(value, elem); } storeScriptable(cx, thisObj); return (Callable)value; }
return getPropFunctionAndThis(obj, s, cx);
return getPropFunctionAndThis(obj, s, cx);
if (obj == DBL_MRK) obj = ScriptRuntime.wrapNumber(sDbl[stackTop]); stack[stackTop] = ScriptRuntime.getPropFunctionAndThis(obj, stringReg, cx, frame.scope); ++stackTop;
if (obj == DBL_MRK) obj = ScriptRuntime.wrapNumber(sDbl[stackTop]); stack[stackTop] = ScriptRuntime.getPropFunctionAndThis(obj, stringReg, cx, frame.scope); ++stackTop;
if (obj == DBL_MRK) obj = ScriptRuntime.wrapNumber(sDbl[stackTop]); stack[stackTop] = ScriptRuntime.getPropFunctionAndThis(obj, stringReg, cx, frame.scope); ++stackTop;
if (obj == DBL_MRK) obj = ScriptRuntime.wrapNumber(sDbl[stackTop]); stack[stackTop] = ScriptRuntime.getPropFunctionAndThis(obj, stringReg, cx, frame.scope); ++stackTop;