JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, JSValue* returnedException) { JSLockHolder lock(exec); RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable()); RELEASE_ASSERT(!exec->vm().isCollectorBusy()); CodeProfiling profile(source); ProgramExecutable* program = ProgramExecutable::create(exec, source); if (!program) { if (returnedException) *returnedException = exec->vm().exception; exec->vm().exception = JSValue(); return jsUndefined(); } if (!thisValue || thisValue.isUndefinedOrNull()) thisValue = exec->dynamicGlobalObject(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue result = exec->interpreter()->execute(program, exec, thisObj); if (exec->hadException()) { if (returnedException) *returnedException = exec->exception(); exec->clearException(); return jsUndefined(); } RELEASE_ASSERT(result); return result; }
JSValue QT_FASTCALL objectProtoFuncDefineSetter(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { CallData callData; if (args.at(1).getCallData(callData) == CallTypeNone) return throwError(exec, SyntaxError, "invalid setter usage"); thisValue.toThisObject(exec)->defineSetter(exec, Identifier(exec, args.at(0).toString(exec)), asObject(args.at(1))); return jsUndefined(); }
EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); CallData callData; if (getCallData(exec->argument(1), callData) == CallTypeNone) return throwVMError(exec, createSyntaxError(exec, "invalid setter usage")); thisValue.toThisObject(exec)->defineSetter(exec, Identifier(exec, exec->argument(0).toString(exec)), asObject(exec->argument(1))); return JSValue::encode(jsUndefined()); }
JSValue QT_FASTCALL objectProtoFuncIsPrototypeOf(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { JSObject* thisObj = thisValue.toThisObject(exec); if (!args.at(0).isObject()) return jsBoolean(false); JSValue v = asObject(args.at(0))->prototype(); while (true) { if (!v.isObject()) return jsBoolean(false); if (v == thisObj) return jsBoolean(true); v = asObject(v)->prototype(); } }
JSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) { JSObject* thisObj = thisValue.toThisObject(exec); JSValue name = thisObj->get(exec, exec->propertyNames().name); JSValue message = thisObj->get(exec, exec->propertyNames().message); // Mozilla-compatible format. if (!name.isUndefined()) { if (!message.isUndefined()) return jsMakeNontrivialString(exec, name.toString(exec), ": ", message.toString(exec)); return jsNontrivialString(exec, name.toString(exec)); } if (!message.isUndefined()) return jsMakeNontrivialString(exec, "Error: ", message.toString(exec)); return jsNontrivialString(exec, "Error"); }
EncodedJSValue JSC_HOST_CALL objectProtoFuncIsPrototypeOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); if (!exec->argument(0).isObject()) return JSValue::encode(jsBoolean(false)); JSValue v = asObject(exec->argument(0))->prototype(); while (true) { if (!v.isObject()) return JSValue::encode(jsBoolean(false)); if (v == thisObj) return JSValue::encode(jsBoolean(true)); v = asObject(v)->prototype(); } }
JSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) { JSObject* object = thisValue.toThisObject(exec); if (exec->hadException()) return jsNull(); JSValue toISOValue = object->get(exec, exec->globalData().propertyNames->toISOString); if (exec->hadException()) return jsNull(); CallData callData; CallType callType = toISOValue.getCallData(callData); if (callType == CallTypeNone) return throwError(exec, TypeError, "toISOString is not a function"); JSValue result = call(exec, asObject(toISOValue), callType, callData, object, exec->emptyList()); if (exec->hadException()) return jsNull(); if (result.isObject()) return throwError(exec, TypeError, "toISOString did not return a primitive value"); return result; }
JSValue JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValue thisValue, const ArgList& args) { JSContextRef execRef = toRef(exec); JSObjectRef functionRef = toRef(functionObject); JSObjectRef thisObjRef = toRef(thisValue.toThisObject(exec)); int argumentCount = static_cast<int>(args.size()); Vector<JSValueRef, 16> arguments(argumentCount); for (int i = 0; i < argumentCount; i++) arguments[i] = toRef(exec, args.at(i)); JSValueRef exception = 0; JSValueRef result; { APICallbackShim callbackShim(exec); result = static_cast<JSCallbackFunction*>(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception); } if (exception) exec->setException(toJS(exec, exception)); return toJS(exec, result); }
EncodedJSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* object = thisValue.toThisObject(exec); if (exec->hadException()) return JSValue::encode(jsNull()); JSValue toISOValue = object->get(exec, exec->globalData().propertyNames->toISOString); if (exec->hadException()) return JSValue::encode(jsNull()); CallData callData; CallType callType = getCallData(toISOValue, callData); if (callType == CallTypeNone) return throwVMError(exec, createTypeError(exec, "toISOString is not a function")); JSValue result = call(exec, asObject(toISOValue), callType, callData, object, exec->emptyList()); if (exec->hadException()) return JSValue::encode(jsNull()); if (result.isObject()) return throwVMError(exec, createTypeError(exec, "toISOString did not return a primitive value")); return JSValue::encode(result); }
EncodedJSValue JSC_HOST_CALL objectProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); return JSValue::encode(jsMakeNontrivialString(exec, "[object ", thisValue.toThisObject(exec)->className(), "]")); }
void ProfileGenerator::addParentForConsoleStart(ExecState* exec) { int lineNumber; intptr_t sourceID; UString sourceURL; JSValue function; exec->interpreter()->retrieveLastCaller(exec, lineNumber, sourceID, sourceURL, function); m_currentNode = ProfileNode::create(exec, Profiler::createCallIdentifier(exec, function ? function.toThisObject(exec) : 0, sourceURL, lineNumber), m_head.get(), m_head.get()); m_head->insertNode(m_currentNode.get()); }
JSValue QT_FASTCALL objectProtoFuncLookupSetter(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { return thisValue.toThisObject(exec)->lookupSetter(exec, Identifier(exec, args.at(0).toString(exec))); }
JSValue JSFunction::call(ExecState* exec, JSValue thisValue, const ArgList& args) { ASSERT(!isHostFunction()); return exec->interpreter()->execute(jsExecutable(), exec, this, thisValue.toThisObject(exec), args, scopeChain().node(), exec->exceptionSlot()); }
JSValue QT_FASTCALL objectProtoFuncToString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) { return jsNontrivialString(exec, makeString("[object ", thisValue.toThisObject(exec)->className(), "]")); }
EncodedJSValue JSC_HOST_CALL objectProtoFuncHasOwnProperty(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); return JSValue::encode(jsBoolean(thisValue.toThisObject(exec)->hasOwnProperty(exec, Identifier(exec, exec->argument(0).toString(exec))))); }
EncodedJSValue JSC_HOST_CALL objectProtoFuncValueOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); return JSValue::encode(thisValue.toThisObject(exec)); }
JSValue QT_FASTCALL objectProtoFuncValueOf(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) { return thisValue.toThisObject(exec); }
EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); return JSValue::encode(thisValue.toThisObject(exec)->lookupSetter(exec, Identifier(exec, exec->argument(0).toString(exec)))); }
JSValue QT_FASTCALL objectProtoFuncHasOwnProperty(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { return jsBoolean(thisValue.toThisObject(exec)->hasOwnProperty(exec, Identifier(exec, args.at(0).toString(exec)))); }