aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-08-21 14:55:53 +0200
committerLars Knoll <lars.knoll@theqtcompany.com>2015-09-15 07:37:08 +0000
commit7dab89a65ef859ef1982d5b882cb74a0a34e53a9 (patch)
tree496f65fb6c0c6d158facca02bf83944269874a77
parentb5902bd43a3b45a25e3b960b20c3c1ecb41073fe (diff)
Cleanup the ExecutionContextSaver
Always operate on the current context (as that's what we do in practice anyway). Change-Id: I4171207a7a86e69aa685754956c0764ac6e152a7 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--src/qml/jsruntime/qv4debugging.cpp2
-rw-r--r--src/qml/jsruntime/qv4engine_p.h15
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp20
-rw-r--r--src/qml/jsruntime/qv4globalobject.cpp3
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h15
-rw-r--r--src/qml/jsruntime/qv4script.cpp5
-rw-r--r--src/qml/memory/qv4mm.cpp2
7 files changed, 31 insertions, 31 deletions
diff --git a/src/qml/jsruntime/qv4debugging.cpp b/src/qml/jsruntime/qv4debugging.cpp
index 6efc3793ce..1833215c42 100644
--- a/src/qml/jsruntime/qv4debugging.cpp
+++ b/src/qml/jsruntime/qv4debugging.cpp
@@ -66,7 +66,7 @@ void Debugger::JavaScriptJob::run()
{
Scope scope(engine);
- ExecutionContextSaver saver(scope, engine->currentContext());
+ ExecutionContextSaver saver(scope);
if (frameNr > 0) {
Value *savedContexts = scope.alloc(frameNr);
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index 8f1047a373..09cde6a957 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -348,6 +348,7 @@ public:
void enableProfiler();
Heap::ExecutionContext *pushGlobalContext();
+ void pushContext(Heap::ExecutionContext *context);
void pushContext(CallContext *context);
Heap::ExecutionContext *popContext();
@@ -441,13 +442,19 @@ public:
void assertObjectBelongsToEngine(const Heap::Base &baseObject);
};
+inline void ExecutionEngine::pushContext(Heap::ExecutionContext *context)
+{
+ Q_ASSERT(current && context);
+ context->parent = current;
+ current = context;
+}
+
inline void ExecutionEngine::pushContext(CallContext *context)
{
- Q_ASSERT(current && context && context->d());
- context->d()->parent = current;
- current = context->d();
+ pushContext(context->d());
}
+
inline Heap::ExecutionContext *ExecutionEngine::popContext()
{
Q_ASSERT(current->parent);
@@ -467,7 +474,7 @@ Heap::ExecutionContext::ExecutionContext(ExecutionEngine *engine, ContextType t)
, strictMode(false)
, lineNumber(-1)
{
- engine->current = this;
+ engine->pushContext(this);
}
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 1cff952401..325f4c5c55 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -434,17 +434,19 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData)
CHECK_STACK_LIMITS(v4);
Scope scope(v4);
+ ExecutionContextSaver ctxSaver(scope);
+
Scoped<ScriptFunction> f(scope, static_cast<const ScriptFunction *>(that));
InternalClass *ic = scope.engine->emptyClass;
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));
- ExecutionContextSaver ctxSaver(scope, context);
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
if (f->function()->compiledFunction->hasQmlDependencies())
@@ -466,12 +468,12 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData)
CHECK_STACK_LIMITS(v4);
Scope scope(v4);
+ ExecutionContextSaver ctxSaver(scope);
+
Scoped<ScriptFunction> f(scope, static_cast<const ScriptFunction *>(that));
ScopedContext context(scope, v4->currentContext());
-
Scoped<CallContext> ctx(scope, context->newCallContext(f, callData));
- ExecutionContextSaver ctxSaver(scope, context);
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
if (f->function()->compiledFunction->hasQmlDependencies())
@@ -522,14 +524,14 @@ ReturnedValue SimpleScriptFunction::construct(const Managed *that, CallData *cal
CHECK_STACK_LIMITS(v4);
Scope scope(v4);
+ ExecutionContextSaver ctxSaver(scope);
+
Scoped<SimpleScriptFunction> f(scope, static_cast<const SimpleScriptFunction *>(that));
InternalClass *ic = scope.engine->emptyClass;
ScopedObject proto(scope, f->protoForConstructor());
callData->thisObject = v4->newObject(ic, proto);
- ExecutionContextSaver ctxSaver(scope, v4->currentContext());
-
CallContext::Data ctx(v4);
#ifndef QT_NO_DEBUG
ctx.mm_data = 0; // make sure we don't run into the assertion in setVTable when allocating a context on the stack
@@ -564,9 +566,9 @@ ReturnedValue SimpleScriptFunction::call(const Managed *that, CallData *callData
CHECK_STACK_LIMITS(v4);
Scope scope(v4);
- Scoped<SimpleScriptFunction> f(scope, static_cast<const SimpleScriptFunction *>(that));
+ ExecutionContextSaver ctxSaver(scope);
- ExecutionContextSaver ctxSaver(scope, v4->currentContext());
+ Scoped<SimpleScriptFunction> f(scope, static_cast<const SimpleScriptFunction *>(that));
CallContext::Data ctx(v4);
#ifndef QT_NO_DEBUG
@@ -625,7 +627,7 @@ ReturnedValue BuiltinFunction::call(const Managed *that, CallData *callData)
CHECK_STACK_LIMITS(v4);
Scope scope(v4);
- ExecutionContextSaver ctxSaver(scope, v4->currentContext());
+ ExecutionContextSaver ctxSaver(scope);
CallContext::Data ctx(v4);
#ifndef QT_NO_DEBUG
@@ -649,7 +651,7 @@ ReturnedValue IndexedBuiltinFunction::call(const Managed *that, CallData *callDa
CHECK_STACK_LIMITS(v4);
Scope scope(v4);
- ExecutionContextSaver ctxSaver(scope, v4->currentContext());
+ ExecutionContextSaver ctxSaver(scope);
CallContext::Data ctx(v4);
#ifndef QT_NO_DEBUG
diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp
index ec7b9b3f7d..91c0d2da2d 100644
--- a/src/qml/jsruntime/qv4globalobject.cpp
+++ b/src/qml/jsruntime/qv4globalobject.cpp
@@ -339,10 +339,9 @@ ReturnedValue EvalFunction::evalCall(CallData *callData, bool directCall) const
ExecutionEngine *v4 = engine();
Scope scope(v4);
+ ExecutionContextSaver ctxSaver(scope);
ScopedContext parentContext(scope, v4->currentContext());
- ExecutionContextSaver ctxSaver(scope, parentContext);
-
ScopedContext ctx(scope, parentContext.getPointer());
if (!directCall) {
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index e19aeaf882..563b8b0e93 100644
--- a/src/qml/jsruntime/qv4scopedvalue_p.h
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -416,20 +416,11 @@ struct ExecutionContextSaver
ExecutionEngine *engine;
Value *savedContext;
- ExecutionContextSaver(Scope &scope, ExecutionContext *context)
- : engine(context->d()->engine)
+ ExecutionContextSaver(Scope &scope)
+ : engine(scope.engine)
, savedContext(scope.alloc(1))
{
- savedContext->setM(context->d());
-#if QT_POINTER_SIZE == 4
- savedContext->setTag(QV4::Value::Managed_Type);
-#endif
- }
- ExecutionContextSaver(Scope &scope, Heap::ExecutionContext *context)
- : engine(context->engine)
- , savedContext(scope.alloc(1))
- {
- savedContext->setM(context);
+ savedContext->setM(scope.engine->currentContext());
#if QT_POINTER_SIZE == 4
savedContext->setTag(QV4::Value::Managed_Type);
#endif
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index 32a15fdf5e..f093652d28 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -117,6 +117,8 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData)
CHECK_STACK_LIMITS(v4);
Scope scope(v4);
+ ExecutionContextSaver ctxSaver(scope);
+
QV4::Function *f = This->function();
if (!f)
return QV4::Encode::undefined();
@@ -124,7 +126,6 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData)
ScopedContext context(scope, v4->currentContext());
Scoped<CallContext> ctx(scope, context->newCallContext(This, callData));
- ExecutionContextSaver ctxSaver(scope, context);
ScopedValue result(scope, Q_V4_PROFILE(v4, f));
return result->asReturnedValue();
@@ -237,7 +238,7 @@ ReturnedValue Script::run()
if (qmlContext.isUndefined()) {
TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, vmFunction);
- ExecutionContextSaver ctxSaver(valueScope, scope);
+ ExecutionContextSaver ctxSaver(valueScope);
ContextStateSaver stateSaver(valueScope, scope);
scope->d()->strictMode = vmFunction->isStrict();
scope->d()->lookups = vmFunction->compilationUnit->runtimeLookups;
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp
index b880c9c8d5..5a7953679b 100644
--- a/src/qml/memory/qv4mm.cpp
+++ b/src/qml/memory/qv4mm.cpp
@@ -483,7 +483,7 @@ void MemoryManager::sweep(bool lastSweep)
// some execution contexts are allocated on the stack, make sure we clear their markBit as well
if (!lastSweep) {
- Heap::ExecutionContext *ctx = engine()->current;
+ Heap::ExecutionContext *ctx = engine()->currentContext();
while (ctx) {
ctx->clearMarkBit();
ctx = ctx->parent;