public static Object callMethod ( Context cx , Scriptable obj , String methodName , Object [ ] args ) { Object funObj = getProperty ( obj , methodName ) ; if ( ! ( funObj instanceof Function ) ) { throw ScriptRuntime . notFunctionError ( obj , methodName ) ; } Function fun = ( Function ) funObj ; // XXX: What should be the scope when calling funObj? // The following favor scope stored in the object on the assumption // that is more useful especially under dynamic scope setup. // An alternative is to check for dynamic scope flag // and use ScriptableObject.getTopLevelScope(fun) if the flag is not // set. But that require access to Context and messy code // so for now it is not checked. Scriptable scope = ScriptableObject . getTopLevelScope ( obj ) ; if ( cx != null ) { return fun . call ( cx , scope , obj , args ) ; } return Context . call ( null , fun , scope , obj , args ) ; }
Call a method of an object .