aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4jsonobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-10-21 09:57:58 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 10:38:59 +0100
commitaf22149dd8daf593182fec978f15dc1667c9cf8d (patch)
tree17334ae83a3015fd6ca535fb9d2e97b40e1da825 /src/qml/jsruntime/qv4jsonobject.cpp
parent2b996ca17fbc36029af3900933b6fcc1418afb6a (diff)
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 <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4jsonobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index 331b528409..721843afba 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -779,8 +779,10 @@ QString Stringify::makeMember(const QString &key, ValueRef v)
QString Stringify::JO(ObjectRef o)
{
- if (stack.contains(o.getPointer()))
+ if (stack.contains(o.getPointer())) {
ctx->throwTypeError();
+ return QString();
+ }
Scope scope(ctx);
@@ -834,8 +836,10 @@ QString Stringify::JO(ObjectRef o)
QString Stringify::JA(ArrayObjectRef a)
{
- if (stack.contains(a.getPointer()))
+ if (stack.contains(a.getPointer())) {
ctx->throwTypeError();
+ return QString();
+ }
Scope scope(a->engine());
@@ -901,7 +905,7 @@ ReturnedValue JsonObject::method_parse(SimpleCallContext *ctx)
ScopedValue result(scope, parser.parse(&error));
if (error.error != QJsonParseError::NoError) {
DEBUG << "parse error" << error.errorString();
- ctx->throwSyntaxError("JSON.parse: Parse error");
+ return ctx->throwSyntaxError("JSON.parse: Parse error");
}
return result.asReturnedValue();