public static Object applyOrCall ( boolean isApply , Context cx , Scriptable scope , Scriptable thisObj , Object [ ] args ) { int L = args . length ; Callable function = getCallable ( thisObj ) ; Scriptable callThis = null ; if ( L != 0 ) { if ( cx . hasFeature ( Context . FEATURE_OLD_UNDEF_NULL_THIS ) ) { callThis = toObjectOrNull ( cx , args [ 0 ] , scope ) ; } else { callThis = args [ 0 ] == Undefined . instance ? Undefined . SCRIPTABLE_UNDEFINED : toObjectOrNull ( cx , args [ 0 ] , scope ) ; } } if ( callThis == null && cx . hasFeature ( Context . FEATURE_OLD_UNDEF_NULL_THIS ) ) { callThis = getTopCallScope ( cx ) ; // This covers the case of args[0] == (null|undefined) as well. } Object [ ] callArgs ; if ( isApply ) { // Follow Ecma 15.3.4.3 callArgs = L <= 1 ? ScriptRuntime . emptyArgs : getApplyArguments ( cx , args [ 1 ] ) ; } else { // Follow Ecma 15.3.4.4 if ( L <= 1 ) { callArgs = ScriptRuntime . emptyArgs ; } else { callArgs = new Object [ L - 1 ] ; System . arraycopy ( args , 1 , callArgs , 0 , L - 1 ) ; } } return function . call ( cx , scope , callThis , callArgs ) ; }
Function . prototype . apply and Function . prototype . call