summaryrefslogtreecommitdiff
path: root/src/qml/jsruntime/qv4functionobject.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/qv4functionobject.cpp
parent2b996ca17fbc36029af3900933b6fcc1418afb6a (diff)
downloadqtdeclarative-af22149dd8daf593182fec978f15dc1667c9cf8d.tar.gz
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/qv4functionobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 3e28024bbf..b2ef86525f 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -166,8 +166,10 @@ bool FunctionObject::hasInstance(Managed *that, const ValueRef value)
return false;
Scoped<Object> o(scope, f->get(scope.engine->id_prototype));
- if (!o)
+ if (!o) {
scope.engine->current->throwTypeError();
+ return false;
+ }
while (v) {
v = v->prototype();
@@ -259,13 +261,13 @@ ReturnedValue FunctionCtor::construct(Managed *that, CallData *callData)
const bool parsed = parser.parseExpression();
if (!parsed)
- f->engine()->current->throwSyntaxError(0);
+ return f->engine()->current->throwSyntaxError(0);
using namespace QQmlJS::AST;
FunctionExpression *fe = QQmlJS::AST::cast<FunctionExpression *>(parser.rootNode());
ExecutionEngine *v4 = f->engine();
if (!fe)
- v4->current->throwSyntaxError(0);
+ return v4->current->throwSyntaxError(0);
QQmlJS::V4IR::Module module(v4->debugger != 0);
@@ -312,7 +314,7 @@ ReturnedValue FunctionPrototype::method_toString(SimpleCallContext *ctx)
{
FunctionObject *fun = ctx->callData->thisObject.asFunctionObject();
if (!fun)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
return ctx->engine->newString(QStringLiteral("function() { [code] }"))->asReturnedValue();
}
@@ -322,7 +324,7 @@ ReturnedValue FunctionPrototype::method_apply(SimpleCallContext *ctx)
Scope scope(ctx);
FunctionObject *o = ctx->callData->thisObject.asFunctionObject();
if (!o)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
ScopedValue arg(scope, ctx->argument(1));
@@ -331,10 +333,8 @@ ReturnedValue FunctionPrototype::method_apply(SimpleCallContext *ctx)
quint32 len;
if (!arr) {
len = 0;
- if (!arg->isNullOrUndefined()) {
- ctx->throwTypeError();
- return Encode::undefined();
- }
+ if (!arg->isNullOrUndefined())
+ return ctx->throwTypeError();
} else {
len = ArrayPrototype::getLength(ctx, arr);
}
@@ -364,7 +364,7 @@ ReturnedValue FunctionPrototype::method_call(SimpleCallContext *ctx)
FunctionObject *o = ctx->callData->thisObject.asFunctionObject();
if (!o)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
ScopedCallData callData(scope, ctx->callData->argc ? ctx->callData->argc - 1 : 0);
if (ctx->callData->argc) {
@@ -380,7 +380,7 @@ ReturnedValue FunctionPrototype::method_bind(SimpleCallContext *ctx)
Scope scope(ctx);
Scoped<FunctionObject> target(scope, ctx->callData->thisObject);
if (!target)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
ScopedValue boundThis(scope, ctx->argument(0));
QVector<SafeValue> boundArgs;
@@ -568,8 +568,7 @@ BuiltinFunction::BuiltinFunction(ExecutionContext *scope, const StringRef name,
ReturnedValue BuiltinFunction::construct(Managed *f, CallData *)
{
- f->engine()->current->throwTypeError();
- return Encode::undefined();
+ return f->engine()->current->throwTypeError();
}
ReturnedValue BuiltinFunction::call(Managed *that, CallData *callData)