Fix a bug in the code for eval
authorLars Knoll <lars.knoll@digia.com>
Fri, 22 Nov 2013 07:32:37 +0000 (08:32 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 4 Dec 2013 08:45:43 +0000 (09:45 +0100)
When eval was being used as an indirect call, the code
didn't reset the current context properly before
returning from the eval call.

Change-Id: Id5c7e9a897101d25593ef0f3b9945adaf19360b3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4globalobject.cpp

index 82622de..33a9755 100644 (file)
@@ -379,15 +379,17 @@ ReturnedValue EvalFunction::evalCall(CallData *callData, bool directCall)
     if (callData->argc < 1)
         return Encode::undefined();
 
-    ExecutionContext *parentContext = engine()->current;
-    ExecutionEngine *engine = parentContext->engine;
+    ExecutionEngine *v4 = engine();
+    ExecutionContext *parentContext = v4->current;
+    ExecutionContextSaver ctxSaver(parentContext);
+
     ExecutionContext *ctx = parentContext;
     Scope scope(ctx);
 
     if (!directCall) {
         // the context for eval should be the global scope, so we fake a root
         // context
-        ctx = engine->pushGlobalContext();
+        ctx = v4->pushGlobalContext();
     }
 
     if (!callData->args[0].isString())
@@ -418,7 +420,6 @@ ReturnedValue EvalFunction::evalCall(CallData *callData, bool directCall)
         return e->call(callData);
     }
 
-    ExecutionContextSaver ctxSaver(parentContext);
     ContextStateSaver stateSaver(ctx);
 
     ExecutionContext::EvalCode evalCode;
@@ -437,7 +438,6 @@ ReturnedValue EvalFunction::evalCall(CallData *callData, bool directCall)
 ReturnedValue EvalFunction::call(Managed *that, CallData *callData)
 {
     // indirect call
-    // ### const_cast
     return static_cast<EvalFunction *>(that)->evalCall(callData, false);
 }