summaryrefslogtreecommitdiffstats
path: root/src/script/bridge/qscriptfunction.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-07-30 19:50:17 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-07-31 14:11:29 (GMT)
commitbb1e71ac344b184d2ab13cd0ed7188eebb34aaf1 (patch)
treee2481d6ab859207c3cef2dd2822f9e0cb65da5cd /src/script/bridge/qscriptfunction.cpp
parentf6713c0e69d2b2b20da00e9a9a4e23a8f4f85c3d (diff)
downloadQt-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/qscriptfunction.cpp')
-rw-r--r--src/script/bridge/qscriptfunction.cpp43
1 files changed, 5 insertions, 38 deletions
diff --git a/src/script/bridge/qscriptfunction.cpp b/src/script/bridge/qscriptfunction.cpp
index 309315c..d51147a 100644
--- a/src/script/bridge/qscriptfunction.cpp
+++ b/src/script/bridge/qscriptfunction.cpp
@@ -86,23 +86,15 @@ JSC::JSValue FunctionWrapper::proxyCall(JSC::ExecState *exec, JSC::JSObject *cal
{
FunctionWrapper *self = static_cast<FunctionWrapper*>(callee);
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine);
- JSC::ExecState *previousFrame = eng_p->currentFrame;
- eng_p->currentFrame = exec;
QScriptContext *ctx = eng_p->contextForFrame(exec);
//We might have nested eval inside our function so we should create another scope
- JSC::JSObject* scope = new (exec) QScriptActivationObject(exec);
- exec->setScopeChain(exec->scopeChain()->copy()->push(scope));
+ QScriptPushScopeHelper scope(exec);
QScriptValue result = self->data->function(ctx, self->data->engine);
if (!result.isValid())
result = QScriptValue(QScriptValue::UndefinedValue);
- exec->setScopeChain(exec->scopeChain()->pop());
- exec->scopeChain()->deref();
-
- eng_p->currentFrame = previousFrame;
- eng_p->releaseContextForFrame(exec);
return eng_p->scriptValueToJSCValue(result);
}
@@ -111,25 +103,16 @@ JSC::JSObject* FunctionWrapper::proxyConstruct(JSC::ExecState *exec, JSC::JSObje
{
FunctionWrapper *self = static_cast<FunctionWrapper*>(callee);
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine);
- JSC::ExecState *previousFrame = eng_p->currentFrame;
QScriptContext *ctx = eng_p->contextForFrame(exec);
- QScriptContextPrivate::get(ctx)->calledAsConstructor = true;
- eng_p->currentFrame = exec;
//We might have nested eval inside our function so we should create another scope
- JSC::JSObject* scope = new (exec) QScriptActivationObject(exec);
- exec->setScopeChain(exec->scopeChain()->copy()->push(scope));
+ QScriptPushScopeHelper scope(exec, true);
QScriptValue defaultObject = ctx->thisObject();
QScriptValue result = self->data->function(ctx, self->data->engine);
if (!result.isObject())
result = defaultObject;
- exec->setScopeChain(exec->scopeChain()->pop());
- exec->scopeChain()->deref();
-
- eng_p->currentFrame = previousFrame;
- eng_p->releaseContextForFrame(exec);
return JSC::asObject(eng_p->scriptValueToJSCValue(result));
}
@@ -159,21 +142,13 @@ JSC::JSValue FunctionWithArgWrapper::proxyCall(JSC::ExecState *exec, JSC::JSObje
{
FunctionWithArgWrapper *self = static_cast<FunctionWithArgWrapper*>(callee);
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine);
- JSC::ExecState *previousFrame = eng_p->currentFrame;
QScriptContext *ctx = eng_p->contextForFrame(exec);
- eng_p->currentFrame = exec;
//We might have nested eval inside our function so we should create another scope
- JSC::JSObject* scope = new (exec) QScriptActivationObject(exec);
- exec->setScopeChain(exec->scopeChain()->copy()->push(scope));
-
- QScriptValue result = self->data->function(ctx, self->data->engine, self->data->arg);
+ QScriptPushScopeHelper scope(exec);
- exec->setScopeChain(exec->scopeChain()->pop());
- exec->scopeChain()->deref();
+ QScriptValue result = self->data->function(eng_p->contextForFrame(exec), self->data->engine, self->data->arg);
- eng_p->currentFrame = previousFrame;
- eng_p->releaseContextForFrame(exec);
return eng_p->scriptValueToJSCValue(result);
}
@@ -182,25 +157,17 @@ JSC::JSObject* FunctionWithArgWrapper::proxyConstruct(JSC::ExecState *exec, JSC:
{
FunctionWithArgWrapper *self = static_cast<FunctionWithArgWrapper*>(callee);
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine);
- JSC::ExecState *previousFrame = eng_p->currentFrame;
QScriptContext *ctx = eng_p->contextForFrame(exec);
- QScriptContextPrivate::get(ctx)->calledAsConstructor = true;
- eng_p->currentFrame = exec;
//We might have nested eval inside our function so we should create another scope
- JSC::JSObject* scope = new (exec) QScriptActivationObject(exec);
- exec->setScopeChain(exec->scopeChain()->copy()->push(scope));
+ QScriptPushScopeHelper scope(exec, true);
QScriptValue defaultObject = ctx->thisObject();
QScriptValue result = self->data->function(ctx, self->data->engine, self->data->arg);
if (!result.isObject())
result = defaultObject;
- exec->setScopeChain(exec->scopeChain()->pop());
- exec->scopeChain()->deref();
- eng_p->currentFrame = previousFrame;
- eng_p->releaseContextForFrame(exec);
return JSC::asObject(eng_p->scriptValueToJSCValue(result));
}