diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-10-21 09:57:58 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-29 10:38:59 +0100 |
commit | af22149dd8daf593182fec978f15dc1667c9cf8d (patch) | |
tree | 17334ae83a3015fd6ca535fb9d2e97b40e1da825 /src/qml/jsruntime/qv4dateobject.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 <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4dateobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4dateobject.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index ffc5fa891a..cfc4843ec9 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -1003,7 +1003,7 @@ ReturnedValue DatePrototype::method_setTime(SimpleCallContext *ctx) Scope scope(ctx); Scoped<DateObject> self(scope, ctx->callData->thisObject); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); self->value.setDouble(TimeClip(t)); @@ -1015,7 +1015,7 @@ ReturnedValue DatePrototype::method_setMilliseconds(SimpleCallContext *ctx) Scope scope(ctx); Scoped<DateObject> self(scope, ctx->callData->thisObject); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); double ms = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1027,7 +1027,7 @@ ReturnedValue DatePrototype::method_setUTCMilliseconds(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); double ms = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1039,7 +1039,7 @@ ReturnedValue DatePrototype::method_setSeconds(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); double sec = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1053,7 +1053,7 @@ ReturnedValue DatePrototype::method_setUTCSeconds(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); double sec = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1067,7 +1067,7 @@ ReturnedValue DatePrototype::method_setMinutes(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); double min = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1082,7 +1082,7 @@ ReturnedValue DatePrototype::method_setUTCMinutes(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); double min = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1097,7 +1097,7 @@ ReturnedValue DatePrototype::method_setHours(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); double hour = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1113,7 +1113,7 @@ ReturnedValue DatePrototype::method_setUTCHours(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); double hour = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1129,7 +1129,7 @@ ReturnedValue DatePrototype::method_setDate(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); double date = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1142,7 +1142,7 @@ ReturnedValue DatePrototype::method_setUTCDate(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); double date = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1155,7 +1155,7 @@ ReturnedValue DatePrototype::method_setMonth(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); double month = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1169,7 +1169,7 @@ ReturnedValue DatePrototype::method_setUTCMonth(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); double month = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1183,7 +1183,7 @@ ReturnedValue DatePrototype::method_setYear(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); if (std::isnan(t)) @@ -1209,7 +1209,7 @@ ReturnedValue DatePrototype::method_setUTCFullYear(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); double year = ctx->callData->argc ? ctx->callData->args[0].toNumber() : qSNaN(); @@ -1224,7 +1224,7 @@ ReturnedValue DatePrototype::method_setFullYear(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); if (std::isnan(t)) @@ -1241,7 +1241,7 @@ ReturnedValue DatePrototype::method_toUTCString(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); return ctx->engine->newString(ToUTCString(t))->asReturnedValue(); @@ -1264,11 +1264,11 @@ ReturnedValue DatePrototype::method_toISOString(SimpleCallContext *ctx) { DateObject *self = ctx->callData->thisObject.asDateObject(); if (!self) - ctx->throwTypeError(); + return ctx->throwTypeError(); double t = self->value.asDouble(); if (!std::isfinite(t)) - ctx->throwRangeError(ctx->callData->thisObject); + return ctx->throwRangeError(ctx->callData->thisObject); QString result; int year = (int)YearFromTime(t); @@ -1312,7 +1312,7 @@ ReturnedValue DatePrototype::method_toJSON(SimpleCallContext *ctx) FunctionObject *toIso = v->asFunctionObject(); if (!toIso) - ctx->throwTypeError(); + return ctx->throwTypeError(); ScopedCallData callData(scope, 0); callData->thisObject = ctx->callData->thisObject; |