diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-10-22 00:18:31 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2012-10-24 08:46:49 +0200 |
commit | 5f06c71bc1bf146977b6a189491f73ddf8792777 (patch) | |
tree | b4d83b72d235d0adb03db75bce910d2d1278c502 /main.cpp | |
parent | 2c62e69b8d1b49dd440f17c7de2f93be970699cb (diff) |
Proper exception handling
Implement exceptions using setjmp/longjmp. The
advantage is that this removes all exception
handling overhead from regular code, the only
code that still has a (very small) overhead
is the try{} catch() {} statement.
Change-Id: I43d6a60dfc9dfd4b7a20d2e99ab0a9315b4d8a2f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -44,6 +44,7 @@ #endif #include "qmljs_objects.h" +#include "qmljs_runtime.h" #include "qv4codegen_p.h" #include "qv4isel_masm_p.h" #include "qv4isel_moth_p.h" @@ -239,7 +240,6 @@ static void evaluate(QQmlJS::VM::Context *ctx, const QString &fileName, const QS return; } - ctx->hasUncaughtException = false; if (! ctx->activation.isObject()) ctx->activation = VM::Value::fromObject(new QQmlJS::VM::Object()); @@ -247,6 +247,15 @@ static void evaluate(QQmlJS::VM::Context *ctx, const QString &fileName, const QS ctx->activation.objectValue()->setProperty(ctx, *local, QQmlJS::VM::Value::undefinedValue()); } + void * buf = __qmljs_create_exception_handler(ctx); + if (setjmp(*(jmp_buf *)buf)) { + if (VM::ErrorObject *e = ctx->result.asErrorObject()) + std::cerr << "Uncaught exception: " << qPrintable(e->value.toString(ctx)->toQString()) << std::endl; + else + std::cerr << "Uncaught exception: " << qPrintable(ctx->result.toString(ctx)->toQString()) << std::endl; + return; + } + if (useMoth) { Moth::VME vme; vme(ctx, code); @@ -254,12 +263,7 @@ static void evaluate(QQmlJS::VM::Context *ctx, const QString &fileName, const QS globalCode->code(ctx, globalCode->codeData); } - if (ctx->hasUncaughtException) { - if (VM::ErrorObject *e = ctx->result.asErrorObject()) - std::cerr << "Uncaught exception: " << qPrintable(e->value.toString(ctx)->toQString()) << std::endl; - else - std::cerr << "Uncaught exception: " << qPrintable(ctx->result.toString(ctx)->toQString()) << std::endl; - } else if (! ctx->result.isUndefined()) { + if (! ctx->result.isUndefined()) { if (! qgetenv("SHOW_EXIT_VALUE").isNull()) std::cout << "exit value: " << qPrintable(ctx->result.toString(ctx)->toQString()) << std::endl; } |