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));
}
EncodedJSValue doCallToJavaScript(void* executableAddress, ProtoCallFrame* protoCallFrame)
{
    CodeBlock* codeBlock = protoCallFrame->codeBlock();
    JSScope* scope = protoCallFrame->scope();
    JSObject* callee = protoCallFrame->callee();
    int argCountIncludingThis = protoCallFrame->argumentCountIncludingThis();
    int argCount = protoCallFrame->argumentCount();
    JSValue thisValue = protoCallFrame->thisValue();
    JSStack& stack = scope->vm()->interpreter->stack();

    CallFrame* newCallFrame = stack.pushFrame(codeBlock, scope, argCountIncludingThis, callee);
    if (UNLIKELY(!newCallFrame)) {
        JSGlobalObject* globalObject = scope->globalObject();
        ExecState* exec = globalObject->globalExec();
        return JSValue::encode(throwStackOverflowError(exec));
    }

    // Set the arguments for the callee:
    newCallFrame->setThisValue(thisValue);
    for (int i = 0; i < argCount; ++i)
        newCallFrame->setArgument(i, protoCallFrame->argument(i));

    JSValue result = execute(newCallFrame, executableAddress);

    stack.popFrame(newCallFrame);

    return JSValue::encode(result);
}
예제 #3
0
void JIT_OPERATION operationThrowStackOverflowForVarargs(ExecState* exec)
{
    VM& vm = exec->vm();
    NativeCallFrameTracer tracer(&vm, exec);
    throwStackOverflowError(exec);
}