EncodedJSValue JSC_HOST_CALL functionProtoFuncApply(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); CallData callData; CallType callType = getCallData(thisValue, callData); if (callType == CallTypeNone) return throwVMTypeError(exec); JSValue array = exec->argument(1); MarkedArgumentBuffer applyArgs; if (!array.isUndefinedOrNull()) { if (!array.isObject()) return throwVMTypeError(exec); if (asObject(array)->classInfo() == &Arguments::s_info) { if (asArguments(array)->length(exec) > Arguments::MaxArguments) return JSValue::encode(throwStackOverflowError(exec)); asArguments(array)->fillArgList(exec, applyArgs); } else if (isJSArray(array)) { if (asArray(array)->length() > Arguments::MaxArguments) return JSValue::encode(throwStackOverflowError(exec)); asArray(array)->fillArgList(exec, applyArgs); } else { unsigned length = asObject(array)->get(exec, exec->propertyNames().length).toUInt32(exec); if (length > Arguments::MaxArguments) return JSValue::encode(throwStackOverflowError(exec)); for (unsigned i = 0; i < length; ++i) applyArgs.append(asObject(array)->get(exec, i)); } } return JSValue::encode(call(exec, thisValue, callType, callData, exec->argument(0), applyArgs)); }
JSValue JSC_HOST_CALL functionProtoFuncApply(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { CallData callData; CallType callType = thisValue.getCallData(callData); if (callType == CallTypeNone) return throwError(exec, TypeError); JSValue array = args.at(1); MarkedArgumentBuffer applyArgs; if (!array.isUndefinedOrNull()) { if (!array.isObject()) return throwError(exec, TypeError); if (asObject(array)->classInfo() == &Arguments::info) asArguments(array)->fillArgList(exec, applyArgs); else if (isJSArray(&exec->globalData(), array)) asArray(array)->fillArgList(exec, applyArgs); else if (asObject(array)->inherits(&JSArray::info)) { unsigned length = asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec); for (unsigned i = 0; i < length; ++i) applyArgs.append(asArray(array)->get(exec, i)); } else return throwError(exec, TypeError); } return call(exec, thisValue, callType, callData, args.at(0), applyArgs); }
EncodedTiValue JSC_HOST_CALL functionProtoFuncApply(TiExcState* exec) { TiValue thisValue = exec->hostThisValue(); CallData callData; CallType callType = getCallData(thisValue, callData); if (callType == CallTypeNone) return throwVMTypeError(exec); TiValue array = exec->argument(1); MarkedArgumentBuffer applyArgs; if (!array.isUndefinedOrNull()) { if (!array.isObject()) return throwVMTypeError(exec); if (asObject(array)->classInfo() == &Arguments::s_info) asArguments(array)->fillArgList(exec, applyArgs); else if (isTiArray(&exec->globalData(), array)) asArray(array)->fillArgList(exec, applyArgs); else if (asObject(array)->inherits(&TiArray::s_info)) { unsigned length = asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec); for (unsigned i = 0; i < length; ++i) applyArgs.append(asArray(array)->get(exec, i)); } else return throwVMTypeError(exec); } return TiValue::encode(call(exec, thisValue, callType, callData, exec->argument(0), applyArgs)); }