Move the exception variable into the engine
authorLars Knoll <lars.knoll@digia.com>
Mon, 19 Nov 2012 21:24:12 +0000 (22:24 +0100)
committerErik Verbruggen <erik.verbruggen@digia.com>
Tue, 20 Nov 2012 09:43:19 +0000 (10:43 +0100)
It's easier to store this in the engine then
in the execution context.

Change-Id: I01ff447602a7d785165e774bdf6e1735c073be2d
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
main.cpp
qmljs_engine.h
qmljs_environment.cpp
qmljs_environment.h
qmljs_runtime.cpp

index 7467568..c9e3170 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -309,10 +309,10 @@ int main(int argc, char *argv[])
 
                 void * buf = __qmljs_create_exception_handler(ctx);
                 if (setjmp(*(jmp_buf *)buf)) {
-                    if (QQmlJS::VM::ErrorObject *e = ctx->res.asErrorObject())
+                    if (QQmlJS::VM::ErrorObject *e = ctx->engine->exception.asErrorObject())
                         std::cerr << "Uncaught exception: " << qPrintable(e->value.toString(ctx)->toQString()) << std::endl;
                     else
-                        std::cerr << "Uncaught exception: " << qPrintable(ctx->res.toString(ctx)->toQString()) << std::endl;
+                        std::cerr << "Uncaught exception: " << qPrintable(ctx->engine->exception.toString(ctx)->toQString()) << std::endl;
                     return EXIT_FAILURE;
                 }
 
index d22cd85..2404ebd 100644 (file)
@@ -136,6 +136,7 @@ struct ExecutionEngine
     };
 
     QVector<ExceptionHandler> unwindStack;
+    Value exception;
 
     ExecutionEngine(EValISelFactory *factory);
 
index 87f8543..121670c 100644 (file)
@@ -171,7 +171,7 @@ void ExecutionContext::init(ExecutionEngine *eng)
     variableEnvironment = new DeclarativeEnvironment(eng);
     lexicalEnvironment = variableEnvironment;
     thisObject = Value::nullValue();
-    res = Value::undefinedValue();
+    eng->exception = Value::undefinedValue();
 }
 
 PropertyDescriptor *ExecutionContext::lookupPropertyDescriptor(String *name, PropertyDescriptor *tmp)
@@ -235,7 +235,6 @@ void ExecutionContext::initCallContext(ExecutionContext *parent, const Value tha
     lexicalEnvironment = variableEnvironment;
 
     thisObject = that;
-    res = Value::undefinedValue();
 }
 
 void ExecutionContext::leaveCallContext()
index 8fe14b2..b16c0f9 100644 (file)
@@ -90,7 +90,6 @@ struct ExecutionContext
     DeclarativeEnvironment *lexicalEnvironment;
     DeclarativeEnvironment *variableEnvironment;
     Value thisObject;
-    Value res;
 
     void init(ExecutionEngine *eng);
 
index a81a6a9..20ea184 100644 (file)
@@ -844,13 +844,14 @@ void __qmljs_throw(Value value, ExecutionContext *context)
         context = context->parent;
     }
 
-    handler.context->res = value;
+    context->engine->exception = value;
 
     longjmp(handler.stackFrame, 1);
 }
 
 void *__qmljs_create_exception_handler(ExecutionContext *context)
 {
+    context->engine->exception = Value::undefinedValue();
     context->engine->unwindStack.append(ExecutionEngine::ExceptionHandler());
     ExecutionEngine::ExceptionHandler &handler = context->engine->unwindStack.last();
     handler.context = context;
@@ -866,7 +867,7 @@ void __qmljs_delete_exception_handler(ExecutionContext *context)
 
 Value __qmljs_get_exception(ExecutionContext *context)
 {
-    return context->res;
+    return context->engine->exception;
 }
 
 Value __qmljs_builtin_typeof(Value val, ExecutionContext *context)