Change exception handling API
authorSimon Hausmann <simon.hausmann@digia.com>
Wed, 11 Sep 2013 11:23:21 +0000 (13:23 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 2 Oct 2013 14:07:33 +0000 (16:07 +0200)
commitc860d1399b4ff5f3a5b1b2630bc33112c88c13e8
tree3e6cdd7b209cc343dd791827d07bb69a700e7043
parentc1d66eec1dbaf9034e03e3efa0403a774c764373
Change exception handling API

This patch changes the exception handling API in the engine slightly, encapsulating
any use of direct throw statements and catch blocks with concrete types. In the future
we need to be able to change the way these are implemented, in order to ensure that
the correct stack unwinding code is triggered for throw and re-throw.

This patch separates the C++ exception object thrown from the V4 exception
(that includes value, throwing context pointer) and stores the latter inside
the engine.

In order for that to compile, ExecutionEngine::StackTrace and StackFrame had to
move into the QV4 namespace directly.

In addition the syntax for catching exceptions changes from

try {
    ...
} catch (QV4::Exception &ex) {
    ex.accept(context);
    QV4::ScopedValue exceptionValue(scope, ex.value());
}

to

try {
    ...
} catch (...) {
    QV4::ScopedValue exception(scope, context->catchException());
}

Context::catchException() checks if there's a "current" exception in the engine,
and if not assumes that we caught an unrelated exception and consequently re-throws.

partiallyUnwind() is also gone and replaced with rethrowException(), in order to
encapsulate the re-throw.

Lastly, in the future nesting try/catch blocks isn't going to be possible due to
limitations in the common C++ ABI with regards to foreign exceptions.

Change-Id: Ic81c75b057a2147e3176d8e0b4d326c14278b47d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
40 files changed:
src/imports/localstorage/plugin.cpp
src/imports/testlib/main.cpp
src/qml/compiler/qv4isel_masm.cpp
src/qml/jsapi/qjsengine.cpp
src/qml/jsapi/qjsvalue.cpp
src/qml/jsapi/qjsvalueiterator.cpp
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4context_p.h
src/qml/jsruntime/qv4engine.cpp
src/qml/jsruntime/qv4engine_p.h
src/qml/jsruntime/qv4errorobject.cpp
src/qml/jsruntime/qv4errorobject_p.h
src/qml/jsruntime/qv4exception.cpp
src/qml/jsruntime/qv4exception_gcc.cpp
src/qml/jsruntime/qv4exception_p.h
src/qml/jsruntime/qv4function_p.h
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4global_p.h
src/qml/jsruntime/qv4globalobject.cpp
src/qml/jsruntime/qv4include.cpp
src/qml/jsruntime/qv4qobjectwrapper.cpp
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4script.cpp
src/qml/jsruntime/qv4sequenceobject.cpp
src/qml/jsruntime/qv4serialize.cpp
src/qml/jsruntime/qv4value.cpp
src/qml/jsruntime/qv4vme_moth.cpp
src/qml/qml/qqmlcomponent.cpp
src/qml/qml/qqmlerror.cpp
src/qml/qml/qqmlerror.h
src/qml/qml/qqmljavascriptexpression.cpp
src/qml/qml/qqmljavascriptexpression_p.h
src/qml/qml/qqmltypeloader.cpp
src/qml/qml/qqmlvaluetypewrapper.cpp
src/qml/qml/qqmlvmemetaobject.cpp
src/qml/qml/qqmlxmlhttprequest.cpp
src/qml/qml/v8/qqmlbuiltinfunctions.cpp
src/qml/types/qquickworkerscript.cpp
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
tools/v4/main.cpp