diff options
author | Lars Knoll <[email protected]> | 2013-10-21 09:57:58 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-10-29 10:38:59 +0100 |
commit | af22149dd8daf593182fec978f15dc1667c9cf8d (patch) | |
tree | 17334ae83a3015fd6ca535fb9d2e97b40e1da825 /src/qml/jsruntime/qv4globalobject.cpp | |
parent | 2b996ca17fbc36029af3900933b6fcc1418afb6a (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 <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4globalobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4globalobject.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index d95ab9791f..084b508b52 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -545,6 +545,9 @@ ReturnedValue GlobalFunctions::method_parseFloat(SimpleCallContext *ctx) // [15.1.2.3] step by step: Scoped<String> inputString(scope, ctx->argument(0), Scoped<String>::Convert); + if (scope.engine->hasException) + return Encode::undefined(); + QString trimmed = inputString->toQString().trimmed(); // 2 // 4: @@ -604,7 +607,7 @@ ReturnedValue GlobalFunctions::method_decodeURI(SimpleCallContext *context) if (!ok) { Scope scope(context); ScopedString s(scope, context->engine->newString(QStringLiteral("malformed URI sequence"))); - context->throwURIError(s); + return context->throwURIError(s); } return context->engine->newString(out)->asReturnedValue(); @@ -622,7 +625,7 @@ ReturnedValue GlobalFunctions::method_decodeURIComponent(SimpleCallContext *cont if (!ok) { Scope scope(context); ScopedString s(scope, context->engine->newString(QStringLiteral("malformed URI sequence"))); - context->throwURIError(s); + return context->throwURIError(s); } return context->engine->newString(out)->asReturnedValue(); @@ -640,7 +643,7 @@ ReturnedValue GlobalFunctions::method_encodeURI(SimpleCallContext *context) if (!ok) { Scope scope(context); ScopedString s(scope, context->engine->newString(QStringLiteral("malformed URI sequence"))); - context->throwURIError(s); + return context->throwURIError(s); } return context->engine->newString(out)->asReturnedValue(); @@ -658,7 +661,7 @@ ReturnedValue GlobalFunctions::method_encodeURIComponent(SimpleCallContext *cont if (!ok) { Scope scope(context); ScopedString s(scope, context->engine->newString(QStringLiteral("malformed URI sequence"))); - context->throwURIError(s); + return context->throwURIError(s); } return context->engine->newString(out)->asReturnedValue(); |