aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-08-24 09:07:10 +0200
committerLars Knoll <lars.knoll@theqtcompany.com>2015-09-15 07:37:11 +0000
commitcedd73279403244bbf4b74da4c3ec60111e60399 (patch)
treefc3a03ecdc4faefd9ed010ee4723d2a2333fd74c
parent7dab89a65ef859ef1982d5b882cb74a0a34e53a9 (diff)
Explicitly push/pop ExecutionContexts
Avoid the implicit push inside the execution context constructor and rather make this explicit in the code. Change-Id: I1bb0fb523fddbb273fc666370d619f55f49cd40a Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--src/qml/jsruntime/qv4context.cpp2
-rw-r--r--src/qml/jsruntime/qv4engine.cpp2
-rw-r--r--src/qml/jsruntime/qv4engine_p.h1
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp7
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp4
-rw-r--r--src/qml/jsruntime/qv4script.cpp1
-rw-r--r--src/qml/qml/qqmlmetatype.cpp8
7 files changed, 13 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index 710c9e0ea2..b1aaf06e80 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -96,7 +96,6 @@ Heap::CatchContext *ExecutionContext::newCatchContext(String *exceptionVarName,
Heap::QmlContext *ExecutionContext::newQmlContext(QmlContextWrapper *qml)
{
Heap::QmlContext *c = d()->engine->memoryManager->alloc<QmlContext>(this, qml);
- d()->engine->popContext();
return c;
}
@@ -105,7 +104,6 @@ Heap::QmlContext *ExecutionContext::newQmlContext(QQmlContextData *context, QObj
Scope scope(this);
Scoped<QmlContextWrapper> qml(scope, QmlContextWrapper::qmlScope(scope.engine, context, scopeObject));
Heap::QmlContext *c = d()->engine->memoryManager->alloc<QmlContext>(this, qml);
- d()->engine->popContext();
return c;
}
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 26991351d1..78a3037665 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -508,6 +508,7 @@ void ExecutionEngine::initRootContext()
r->d()->callData->argc = 0;
r->d()->callData->thisObject = globalObject;
r->d()->callData->args[0] = Encode::undefined();
+ current = r->d();
jsObjects[RootContect] = r;
}
@@ -522,6 +523,7 @@ Heap::ExecutionContext *ExecutionEngine::pushGlobalContext()
Scope scope(this);
Scoped<GlobalContext> g(scope, memoryManager->alloc<GlobalContext>(this));
g->d()->callData = rootContext()->d()->callData;
+ pushContext(g->d());
Q_ASSERT(currentContext() == g->d());
return g->d();
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index 09cde6a957..968c9d5df0 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -474,7 +474,6 @@ Heap::ExecutionContext::ExecutionContext(ExecutionEngine *engine, ContextType t)
, strictMode(false)
, lineNumber(-1)
{
- engine->pushContext(this);
}
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 325f4c5c55..9192cd9f8a 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -442,10 +442,10 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData)
ScopedObject proto(scope, f->protoForConstructor());
ScopedObject obj(scope, v4->newObject(ic, proto));
-
ScopedContext context(scope, v4->currentContext());
callData->thisObject = obj.asReturnedValue();
Scoped<CallContext> ctx(scope, context->newCallContext(f, callData));
+ v4->pushContext(ctx);
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
@@ -473,6 +473,7 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData)
Scoped<ScriptFunction> f(scope, static_cast<const ScriptFunction *>(that));
ScopedContext context(scope, v4->currentContext());
Scoped<CallContext> ctx(scope, context->newCallContext(f, callData));
+ v4->pushContext(ctx);
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
@@ -546,6 +547,7 @@ ReturnedValue SimpleScriptFunction::construct(const Managed *that, CallData *cal
ctx.locals = scope.alloc(f->varCount());
for (int i = callData->argc; i < (int)f->formalParameterCount(); ++i)
callData->args[i] = Encode::undefined();
+ v4->pushContext(&ctx);
Q_ASSERT(v4->currentContext() == &ctx);
ScopedObject result(scope, Q_V4_PROFILE(v4, f->function()));
@@ -584,6 +586,7 @@ ReturnedValue SimpleScriptFunction::call(const Managed *that, CallData *callData
ctx.locals = scope.alloc(f->varCount());
for (int i = callData->argc; i < (int)f->formalParameterCount(); ++i)
callData->args[i] = Encode::undefined();
+ v4->pushContext(&ctx);
Q_ASSERT(v4->currentContext() == &ctx);
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
@@ -636,6 +639,7 @@ ReturnedValue BuiltinFunction::call(const Managed *that, CallData *callData)
ctx.setVtable(CallContext::staticVTable());
ctx.strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
ctx.callData = callData;
+ v4->pushContext(&ctx);
Q_ASSERT(v4->currentContext() == &ctx);
Scoped<CallContext> sctx(scope, &ctx);
@@ -660,6 +664,7 @@ ReturnedValue IndexedBuiltinFunction::call(const Managed *that, CallData *callDa
ctx.setVtable(CallContext::staticVTable());
ctx.strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
ctx.callData = callData;
+ v4->pushContext(&ctx);
Q_ASSERT(v4->currentContext() == &ctx);
Scoped<CallContext> sctx(scope, &ctx);
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 9316223696..5cc47aacd8 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1180,7 +1180,7 @@ void Runtime::pushWithScope(const Value &o, ExecutionEngine *engine)
Scope scope(engine);
ScopedObject obj(scope, o.toObject(engine));
ScopedContext ctx(scope, engine->currentContext());
- ctx->newWithContext(obj);
+ engine->pushContext(ctx->newWithContext(obj));
}
ReturnedValue Runtime::unwindException(ExecutionEngine *engine)
@@ -1196,7 +1196,7 @@ void Runtime::pushCatchScope(NoThrowEngine *engine, int exceptionVarNameIndex)
ScopedValue v(scope, engine->catchException(0));
ScopedString exceptionVarName(scope, engine->currentContext()->compilationUnit->runtimeStrings[exceptionVarNameIndex]);
ScopedContext ctx(scope, engine->currentContext());
- ctx->newCatchContext(exceptionVarName, v);
+ engine->pushContext(ctx->newCatchContext(exceptionVarName, v));
}
void Runtime::popScope(ExecutionEngine *engine)
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index f093652d28..acb1d8f55d 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -125,6 +125,7 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData)
ScopedContext context(scope, v4->currentContext());
Scoped<CallContext> ctx(scope, context->newCallContext(This, callData));
+ v4->pushContext(ctx);
ScopedValue result(scope, Q_V4_PROFILE(v4, f));
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index fbb21f4562..f0debb8e59 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -217,12 +217,10 @@ public:
void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e)
{
QV4::ExecutionEngine *v4 = QV8Engine::getV4(e->handle());
+ v4->pushGlobalContext();
if (scriptCallback && scriptApi(e).isUndefined()) {
- v4->pushGlobalContext();
setScriptApi(e, scriptCallback(e, e));
- v4->popContext();
} else if (qobjectCallback && !qobjectApi(e)) {
- v4->pushGlobalContext();
QObject *o = qobjectCallback(e, e);
setQObjectApi(e, o);
if (!o) {
@@ -230,14 +228,12 @@ void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e)
}
// if this object can use a property cache, create it now
QQmlData::ensurePropertyCache(e, o);
- v4->popContext();
} else if (!url.isEmpty() && !qobjectApi(e)) {
- v4->pushGlobalContext();
QQmlComponent component(e, url, QQmlComponent::PreferSynchronous);
QObject *o = component.create();
setQObjectApi(e, o);
- v4->popContext();
}
+ v4->popContext();
}
void QQmlType::SingletonInstanceInfo::destroy(QQmlEngine *e)