From af22149dd8daf593182fec978f15dc1667c9cf8d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 21 Oct 2013 09:57:58 +0200 Subject: Avoid side effects when en exception has been thrown. We don't want to check for exceptions after every single line on our runtime methods. A better way to handle this is to add the check in all methods that have direct side effects (as e.g. writing to a property of the JS stack). We also need to return whereever we throw an exception. To simplify the code, ExecutionContext::throwXxx methods now return a ReturnedValue (always undefined) for convenience. Change-Id: Ide6c804f819c731a3f14c6c43121d08029c9fb90 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlcontextwrapper.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/qml/qml/qqmlcontextwrapper.cpp') diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index c867b6e126..a187b17a08 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -135,7 +135,7 @@ ReturnedValue QmlContextWrapper::get(Managed *m, const StringRef name, bool *has QV4::Scope scope(v4); QmlContextWrapper *resource = m->as(); if (!resource) - v4->current->throwTypeError(); + return v4->current->throwTypeError(); // In V8 the JS global object would come _before_ the QML global object, // so simulate that here. @@ -282,8 +282,10 @@ void QmlContextWrapper::put(Managed *m, const StringRef name, const ValueRef val ExecutionEngine *v4 = m->engine(); QV4::Scope scope(v4); QV4::Scoped wrapper(scope, m->as()); - if (!wrapper) + if (!wrapper) { v4->current->throwTypeError(); + return; + } if (wrapper->isNullWrapper) { if (wrapper && wrapper->readOnly) { @@ -291,6 +293,7 @@ void QmlContextWrapper::put(Managed *m, const StringRef name, const ValueRef val QLatin1Char('"'); Scoped e(scope, v4->current->engine->newString(error)); v4->current->throwError(e); + return; } Object::put(m, name, value); @@ -341,6 +344,7 @@ void QmlContextWrapper::put(Managed *m, const StringRef name, const ValueRef val QString error = QLatin1String("Invalid write to global property \"") + name->toQString() + QLatin1Char('"'); v4->current->throwError(error); + return; } Object::put(m, name, value); -- cgit v1.2.3