diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-30 19:50:17 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-31 14:11:29 (GMT) |
commit | bb1e71ac344b184d2ab13cd0ed7188eebb34aaf1 (patch) | |
tree | e2481d6ab859207c3cef2dd2822f9e0cb65da5cd /src/script/bridge/qscriptclassobject.cpp | |
parent | f6713c0e69d2b2b20da00e9a9a4e23a8f4f85c3d (diff) | |
download | Qt-bb1e71ac344b184d2ab13cd0ed7188eebb34aaf1.zip Qt-bb1e71ac344b184d2ab13cd0ed7188eebb34aaf1.tar.gz Qt-bb1e71ac344b184d2ab13cd0ed7188eebb34aaf1.tar.bz2 |
Small Refactoring of QScript
- Create a scope (activation object) for the native constructor in QScriptClass
- put the isCalledasConstructor in the activation object (so i can
clean up the QScriptContext
- Remove the code duplication in all native functions.
Aknoweldged-by: Kent
Diffstat (limited to 'src/script/bridge/qscriptclassobject.cpp')
-rw-r--r-- | src/script/bridge/qscriptclassobject.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/script/bridge/qscriptclassobject.cpp b/src/script/bridge/qscriptclassobject.cpp index 2a26049..d07fa83 100644 --- a/src/script/bridge/qscriptclassobject.cpp +++ b/src/script/bridge/qscriptclassobject.cpp @@ -213,15 +213,15 @@ JSC::JSValue JSC_HOST_CALL ClassObjectDelegate::call(JSC::ExecState *exec, JSC:: QScriptObjectDelegate *delegate = obj->delegate(); if (!delegate || (delegate->type() != QScriptObjectDelegate::ClassObject)) return JSC::throwError(exec, JSC::TypeError, "callee is not a ClassObject object"); + + //We might have nested eval inside our function so we should create another scope + QScriptPushScopeHelper scope(exec, true); + QScriptClass *scriptClass = static_cast<ClassObjectDelegate*>(delegate)->scriptClass(); QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec); - JSC::ExecState *previousFrame = eng_p->currentFrame; QScriptContext *ctx = eng_p->contextForFrame(exec); - eng_p->currentFrame = exec; QScriptValue scriptObject = eng_p->scriptValueFromJSCValue(obj); QVariant result = scriptClass->extension(QScriptClass::Callable, qVariantFromValue(ctx)); - eng_p->currentFrame = previousFrame; - eng_p->releaseContextForFrame(exec); return eng_p->jscValueFromVariant(result); } @@ -240,17 +240,16 @@ JSC::JSObject* ClassObjectDelegate::construct(JSC::ExecState *exec, JSC::JSObjec QScriptObject *obj = static_cast<QScriptObject*>(callee); QScriptObjectDelegate *delegate = obj->delegate(); QScriptClass *scriptClass = static_cast<ClassObjectDelegate*>(delegate)->scriptClass(); + + //We might have nested eval inside our function so we should create another scope + QScriptPushScopeHelper scope(exec, true); + QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec); - JSC::ExecState *previousFrame = eng_p->currentFrame; QScriptContext *ctx = eng_p->contextForFrame(exec); - QScriptContextPrivate::get(ctx)->calledAsConstructor = true; - eng_p->currentFrame = exec; QScriptValue defaultObject = ctx->thisObject(); QScriptValue result = qvariant_cast<QScriptValue>(scriptClass->extension(QScriptClass::Callable, qVariantFromValue(ctx))); if (!result.isObject()) result = defaultObject; - eng_p->currentFrame = previousFrame; - eng_p->releaseContextForFrame(exec); return JSC::asObject(eng_p->scriptValueToJSCValue(result)); } |