public static Callable getElemFunctionAndThis(Object obj, Object elem,
                                                  Context cx, Scriptable scope)
    {
        Scriptable thisObj;
        Object value;

        if (isSymbol(elem)) {
            thisObj = toObjectOrNull(cx, obj, scope);
            if (thisObj == null) {
                throw undefCallError(obj, String.valueOf(elem));
            }
            value = ScriptableObject.getProperty(thisObj, (Symbol)elem);

        } else {
            String str = toStringIdOrIndex(cx, elem);
            if (str != null) {
                return getPropFunctionAndThis(obj, str, cx, scope);
            }
            int index = lastIndexResult(cx);

            thisObj = toObjectOrNull(cx, obj, scope);
            if (thisObj == null) {
                throw undefCallError(obj, String.valueOf(elem));
            }

            value = ScriptableObject.getProperty(thisObj, index);
        }

        if (!(value instanceof Callable)) {
            throw notFunctionError(value, elem);
        }

        storeScriptable(cx, thisObj);
        return (Callable)value;
    }
public static Callable getElemFunctionAndThis ( Object obj , Object elem , Context cx , Scriptable scope ) { Scriptable thisObj ; Object value ; if ( isSymbol ( elem ) ) { thisObj = toObjectOrNull ( cx , obj , scope ) ; if ( thisObj == null ) { throw undefCallError ( obj , String . valueOf ( elem ) ) ; } value = ScriptableObject . getProperty ( thisObj , ( Symbol ) elem ) ; } else { String str = toStringIdOrIndex ( cx , elem ) ; if ( str != null ) { return getPropFunctionAndThis ( obj , str , cx , scope ) ; } int index = lastIndexResult ( cx ) ; thisObj = toObjectOrNull ( cx , obj , scope ) ; if ( thisObj == null ) { throw undefCallError ( obj , String . valueOf ( elem ) ) ; } 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.