From bbadec8c68d930a4cb9f45835aa7d1659620cdc3 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 12 Aug 2009 15:39:55 +0200 Subject: Cantralize the place when we construct the default 'this' object that JSC doesn't construct. Removes code duplication. This also indirrectly fixes the QMetaObjectWrapperObject where this was missing --- src/script/api/qscriptengine.cpp | 11 ++++++++++- src/script/bridge/qscriptclassobject.cpp | 10 +--------- src/script/bridge/qscriptfunction.cpp | 20 ++------------------ 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index a0ca6b0..cc6233b 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -2271,9 +2271,18 @@ QScriptContext *QScriptEngine::pushContext() return the new top frame. (might be the same as exec if a new stackframe was not needed) or 0 if stack overflow */ -JSC::CallFrame *QScriptEnginePrivate::pushContext(JSC::CallFrame *exec, const JSC::JSValue &thisObject, +JSC::CallFrame *QScriptEnginePrivate::pushContext(JSC::CallFrame *exec, const JSC::JSValue &_thisObject, const JSC::ArgList& args, JSC::JSObject *callee, bool calledAsConstructor) { + JSC::JSValue thisObject = _thisObject; + if (calledAsConstructor) { + //JSC doesn't create default created object for native functions. so we do it + JSC::JSValue prototype = callee->get(exec, exec->propertyNames().prototype); + JSC::Structure *structure = prototype.isObject() ? JSC::asObject(prototype)->inheritorID() + : exec->lexicalGlobalObject()->emptyObjectStructure(); + thisObject = new (exec) QScriptObject(structure); + } + JSC::CallFrame *newCallFrame = exec; if (callee == 0 || !(exec->callee() == callee && exec->returnPC() != 0)) { //We need to check if the Interpreter might have already created a frame for function called from JS. diff --git a/src/script/bridge/qscriptclassobject.cpp b/src/script/bridge/qscriptclassobject.cpp index 3a41dae..9b9af9e 100644 --- a/src/script/bridge/qscriptclassobject.cpp +++ b/src/script/bridge/qscriptclassobject.cpp @@ -243,17 +243,9 @@ JSC::JSObject* ClassObjectDelegate::construct(JSC::ExecState *exec, JSC::JSObjec QScriptObjectDelegate *delegate = obj->delegate(); QScriptClass *scriptClass = static_cast(delegate)->scriptClass(); - JSC::Structure* structure; - JSC::JSValue prototype = JSC::asObject(callee)->get(exec, exec->propertyNames().prototype); - if (prototype.isObject()) - structure = JSC::asObject(prototype)->inheritorID(); - else - structure = exec->lexicalGlobalObject()->emptyObjectStructure(); - JSC::JSObject* thisObject = new (exec) QScriptObject(structure); - QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec); JSC::ExecState *oldFrame = eng_p->currentFrame; - eng_p->pushContext(exec, thisObject, args, callee, true); + eng_p->pushContext(exec, JSC::JSValue(), args, callee, true); QScriptContext *ctx = eng_p->contextForFrame(eng_p->currentFrame); QScriptValue defaultObject = ctx->thisObject(); diff --git a/src/script/bridge/qscriptfunction.cpp b/src/script/bridge/qscriptfunction.cpp index f3880b4..08f0ca0 100644 --- a/src/script/bridge/qscriptfunction.cpp +++ b/src/script/bridge/qscriptfunction.cpp @@ -109,19 +109,11 @@ JSC::JSValue FunctionWrapper::proxyCall(JSC::ExecState *exec, JSC::JSObject *cal JSC::JSObject* FunctionWrapper::proxyConstruct(JSC::ExecState *exec, JSC::JSObject *callee, const JSC::ArgList &args) { - JSC::Structure* structure; - JSC::JSValue prototype = JSC::asObject(callee)->get(exec, exec->propertyNames().prototype); - if (prototype.isObject()) - structure = JSC::asObject(prototype)->inheritorID(); - else - structure = exec->lexicalGlobalObject()->emptyObjectStructure(); - JSC::JSObject* thisObject = new (exec) QScriptObject(structure); - FunctionWrapper *self = static_cast(callee); QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec); JSC::ExecState *oldFrame = eng_p->currentFrame; - eng_p->pushContext(exec, thisObject, args, callee, true); + eng_p->pushContext(exec, JSC::JSValue(), args, callee, true); QScriptContext *ctx = eng_p->contextForFrame(eng_p->currentFrame); QScriptValue result = self->data->function(ctx, QScriptEnginePrivate::get(eng_p)); @@ -179,19 +171,11 @@ JSC::JSValue FunctionWithArgWrapper::proxyCall(JSC::ExecState *exec, JSC::JSObje JSC::JSObject* FunctionWithArgWrapper::proxyConstruct(JSC::ExecState *exec, JSC::JSObject *callee, const JSC::ArgList &args) { - JSC::Structure* structure; - JSC::JSValue prototype = JSC::asObject(callee)->get(exec, exec->propertyNames().prototype); - if (prototype.isObject()) - structure = JSC::asObject(prototype)->inheritorID(); - else - structure = exec->lexicalGlobalObject()->emptyObjectStructure(); - JSC::JSObject* thisObject = new (exec) QScriptObject(structure); - FunctionWithArgWrapper *self = static_cast(callee); QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec); JSC::ExecState *oldFrame = eng_p->currentFrame; - eng_p->pushContext(exec, thisObject, args, callee, true); + eng_p->pushContext(exec, JSC::JSValue(), args, callee, true); QScriptContext *ctx = eng_p->contextForFrame(eng_p->currentFrame); QScriptValue result = self->data->function(ctx, QScriptEnginePrivate::get(eng_p) , self->data->arg); -- cgit v0.12