diff options
author | Lars Knoll <[email protected]> | 2017-01-05 13:39:38 +0100 |
---|---|---|
committer | Lars Knoll <[email protected]> | 2017-01-25 08:31:17 +0000 |
commit | afc29a54791e70264f7c175b2da0a234f791f749 (patch) | |
tree | ea591cd4322c861e0aeb5cd5f5ae3fdfecb6cc66 /src | |
parent | cea4a039d713173d423c35fa56a6994a4ebefd2c (diff) |
Convert more builtin methods to the new calling convention
Change-Id: I2cd1df437d91918001beed8dfe92d553b3bb377f
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4booleanobject.cpp | 26 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4booleanobject_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4dateobject.cpp | 475 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4dateobject_p.h | 102 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4numberobject.cpp | 160 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4numberobject_p.h | 16 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 395 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4stringobject_p.h | 46 | ||||
-rw-r--r-- | src/qml/qml/qqmllocale.cpp | 485 | ||||
-rw-r--r-- | src/qml/qml/qqmllocale_p.h | 82 |
10 files changed, 891 insertions, 900 deletions
diff --git a/src/qml/jsruntime/qv4booleanobject.cpp b/src/qml/jsruntime/qv4booleanobject.cpp index 8047993266..601066110f 100644 --- a/src/qml/jsruntime/qv4booleanobject.cpp +++ b/src/qml/jsruntime/qv4booleanobject.cpp @@ -73,29 +73,31 @@ void BooleanPrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(engine->id_valueOf(), method_valueOf); } -ReturnedValue BooleanPrototype::method_toString(CallContext *ctx) +void BooleanPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData) { bool result; - if (ctx->thisObject().isBoolean()) { - result = ctx->thisObject().booleanValue(); + if (callData->thisObject.isBoolean()) { + result = callData->thisObject.booleanValue(); } else { - const BooleanObject *thisObject = ctx->thisObject().as<BooleanObject>(); + const BooleanObject *thisObject = callData->thisObject.as<BooleanObject>(); if (!thisObject) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); result = thisObject->value(); } - return Encode(ctx->d()->engine->newString(QLatin1String(result ? "true" : "false"))); + scope.result = scope.engine->newString(QLatin1String(result ? "true" : "false")); } -ReturnedValue BooleanPrototype::method_valueOf(CallContext *ctx) +void BooleanPrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (ctx->thisObject().isBoolean()) - return ctx->thisObject().asReturnedValue(); + if (callData->thisObject.isBoolean()) { + scope.result = callData->thisObject.asReturnedValue(); + return; + } - const BooleanObject *thisObject = ctx->thisObject().as<BooleanObject>(); + const BooleanObject *thisObject = callData->thisObject.as<BooleanObject>(); if (!thisObject) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); - return Encode(thisObject->value()); + scope.result = Encode(thisObject->value()); } diff --git a/src/qml/jsruntime/qv4booleanobject_p.h b/src/qml/jsruntime/qv4booleanobject_p.h index 4c2f3c09e7..9c8b1d67f1 100644 --- a/src/qml/jsruntime/qv4booleanobject_p.h +++ b/src/qml/jsruntime/qv4booleanobject_p.h @@ -78,8 +78,8 @@ struct BooleanPrototype: BooleanObject { void init(ExecutionEngine *engine, Object *ctor); - static ReturnedValue method_toString(CallContext *ctx); - static ReturnedValue method_valueOf(CallContext *ctx); + static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData); }; diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index 8cc6a25fea..b90c335b1c 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -780,435 +780,435 @@ void DatePrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(QStringLiteral("toJSON"), method_toJSON, 1); } -double DatePrototype::getThisDate(ExecutionContext *ctx) +double DatePrototype::getThisDate(Scope &scope, CallData *callData) { - if (DateObject *thisObject = ctx->thisObject().as<DateObject>()) + if (DateObject *thisObject = callData->thisObject.as<DateObject>()) return thisObject->date(); else { - ctx->engine()->throwTypeError(); + scope.engine->throwTypeError(); return 0; } } -ReturnedValue DatePrototype::method_parse(CallContext *ctx) +void DatePrototype::method_parse(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (!ctx->argc()) - return Encode(qt_qnan()); - return Encode(ParseString(ctx->args()[0].toQString())); + if (!callData->argc) + scope.result = Encode(qt_qnan()); + else + scope.result = Encode(ParseString(callData->args[0].toQString())); } -ReturnedValue DatePrototype::method_UTC(CallContext *ctx) +void DatePrototype::method_UTC(const BuiltinFunction *, Scope &scope, CallData *callData) { - const int numArgs = ctx->argc(); + const int numArgs = callData->argc; if (numArgs >= 2) { - double year = ctx->args()[0].toNumber(); - double month = ctx->args()[1].toNumber(); - double day = numArgs >= 3 ? ctx->args()[2].toNumber() : 1; - double hours = numArgs >= 4 ? ctx->args()[3].toNumber() : 0; - double mins = numArgs >= 5 ? ctx->args()[4].toNumber() : 0; - double secs = numArgs >= 6 ? ctx->args()[5].toNumber() : 0; - double ms = numArgs >= 7 ? ctx->args()[6].toNumber() : 0; + double year = callData->args[0].toNumber(); + double month = callData->args[1].toNumber(); + double day = numArgs >= 3 ? callData->args[2].toNumber() : 1; + double hours = numArgs >= 4 ? callData->args[3].toNumber() : 0; + double mins = numArgs >= 5 ? callData->args[4].toNumber() : 0; + double secs = numArgs >= 6 ? callData->args[5].toNumber() : 0; + double ms = numArgs >= 7 ? callData->args[6].toNumber() : 0; if (year >= 0 && year <= 99) year += 1900; double t = MakeDate(MakeDay(year, month, day), MakeTime(hours, mins, secs, ms)); - return Encode(TimeClip(t)); + scope.result = Encode(TimeClip(t)); + return; } - return Encode::undefined(); + RETURN_UNDEFINED(); } -ReturnedValue DatePrototype::method_now(CallContext *ctx) +void DatePrototype::method_now(const BuiltinFunction *, Scope &scope, CallData *callData) { - Q_UNUSED(ctx); + Q_UNUSED(callData); double t = currentTime(); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_toString(CallContext *ctx) +void DatePrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return ctx->d()->engine->newString(ToString(t))->asReturnedValue(); + double t = getThisDate(scope, callData); + scope.result = scope.engine->newString(ToString(t)); } -ReturnedValue DatePrototype::method_toDateString(CallContext *ctx) +void DatePrototype::method_toDateString(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return ctx->d()->engine->newString(ToDateString(t))->asReturnedValue(); + double t = getThisDate(scope, callData); + scope.result = scope.engine->newString(ToDateString(t)); } -ReturnedValue DatePrototype::method_toTimeString(CallContext *ctx) +void DatePrototype::method_toTimeString(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return ctx->d()->engine->newString(ToTimeString(t))->asReturnedValue(); + double t = getThisDate(scope, callData); + scope.result = scope.engine->newString(ToTimeString(t)); } -ReturnedValue DatePrototype::method_toLocaleString(CallContext *ctx) +void DatePrototype::method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return ctx->d()->engine->newString(ToLocaleString(t))->asReturnedValue(); + double t = getThisDate(scope, callData); + scope.result = scope.engine->newString(ToLocaleString(t)); } -ReturnedValue DatePrototype::method_toLocaleDateString(CallContext *ctx) +void DatePrototype::method_toLocaleDateString(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return ctx->d()->engine->newString(ToLocaleDateString(t))->asReturnedValue(); + double t = getThisDate(scope, callData); + scope.result = scope.engine->newString(ToLocaleDateString(t)); } -ReturnedValue DatePrototype::method_toLocaleTimeString(CallContext *ctx) +void DatePrototype::method_toLocaleTimeString(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return ctx->d()->engine->newString(ToLocaleTimeString(t))->asReturnedValue(); + double t = getThisDate(scope, callData); + scope.result = scope.engine->newString(ToLocaleTimeString(t)); } -ReturnedValue DatePrototype::method_valueOf(CallContext *ctx) +void DatePrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return Encode(t); + double t = getThisDate(scope, callData); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getTime(CallContext *ctx) +void DatePrototype::method_getTime(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - return Encode(t); + double t = getThisDate(scope, callData); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getYear(CallContext *ctx) +void DatePrototype::method_getYear(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = YearFromTime(LocalTime(t)) - 1900; - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getFullYear(CallContext *ctx) +void DatePrototype::method_getFullYear(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = YearFromTime(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCFullYear(CallContext *ctx) +void DatePrototype::method_getUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = YearFromTime(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getMonth(CallContext *ctx) +void DatePrototype::method_getMonth(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = MonthFromTime(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCMonth(CallContext *ctx) +void DatePrototype::method_getUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = MonthFromTime(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getDate(CallContext *ctx) +void DatePrototype::method_getDate(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = DateFromTime(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCDate(CallContext *ctx) +void DatePrototype::method_getUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = DateFromTime(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getDay(CallContext *ctx) +void DatePrototype::method_getDay(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = WeekDay(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCDay(CallContext *ctx) +void DatePrototype::method_getUTCDay(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = WeekDay(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getHours(CallContext *ctx) +void DatePrototype::method_getHours(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = HourFromTime(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCHours(CallContext *ctx) +void DatePrototype::method_getUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = HourFromTime(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getMinutes(CallContext *ctx) +void DatePrototype::method_getMinutes(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = MinFromTime(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCMinutes(CallContext *ctx) +void DatePrototype::method_getUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = MinFromTime(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getSeconds(CallContext *ctx) +void DatePrototype::method_getSeconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = SecFromTime(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCSeconds(CallContext *ctx) +void DatePrototype::method_getUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = SecFromTime(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getMilliseconds(CallContext *ctx) +void DatePrototype::method_getMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = msFromTime(LocalTime(t)); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getUTCMilliseconds(CallContext *ctx) +void DatePrototype::method_getUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = msFromTime(t); - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_getTimezoneOffset(CallContext *ctx) +void DatePrototype::method_getTimezoneOffset(const BuiltinFunction *, Scope &scope, CallData *callData) { - double t = getThisDate(ctx); - if (! std::isnan(t)) + double t = getThisDate(scope, callData); + if (!std::isnan(t)) t = (t - LocalTime(t)) / msPerMinute; - return Encode(t); + scope.result = Encode(t); } -ReturnedValue DatePrototype::method_setTime(CallContext *ctx) +void DatePrototype::method_setTime(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - Scoped<DateObject> self(scope, ctx->thisObject()); + Scoped<DateObject> self(scope, callData->thisObject); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); - double t = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); + double t = callData->argc ? callData->args[0].toNumber() : qt_qnan(); self->setDate(TimeClip(t)); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setMilliseconds(CallContext *ctx) +void DatePrototype::method_setMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - Scoped<DateObject> self(scope, ctx->thisObject()); + Scoped<DateObject> self(scope, callData->thisObject); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = LocalTime(self->date()); - double ms = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); + double ms = callData->argc ? callData->args[0].toNumber() : qt_qnan(); self->setDate(TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms))))); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setUTCMilliseconds(CallContext *ctx) +void DatePrototype::method_setUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - double ms = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); + double ms = callData->argc ? callData->args[0].toNumber() : qt_qnan(); self->setDate(TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms)))); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setSeconds(CallContext *ctx) +void DatePrototype::method_setSeconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = LocalTime(self->date()); - double sec = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double ms = (ctx->argc() < 2) ? msFromTime(t) : ctx->args()[1].toNumber(); + double sec = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double ms = (callData->argc < 2) ? msFromTime(t) : callData->args[1].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms)))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setUTCSeconds(CallContext *ctx) +void DatePrototype::method_setUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - double sec = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double ms = (ctx->argc() < 2) ? msFromTime(t) : ctx->args()[1].toNumber(); + double sec = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double ms = (callData->argc < 2) ? msFromTime(t) : callData->args[1].toNumber(); t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setMinutes(CallContext *ctx) +void DatePrototype::method_setMinutes(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = LocalTime(self->date()); - double min = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double sec = (ctx->argc() < 2) ? SecFromTime(t) : ctx->args()[1].toNumber(); - double ms = (ctx->argc() < 3) ? msFromTime(t) : ctx->args()[2].toNumber(); + double min = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double sec = (callData->argc < 2) ? SecFromTime(t) : callData->args[1].toNumber(); + double ms = (callData->argc < 3) ? msFromTime(t) : callData->args[2].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms)))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setUTCMinutes(CallContext *ctx) +void DatePrototype::method_setUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - double min = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double sec = (ctx->argc() < 2) ? SecFromTime(t) : ctx->args()[1].toNumber(); - double ms = (ctx->argc() < 3) ? msFromTime(t) : ctx->args()[2].toNumber(); + double min = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double sec = (callData->argc < 2) ? SecFromTime(t) : callData->args[1].toNumber(); + double ms = (callData->argc < 3) ? msFromTime(t) : callData->args[2].toNumber(); t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setHours(CallContext *ctx) +void DatePrototype::method_setHours(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = LocalTime(self->date()); - double hour = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double min = (ctx->argc() < 2) ? MinFromTime(t) : ctx->args()[1].toNumber(); - double sec = (ctx->argc() < 3) ? SecFromTime(t) : ctx->args()[2].toNumber(); - double ms = (ctx->argc() < 4) ? msFromTime(t) : ctx->args()[3].toNumber(); + double hour = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double min = (callData->argc < 2) ? MinFromTime(t) : callData->args[1].toNumber(); + double sec = (callData->argc < 3) ? SecFromTime(t) : callData->args[2].toNumber(); + double ms = (callData->argc < 4) ? msFromTime(t) : callData->args[3].toNumber(); t = TimeClip(UTC(MakeDate(Day(t), MakeTime(hour, min, sec, ms)))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setUTCHours(CallContext *ctx) +void DatePrototype::method_setUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - double hour = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double min = (ctx->argc() < 2) ? MinFromTime(t) : ctx->args()[1].toNumber(); - double sec = (ctx->argc() < 3) ? SecFromTime(t) : ctx->args()[2].toNumber(); - double ms = (ctx->argc() < 4) ? msFromTime(t) : ctx->args()[3].toNumber(); + double hour = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double min = (callData->argc < 2) ? MinFromTime(t) : callData->args[1].toNumber(); + double sec = (callData->argc < 3) ? SecFromTime(t) : callData->args[2].toNumber(); + double ms = (callData->argc < 4) ? msFromTime(t) : callData->args[3].toNumber(); t = TimeClip(MakeDate(Day(t), MakeTime(hour, min, sec, ms))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setDate(CallContext *ctx) +void DatePrototype::method_setDate(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = LocalTime(self->date()); - double date = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); + double date = callData->argc ? callData->args[0].toNumber() : qt_qnan(); t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t)))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setUTCDate(CallContext *ctx) +void DatePrototype::method_setUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - double date = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); + double date = callData->argc ? callData->args[0].toNumber() : qt_qnan(); t = TimeClip(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setMonth(CallContext *ctx) +void DatePrototype::method_setMonth(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = LocalTime(self->date()); - double month = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double date = (ctx->argc() < 2) ? DateFromTime(t) : ctx->args()[1].toNumber(); + double month = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double date = (callData->argc < 2) ? DateFromTime(t) : callData->args[1].toNumber(); t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t)))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setUTCMonth(CallContext *ctx) +void DatePrototype::method_setUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - double month = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double date = (ctx->argc() < 2) ? DateFromTime(t) : ctx->args()[1].toNumber(); + double month = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double date = (callData->argc < 2) ? DateFromTime(t) : callData->args[1].toNumber(); t = TimeClip(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setYear(CallContext *ctx) +void DatePrototype::method_setYear(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); if (std::isnan(t)) t = 0; else t = LocalTime(t); - double year = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); + double year = callData->argc ? callData->args[0].toNumber() : qt_qnan(); double r; if (std::isnan(year)) { r = qt_qnan(); @@ -1220,49 +1220,49 @@ ReturnedValue DatePrototype::method_setYear(CallContext *ctx) r = TimeClip(r); } self->setDate(r); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setUTCFullYear(CallContext *ctx) +void DatePrototype::method_setUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - double year = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double month = (ctx->argc() < 2) ? MonthFromTime(t) : ctx->args()[1].toNumber(); - double date = (ctx->argc() < 3) ? DateFromTime(t) : ctx->args()[2].toNumber(); + double year = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double month = (callData->argc < 2) ? MonthFromTime(t) : callData->args[1].toNumber(); + double date = (callData->argc < 3) ? DateFromTime(t) : callData->args[2].toNumber(); t = TimeClip(MakeDate(MakeDay(year, month, date), TimeWithinDay(t))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_setFullYear(CallContext *ctx) +void DatePrototype::method_setFullYear(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = LocalTime(self->date()); if (std::isnan(t)) t = 0; - double year = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan(); - double month = (ctx->argc() < 2) ? MonthFromTime(t) : ctx->args()[1].toNumber(); - double date = (ctx->argc() < 3) ? DateFromTime(t) : ctx->args()[2].toNumber(); + double year = callData->argc ? callData->args[0].toNumber() : qt_qnan(); + double month = (callData->argc < 2) ? MonthFromTime(t) : callData->args[1].toNumber(); + double date = (callData->argc < 3) ? DateFromTime(t) : callData->args[2].toNumber(); t = TimeClip(UTC(MakeDate(MakeDay(year, month, date), TimeWithinDay(t)))); self->setDate(t); - return Encode(self->date()); + scope.result = Encode(self->date()); } -ReturnedValue DatePrototype::method_toUTCString(CallContext *ctx) +void DatePrototype::method_toUTCString(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); - return ctx->d()->engine->newString(ToUTCString(t))->asReturnedValue(); + scope.result = scope.engine->newString(ToUTCString(t)); } static void addZeroPrefixedInt(QString &str, int num, int nDigits) @@ -1278,21 +1278,21 @@ static void addZeroPrefixedInt(QString &str, int num, int nDigits) } } -ReturnedValue DatePrototype::method_toISOString(CallContext *ctx) +void DatePrototype::method_toISOString(const BuiltinFunction *, Scope &scope, CallData *callData) { - DateObject *self = ctx->thisObject().as<DateObject>(); + DateObject *self = callData->thisObject.as<DateObject>(); if (!self) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); double t = self->date(); if (!std::isfinite(t)) - return ctx->engine()->throwRangeError(ctx->thisObject()); + RETURN_RESULT(scope.engine->throwRangeError(callData->thisObject)); QString result; int year = (int)YearFromTime(t); if (year < 0 || year > 9999) { if (qAbs(year) >= 1000000) - return ctx->d()->engine->newString(QStringLiteral("Invalid Date"))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(QStringLiteral("Invalid Date"))); result += year < 0 ? QLatin1Char('-') : QLatin1Char('+'); year = qAbs(year); addZeroPrefixedInt(result, year, 6); @@ -1313,32 +1313,29 @@ ReturnedValue DatePrototype::method_toISOString(CallContext *ctx) addZeroPrefixedInt(result, msFromTime(t), 3); result += QLatin1Char('Z'); - return ctx->d()->engine->newString(result)->asReturnedValue(); + scope.result = scope.engine->newString(result); } -ReturnedValue DatePrototype::method_toJSON(CallContext *ctx) +void DatePrototype::method_toJSON(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - ScopedObject O(scope, ctx->thisObject().toObject(scope.engine)); - if (scope.hasException()) - return Encode::undefined(); + ScopedObject O(scope, callData->thisObject.toObject(scope.engine)); + CHECK_EXCEPTION(); ScopedValue tv(scope, RuntimeHelpers::toPrimitive(O, NUMBER_HINT)); if (tv->isNumber() && !std::isfinite(tv->toNumber())) - return Encode::null(); + RETURN_RESULT(Encode::null()); - ScopedString s(scope, ctx->d()->engine->newString(QStringLiteral("toISOString"))); + ScopedString s(scope, scope.engine->newString(QStringLiteral("toISOString"))); ScopedValue v(scope, O->get(s)); FunctionObject *toIso = v->as<FunctionObject>(); if (!toIso) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); - ScopedCallData callData(scope); - callData->thisObject = ctx->thisObject(); - toIso->call(scope, callData); - return scope.result.asReturnedValue(); + ScopedCallData cData(scope); + cData->thisObject = callData->thisObject; + toIso->call(scope, cData); } void DatePrototype::timezoneUpdated() diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h index 835f6adbe0..a56d17f9b1 100644 --- a/src/qml/jsruntime/qv4dateobject_p.h +++ b/src/qml/jsruntime/qv4dateobject_p.h @@ -116,57 +116,57 @@ struct DatePrototype: DateObject { void init(ExecutionEngine *engine, Object *ctor); - static double getThisDate(ExecutionContext *ctx); - - static ReturnedValue method_parse(CallContext *ctx); - static ReturnedValue method_UTC(CallContext *ctx); - static ReturnedValue method_now(CallContext *ctx); - - static ReturnedValue method_toString(CallContext *ctx); - static ReturnedValue method_toDateString(CallContext *ctx); - static ReturnedValue method_toTimeString(CallContext *ctx); - static ReturnedValue method_toLocaleString(CallContext *ctx); - static ReturnedValue method_toLocaleDateString(CallContext *ctx); - static ReturnedValue method_toLocaleTimeString(CallContext *ctx); - static ReturnedValue method_valueOf(CallContext *ctx); - static ReturnedValue method_getTime(CallContext *ctx); - static ReturnedValue method_getYear(CallContext *ctx); - static ReturnedValue method_getFullYear(CallContext *ctx); - static ReturnedValue method_getUTCFullYear(CallContext *ctx); - static ReturnedValue method_getMonth(CallContext *ctx); - static ReturnedValue method_getUTCMonth(CallContext *ctx); - static ReturnedValue method_getDate(CallContext *ctx); - static ReturnedValue method_getUTCDate(CallContext *ctx); - static ReturnedValue method_getDay(CallContext *ctx); - static ReturnedValue method_getUTCDay(CallContext *ctx); - static ReturnedValue method_getHours(CallContext *ctx); - static ReturnedValue method_getUTCHours(CallContext *ctx); - static ReturnedValue method_getMinutes(CallContext *ctx); - static ReturnedValue method_getUTCMinutes(CallContext *ctx); - static ReturnedValue method_getSeconds(CallContext *ctx); - static ReturnedValue method_getUTCSeconds(CallContext *ctx); - static ReturnedValue method_getMilliseconds(CallContext *ctx); - static ReturnedValue method_getUTCMilliseconds(CallContext *ctx); - static ReturnedValue method_getTimezoneOffset(CallContext *ctx); - static ReturnedValue method_setTime(CallContext *ctx); - static ReturnedValue method_setMilliseconds(CallContext *ctx); - static ReturnedValue method_setUTCMilliseconds(CallContext *ctx); - static ReturnedValue method_setSeconds(CallContext *ctx); - static ReturnedValue method_setUTCSeconds(CallContext *ctx); - static ReturnedValue method_setMinutes(CallContext *ctx); - static ReturnedValue method_setUTCMinutes(CallContext *ctx); - static ReturnedValue method_setHours(CallContext *ctx); - static ReturnedValue method_setUTCHours(CallContext *ctx); - static ReturnedValue method_setDate(CallContext *ctx); - static ReturnedValue method_setUTCDate(CallContext *ctx); - static ReturnedValue method_setMonth(CallContext *ctx); - static ReturnedValue method_setUTCMonth(CallContext *ctx); - static ReturnedValue method_setYear(CallContext *ctx); - static ReturnedValue method_setFullYear(CallContext *ctx); - static ReturnedValue method_setUTCFullYear(CallContext *ctx); - static ReturnedValue method_toUTCString(CallContext *ctx); - static ReturnedValue method_toISOString(CallContext *ctx); - static ReturnedValue method_toJSON(CallContext *ctx); + static double getThisDate(Scope &scope, CallData *callData); + + static void method_parse(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_UTC(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_now(const BuiltinFunction *, Scope &scope, CallData *callData); + + static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toDateString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toTimeString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toLocaleDateString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toLocaleTimeString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getTime(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getYear(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getFullYear(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getMonth(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getDate(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getDay(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCDay(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getHours(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getMinutes(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getSeconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_getTimezoneOffset(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setTime(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setSeconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setMinutes(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setHours(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setDate(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setMonth(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setYear(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setFullYear(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_setUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toUTCString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toISOString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toJSON(const BuiltinFunction *, Scope &scope, CallData *callData); static void timezoneUpdated(); }; diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index 3a6b9da763..09644c161d 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -120,61 +120,71 @@ QT_WARNING_POP defineDefaultProperty(QStringLiteral("toPrecision"), method_toPrecision); } -inline ReturnedValue thisNumberValue(ExecutionContext *ctx) +inline ReturnedValue thisNumberValue(Scope &scope, CallData *callData) { - if (ctx->thisObject().isNumber()) - return ctx->thisObject().asReturnedValue(); - NumberObject *n = ctx->thisObject().as<NumberObject>(); - if (!n) - return ctx->engine()->throwTypeError(); + if (callData->thisObject.isNumber()) + return callData->thisObject.asReturnedValue(); + NumberObject *n = callData->thisObject.as<NumberObject>(); + if (!n) { + scope.engine->throwTypeError(); + return Encode::undefined(); + } return Encode(n->value()); } -inline double thisNumber(ExecutionContext *ctx) +inline double thisNumber(Scope &scope, CallData *callData) { - if (ctx->thisObject().isNumber()) - return ctx->thisObject().asDouble(); - NumberObject *n = ctx->thisObject().as<NumberObject>(); - if (!n) - return ctx->engine()->throwTypeError(); + if (callData->thisObject.isNumber()) + return callData->thisObject.asDouble(); + NumberObject *n = callData->thisObject.as<NumberObject>(); + if (!n) { + scope.engine->throwTypeError(); + return 0; + } return n->value(); } -ReturnedValue NumberPrototype::method_isFinite(CallContext *ctx) +void NumberPrototype::method_isFinite(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (!ctx->argc()) - return Encode(false); + if (!callData->argc) { + scope.result = Encode(false); + return; + } - double v = ctx->args()[0].toNumber(); - return Encode(!std::isnan(v) && !qt_is_inf(v)); + double v = callData->args[0].toNumber(); + scope.result = Encode(!std::isnan(v) && !qt_is_inf(v)); } -ReturnedValue NumberPrototype::method_isNaN(CallContext *ctx) +void NumberPrototype::method_isNaN(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (!ctx->argc()) - return Encode(false); + if (!callData->argc) { + scope.result = Encode(false); + return; + } - double v = ctx->args()[0].toNumber(); - return Encode(std::isnan(v)); + double v = callData->args[0].toNumber(); + scope.result = Encode(std::isnan(v)); } -ReturnedValue NumberPrototype::method_toString(CallContext *ctx) +void NumberPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - double num = thisNumber(ctx); - if (scope.engine->hasException) - return Encode::undefined(); + double num = thisNumber(scope, callData); + CHECK_EXCEPTION(); - if (ctx->argc() && !ctx->args()[0].isUndefined()) { - int radix = ctx->args()[0].toInt32(); - if (radix < 2 || radix > 36) - return ctx->engine()->throwError(QStringLiteral("Number.prototype.toString: %0 is not a valid radix") + if (callData->argc && !callData->args[0].isUndefined()) { + int radix = callData->args[0].toInt32(); + if (radix < 2 || radix > 36) { + scope.result = scope.engine->throwError(QStringLiteral("Number.prototype.toString: %0 is not a valid radix") .arg(radix)); + return; + } if (std::isnan(num)) { - return scope.engine->newString(QStringLiteral("NaN"))->asReturnedValue(); + scope.result = scope.engine->newString(QStringLiteral("NaN")); + return; } else if (qt_is_inf(num)) { - return scope.engine->newString(QLatin1String(num < 0 ? "-Infinity" : "Infinity"))->asReturnedValue(); + scope.result = scope.engine->newString(QLatin1String(num < 0 ? "-Infinity" : "Infinity")); + return; } if (radix != 10) { @@ -204,45 +214,43 @@ ReturnedValue NumberPrototype::method_toString(CallContext *ctx) } if (negative) str.prepend(QLatin1Char('-')); - return scope.engine->newString(str)->asReturnedValue(); + scope.result = scope.engine->newString(str); + return; } } - return Primitive::fromDouble(num).toString(scope.engine)->asReturnedValue(); + scope.result = Primitive::fromDouble(num).toString(scope.engine); } -ReturnedValue NumberPrototype::method_toLocaleString(CallContext *ctx) +void NumberPrototype::method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - ScopedValue v(scope, thisNumberValue(ctx)); - ScopedString str(scope, v->toString(scope.engine)); - if (scope.engine->hasException) - return Encode::undefined(); - return str.asReturnedValue(); + ScopedValue v(scope, thisNumberValue(scope, callData)); + scope.result = v->toString(scope.engine); + CHECK_EXCEPTION(); } -ReturnedValue NumberPrototype::method_valueOf(CallContext *ctx) +void NumberPrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData) { - return thisNumberValue(ctx); + scope.result = thisNumberValue(scope, callData); } -ReturnedValue NumberPrototype::method_toFixed(CallContext *ctx) +void NumberPrototype::method_toFixed(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - double v = thisNumber(ctx); - if (scope.engine->hasException) - return Encode::undefined(); + double v = thisNumber(scope, callData); + CHECK_EXCEPTION(); double fdigits = 0; - if (ctx->argc() > 0) - fdigits = ctx->args()[0].toInteger(); + if (callData->argc > 0) + fdigits = callData->args[0].toInteger(); if (std::isnan(fdigits)) fdigits = 0; - if (fdigits < 0 || fdigits > 20) - return ctx->engine()->throwRangeError(ctx->thisObject()); + if (fdigits < 0 || fdigits > 20) { + scope.result = scope.engine->throwRangeError(callData->thisObject); + return; + } QString str; if (std::isnan(v)) @@ -251,48 +259,50 @@ ReturnedValue NumberPrototype::method_toFixed(CallContext *ctx) str = QString::fromLatin1(v < 0 ? "-Infinity" : "Infinity"); else if (v < 1.e21) str = NumberLocale::instance()->toString(v, 'f', int(fdigits)); - else - return RuntimeHelpers::stringFromNumber(ctx->engine(), v)->asReturnedValue(); - return scope.engine->newString(str)->asReturnedValue(); + else { + scope.result = RuntimeHelpers::stringFromNumber(scope.engine, v); + return; + } + scope.result = scope.engine->newString(str); } -ReturnedValue NumberPrototype::method_toExponential(CallContext *ctx) +void NumberPrototype::method_toExponential(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - double d = thisNumber(ctx); - if (scope.engine->hasException) - return Encode::undefined(); + double d = thisNumber(scope, callData); + CHECK_EXCEPTION(); int fdigits = NumberLocale::instance()->defaultDoublePrecision; - if (ctx->argc() && !ctx->args()[0].isUndefined()) { - fdigits = ctx->args()[0].toInt32(); + if (callData->argc && !callData->args[0].isUndefined()) { + fdigits = callData->args[0].toInt32(); if (fdigits < 0 || fdigits > 20) { ScopedString error(scope, scope.engine->newString(QStringLiteral("Number.prototype.toExponential: fractionDigits out of range"))); - return ctx->engine()->throwRangeError(error); + scope.result = scope.engine->throwRangeError(error); + return; } } QString result = NumberLocale::instance()->toString(d, 'e', fdigits); - return scope.engine->newString(result)->asReturnedValue(); + scope.result = scope.engine->newString(result); } -ReturnedValue NumberPrototype::method_toPrecision(CallContext *ctx) +void NumberPrototype::method_toPrecision(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - ScopedValue v(scope, thisNumberValue(ctx)); - if (scope.engine->hasException) - return Encode::undefined(); + ScopedValue v(scope, thisNumberValue(scope, callData)); + CHECK_EXCEPTION(); - if (!ctx->argc() || ctx->args()[0].isUndefined()) - return Encode(v->toString(scope.engine)); + if (!callData->argc || callData->args[0].isUndefined()) { + scope.result = v->toString(scope.engine); + return; + } - int precision = ctx->args()[0].toInt32(); + int precision = callData->args[0].toInt32(); if (precision < 1 || precision > 21) { ScopedString error(scope, scope.engine->newString(QStringLiteral("Number.prototype.toPrecision: precision out of range"))); - return ctx->engine()->throwRangeError(error); + scope.result = scope.engine->throwRangeError(error); + return; } QString result = NumberLocale::instance()->toString(v->asDouble(), 'g', precision); - return scope.engine->newString(result)->asReturnedValue(); + scope.result = scope.engine->newString(result); } diff --git a/src/qml/jsruntime/qv4numberobject_p.h b/src/qml/jsruntime/qv4numberobject_p.h index 6022b3a029..364b866a16 100644 --- a/src/qml/jsruntime/qv4numberobject_p.h +++ b/src/qml/jsruntime/qv4numberobject_p.h @@ -87,14 +87,14 @@ struct NumberPrototype: NumberObject { void init(ExecutionEngine *engine, Object *ctor); - static ReturnedValue method_isFinite(CallContext *ctx); - static ReturnedValue method_isNaN(CallContext *ctx); - static ReturnedValue method_toString(CallContext *ctx); - static ReturnedValue method_toLocaleString(CallContext *ctx); - static ReturnedValue method_valueOf(CallContext *ctx); - static ReturnedValue method_toFixed(CallContext *ctx); - static ReturnedValue method_toExponential(CallContext *ctx); - static ReturnedValue method_toPrecision(CallContext *ctx); + static void method_isFinite(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_isNaN(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toFixed(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toExponential(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toPrecision(const BuiltinFunction *, Scope &scope, CallData *callData); }; diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 6fbf1c3c85..3c6a24e035 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -214,10 +214,9 @@ void StringPrototype::init(ExecutionEngine *engine, Object *ctor) defineDefaultProperty(QStringLiteral("trim"), method_trim); } -static QString getThisString(ExecutionContext *ctx) +static QString getThisString(Scope &scope, CallData *callData) { - Scope scope(ctx); - ScopedValue t(scope, ctx->thisObject()); + ScopedValue t(scope, callData->thisObject); if (String *s = t->stringValue()) return s->toQString(); if (StringObject *thisString = t->as<StringObject>()) @@ -229,158 +228,146 @@ static QString getThisString(ExecutionContext *ctx) return t->toQString(); } -ReturnedValue StringPrototype::method_toString(CallContext *context) +void StringPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (context->thisObject().isString()) - return context->thisObject().asReturnedValue(); + if (callData->thisObject.isString()) + RETURN_RESULT(callData->thisObject); - StringObject *o = context->thisObject().as<StringObject>(); + StringObject *o = callData->thisObject.as<StringObject>(); if (!o) - return context->engine()->throwTypeError(); - return Encode(o->d()->string); + THROW_TYPE_ERROR(); + scope.result = o->d()->string; } -ReturnedValue StringPrototype::method_charAt(CallContext *context) +void StringPrototype::method_charAt(const BuiltinFunction *, Scope &scope, CallData *callData) { - const QString str = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + const QString str = getThisString(scope, callData); + CHECK_EXCEPTION(); int pos = 0; - if (context->argc() > 0) - pos = (int) context->args()[0].toInteger(); + if (callData->argc > 0) + pos = (int) callData->args[0].toInteger(); QString result; if (pos >= 0 && pos < str.length()) result += str.at(pos); - return context->d()->engine->newString(result)->asReturnedValue(); + scope.result = scope.engine->newString(result); } -ReturnedValue StringPrototype::method_charCodeAt(CallContext *context) +void StringPrototype::method_charCodeAt(const BuiltinFunction *, Scope &scope, CallData *callData) { - const QString str = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + const QString str = getThisString(scope, callData); + CHECK_EXCEPTION(); int pos = 0; - if (context->argc() > 0) - pos = (int) context->args()[0].toInteger(); + if (callData->argc > 0) + pos = (int) callData->args[0].toInteger(); if (pos >= 0 && pos < str.length()) - return Encode(str.at(pos).unicode()); + RETURN_RESULT(Encode(str.at(pos).unicode())); - return Encode(qt_qnan()); + scope.result = Encode(qt_qnan()); } -ReturnedValue StringPrototype::method_concat(CallContext *context) +void StringPrototype::method_concat(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(context); - - QString value = getThisString(context); - if (scope.engine->hasException) - return Encode::undefined(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); ScopedString s(scope); - for (int i = 0; i < context->argc(); ++i) { - s = context->args()[i].toString(scope.engine); - if (scope.hasException()) - return Encode::undefined(); + for (int i = 0; i < callData->argc; ++i) { + s = callData->args[i].toString(scope.engine); + CHECK_EXCEPTION(); + Q_ASSERT(s->isString()); value += s->toQString(); } - return context->d()->engine->newString(value)->asReturnedValue(); + scope.result = scope.engine->newString(value); } -ReturnedValue StringPrototype::method_endsWith(CallContext *context) +void StringPrototype::method_endsWith(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString value = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); QString searchString; - if (context->argc()) { - if (context->args()[0].as<RegExpObject>()) - return context->engine()->throwTypeError(); - searchString = context->args()[0].toQString(); + if (callData->argc) { + if (callData->args[0].as<RegExpObject>()) + THROW_TYPE_ERROR(); + searchString = callData->args[0].toQString(); } int pos = value.length(); - if (context->argc() > 1) - pos = (int) context->args()[1].toInteger(); + if (callData->argc > 1) + pos = (int) callData->args[1].toInteger(); if (pos == value.length()) - return Encode(value.endsWith(searchString)); + RETURN_RESULT(Encode(value.endsWith(searchString))); QStringRef stringToSearch = value.leftRef(pos); - return Encode(stringToSearch.endsWith(searchString)); + scope.result = Encode(stringToSearch.endsWith(searchString)); } -ReturnedValue StringPrototype::method_indexOf(CallContext *context) +void StringPrototype::method_indexOf(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString value = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); QString searchString; - if (context->argc()) - searchString = context->args()[0].toQString(); + if (callData->argc) + searchString = callData->args[0].toQString(); int pos = 0; - if (context->argc() > 1) - pos = (int) context->args()[1].toInteger(); + if (callData->argc > 1) + pos = (int) callData->args[1].toInteger(); int index = -1; if (! value.isEmpty()) index = value.indexOf(searchString, qMin(qMax(pos, 0), value.length())); - return Encode(index); + scope.result = Encode(index); } -ReturnedValue StringPrototype::method_includes(CallContext *context) +void StringPrototype::method_includes(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString value = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); QString searchString; - if (context->argc()) { - if (context->args()[0].as<RegExpObject>()) - return context->engine()->throwTypeError(); - searchString = context->args()[0].toQString(); + if (callData->argc) { + if (callData->args[0].as<RegExpObject>()) + THROW_TYPE_ERROR(); + searchString = callData->args[0].toQString(); } int pos = 0; - if (context->argc() > 1) { - Scope scope(context); - ScopedValue posArg(scope, context->argument(1)); + if (callData->argc > 1) { + ScopedValue posArg(scope, callData->argument(1)); pos = (int) posArg->toInteger(); if (!posArg->isInteger() && posArg->isNumber() && qIsInf(posArg->toNumber())) pos = value.length(); } if (pos == 0) - return Encode(value.contains(searchString)); + RETURN_RESULT(Encode(value.contains(searchString))); QStringRef stringToSearch = value.midRef(pos); - return Encode(stringToSearch.contains(searchString)); + scope.result = Encode(stringToSearch.contains(searchString)); } -ReturnedValue StringPrototype::method_lastIndexOf(CallContext *context) +void StringPrototype::method_lastIndexOf(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(context); - - const QString value = getThisString(context); - if (scope.engine->hasException) - return Encode::undefined(); + const QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); QString searchString; - if (context->argc()) - searchString = context->args()[0].toQString(); + if (callData->argc) + searchString = callData->args[0].toQString(); - ScopedValue posArg(scope, context->argument(1)); + ScopedValue posArg(scope, callData->argument(1)); double position = RuntimeHelpers::toNumber(posArg); if (std::isnan(position)) position = +qInf(); @@ -391,43 +378,40 @@ ReturnedValue StringPrototype::method_lastIndexOf(CallContext *context) if (!searchString.isEmpty() && pos == value.length()) --pos; if (searchString.isNull() && pos == 0) - return Encode(-1); + RETURN_RESULT(Encode(-1)); int index = value.lastIndexOf(searchString, pos); - return Encode(index); + scope.result = Encode(index); } -ReturnedValue StringPrototype::method_localeCompare(CallContext *context) +void StringPrototype::method_localeCompare(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(context); - const QString value = getThisString(context); - if (scope.engine->hasException) - return Encode::undefined(); + const QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); - ScopedValue v(scope, context->argument(0)); + ScopedValue v(scope, callData->argument(0)); const QString that = v->toQString(); - return Encode(QString::localeAwareCompare(value, that)); + scope.result = Encode(QString::localeAwareCompare(value, that)); } -ReturnedValue StringPrototype::method_match(CallContext *context) +void StringPrototype::method_match(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (context->thisObject().isUndefined() || context->thisObject().isNull()) - return context->engine()->throwTypeError(); + if (callData->thisObject.isUndefined() || callData->thisObject.isNull()) + THROW_TYPE_ERROR(); - Scope scope(context); - ScopedString s(scope, context->thisObject().toString(scope.engine)); + ScopedString s(scope, callData->thisObject.toString(scope.engine)); - ScopedValue regexp(scope, context->argument(0)); + ScopedValue regexp(scope, callData->argument(0)); Scoped<RegExpObject> rx(scope, regexp); if (!rx) { ScopedCallData callData(scope, 1); callData->args[0] = regexp; - context->d()->engine->regExpCtor()->construct(scope, callData); + scope.engine->regExpCtor()->construct(scope, callData); rx = scope.result.asReturnedValue(); } if (!rx) // ### CHECK - return context->engine()->throwTypeError(); + THROW_TYPE_ERROR(); bool global = rx->global(); @@ -435,24 +419,24 @@ ReturnedValue StringPrototype::method_match(CallContext *context) ScopedString execString(scope, scope.engine->newString(QStringLiteral("exec"))); ScopedFunctionObject exec(scope, scope.engine->regExpPrototype()->get(execString)); - ScopedCallData callData(scope, 1); - callData->thisObject = rx; - callData->args[0] = s; + ScopedCallData cData(scope, 1); + cData->thisObject = rx; + cData->args[0] = s; if (!global) { - exec->call(scope, callData); - return scope.result.asReturnedValue(); + exec->call(scope, cData); + return; } - ScopedString lastIndex(scope, context->d()->engine->newString(QStringLiteral("lastIndex"))); + ScopedString lastIndex(scope, scope.engine->newString(QStringLiteral("lastIndex"))); rx->put(lastIndex, ScopedValue(scope, Primitive::fromInt32(0))); - ScopedArrayObject a(scope, context->d()->engine->newArrayObject()); + ScopedArrayObject a(scope, scope.engine->newArrayObject()); double previousLastIndex = 0; uint n = 0; ScopedValue matchStr(scope); ScopedValue index(scope); while (1) { - exec->call(scope, callData); + exec->call(scope, cData); if (scope.result.isNull()) break; assert(scope.result.isObject()); @@ -469,10 +453,9 @@ ReturnedValue StringPrototype::method_match(CallContext *context) ++n; } if (!n) - return Encode::null(); - - return a.asReturnedValue(); - + scope.result = Encode::null(); + else + scope.result = a; } static void appendReplacementString(QString *result, const QString &input, const QString& replaceValue, uint* matchOffsets, int captureCount) @@ -521,14 +504,13 @@ static void appendReplacementString(QString *result, const QString &input, const } } -ReturnedValue StringPrototype::method_replace(CallContext *ctx) +void StringPrototype::method_replace(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); QString string; - if (StringObject *thisString = ctx->thisObject().as<StringObject>()) + if (StringObject *thisString = callData->thisObject.as<StringObject>()) string = thisString->d()->string->toQString(); else - string = ctx->thisObject().toQString(); + string = callData->thisObject.toQString(); int numCaptures = 0; int numStringMatches = 0; @@ -537,7 +519,7 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx) uint _matchOffsets[64]; uint *matchOffsets = _matchOffsets; - ScopedValue searchValue(scope, ctx->argument(0)); + ScopedValue searchValue(scope, callData->argument(0)); Scoped<RegExpObject> regExp(scope, searchValue); if (regExp) { uint offset = 0; @@ -580,7 +562,7 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx) } QString result; - ScopedValue replaceValue(scope, ctx->argument(1)); + ScopedValue replaceValue(scope, callData->argument(1)); ScopedFunctionObject searchCallback(scope, replaceValue); if (!!searchCallback) { result.reserve(string.length() + 10*numStringMatches); @@ -595,14 +577,14 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx) uint end = matchOffsets[idx + 1]; entry = Primitive::undefinedValue(); if (start != JSC::Yarr::offsetNoMatch && end != JSC::Yarr::offsetNoMatch) - entry = ctx->d()->engine->newString(string.mid(start, end - start)); + entry = scope.engine->newString(string.mid(start, end - start)); callData->args[k] = entry; } uint matchStart = matchOffsets[i * numCaptures * 2]; Q_ASSERT(matchStart >= static_cast<uint>(lastEnd)); uint matchEnd = matchOffsets[i * numCaptures * 2 + 1]; callData->args[numCaptures] = Primitive::fromUInt32(matchStart); - callData->args[numCaptures + 1] = ctx->d()->engine->newString(string); + callData->args[numCaptures + 1] = scope.engine->newString(string); searchCallback->call(scope, callData); result += string.midRef(lastEnd, matchStart - lastEnd); @@ -632,23 +614,22 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx) if (matchOffsets != _matchOffsets) free(matchOffsets); - return ctx->d()->engine->newString(result)->asReturnedValue(); + scope.result = scope.engine->newString(result); } -ReturnedValue StringPrototype::method_search(CallContext *ctx) +void StringPrototype::method_search(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - QString string = getThisString(ctx); - scope.result = ctx->argument(0); - if (scope.engine->hasException) - return Encode::undefined(); + QString string = getThisString(scope, callData); + scope.result = callData->argument(0); + CHECK_EXCEPTION(); + Scoped<RegExpObject> regExp(scope, scope.result.as<RegExpObject>()); if (!regExp) { ScopedCallData callData(scope, 1); callData->args[0] = scope.result; - ctx->d()->engine->regExpCtor()->construct(scope, callData); - if (scope.engine->hasException) - return Encode::undefined(); + scope.engine->regExpCtor()->construct(scope, callData); + CHECK_EXCEPTION(); + regExp = scope.result.as<RegExpObject>(); Q_ASSERT(regExp); } @@ -656,21 +637,21 @@ ReturnedValue StringPrototype::method_search(CallContext *ctx) uint* matchOffsets = (uint*)alloca(regExp->value()->captureCount() * 2 * sizeof(uint)); uint result = re->match(string, /*offset*/0, matchOffsets); if (result == JSC::Yarr::offsetNoMatch) - return Encode(-1); - return Encode(result); + scope.result = Encode(-1); + else + scope.result = Encode(result); } -ReturnedValue StringPrototype::method_slice(CallContext *ctx) +void StringPrototype::method_slice(const BuiltinFunction *, Scope &scope, CallData *callData) { - const QString text = getThisString(ctx); - if (ctx->d()->engine->hasException) - return Encode::undefined(); + const QString text = getThisString(scope, callData); + CHECK_EXCEPTION(); const double length = text.length(); - double start = ctx->argc() ? ctx->args()[0].toInteger() : 0; - double end = (ctx->argc() < 2 || ctx->args()[1].isUndefined()) - ? length : ctx->args()[1].toInteger(); + double start = callData->argc ? callData->args[0].toInteger() : 0; + double end = (callData->argc < 2 || callData->args[1].isUndefined()) + ? length : callData->args[1].toInteger(); if (start < 0) start = qMax(length + start, 0.); @@ -686,40 +667,38 @@ ReturnedValue StringPrototype::method_slice(CallContext *ctx) const int intEnd = int(end); int count = qMax(0, intEnd - intStart); - return ctx->d()->engine->newString(text.mid(intStart, count))->asReturnedValue(); + scope.result = scope.engine->newString(text.mid(intStart, count)); } -ReturnedValue StringPrototype::method_split(CallContext *ctx) +void StringPrototype::method_split(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - QString text = getThisString(ctx); - if (scope.engine->hasException) - return Encode::undefined(); + QString text = getThisString(scope, callData); + CHECK_EXCEPTION(); - ScopedValue separatorValue(scope, ctx->argument(0)); - ScopedValue limitValue(scope, ctx->argument(1)); + ScopedValue separatorValue(scope, callData->argument(0)); + ScopedValue limitValue(scope, callData->argument(1)); - ScopedArrayObject array(scope, ctx->d()->engine->newArrayObject()); + ScopedArrayObject array(scope, scope.engine->newArrayObject()); if (separatorValue->isUndefined()) { if (limitValue->isUndefined()) { - ScopedString s(scope, ctx->d()->engine->newString(text)); + ScopedString s(scope, scope.engine->newString(text)); array->push_back(s); - return array.asReturnedValue(); + RETURN_RESULT(array); } - return ctx->d()->engine->newString(text.left(limitValue->toInteger()))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(text.left(limitValue->toInteger()))); } uint limit = limitValue->isUndefined() ? UINT_MAX : limitValue->toUInt32(); if (limit == 0) - return array.asReturnedValue(); + RETURN_RESULT(array); Scoped<RegExpObject> re(scope, separatorValue); if (re) { if (re->value()->pattern->isEmpty()) { re = (RegExpObject *)0; - separatorValue = ctx->d()->engine->newString(); + separatorValue = scope.engine->newString(); } } @@ -733,7 +712,7 @@ ReturnedValue StringPrototype::method_split(CallContext *ctx) if (result == JSC::Yarr::offsetNoMatch) break; - array->push_back((s = ctx->d()->engine->newString(text.mid(offset, matchOffsets[0] - offset)))); + array->push_back((s = scope.engine->newString(text.mid(offset, matchOffsets[0] - offset)))); offset = qMax(offset + 1, matchOffsets[1]); if (array->getLength() >= limit) @@ -742,72 +721,70 @@ ReturnedValue StringPrototype::method_split(CallContext *ctx) for (int i = 1; i < re->value()->captureCount(); ++i) { uint start = matchOffsets[i * 2]; uint end = matchOffsets[i * 2 + 1]; - array->push_back((s = ctx->d()->engine->newString(text.mid(start, end - start)))); + array->push_back((s = scope.engine->newString(text.mid(start, end - start)))); if (array->getLength() >= limit) break; } } if (array->getLength() < limit) - array->push_back((s = ctx->d()->engine->newString(text.mid(offset)))); + array->push_back((s = scope.engine->newString(text.mid(offset)))); } else { QString separator = separatorValue->toQString(); if (separator.isEmpty()) { for (uint i = 0; i < qMin(limit, uint(text.length())); ++i) - array->push_back((s = ctx->d()->engine->newString(text.mid(i, 1)))); - return array.asReturnedValue(); + array->push_back((s = scope.engine->newString(text.mid(i, 1)))); + RETURN_RESULT(array); } int start = 0; int end; while ((end = text.indexOf(separator, start)) != -1) { - array->push_back((s = ctx->d()->engine->newString(text.mid(start, end - start)))); + array->push_back((s = scope.engine->newString(text.mid(start, end - start)))); start = end + separator.size(); if (array->getLength() >= limit) break; } if (array->getLength() < limit && start != -1) - array->push_back((s = ctx->d()->engine->newString(text.mid(start)))); + array->push_back((s = scope.engine->newString(text.mid(start)))); } - return array.asReturnedValue(); + RETURN_RESULT(array); } -ReturnedValue StringPrototype::method_startsWith(CallContext *context) +void StringPrototype::method_startsWith(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString value = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); QString searchString; - if (context->argc()) { - if (context->args()[0].as<RegExpObject>()) - return context->engine()->throwTypeError(); - searchString = context->args()[0].toQString(); + if (callData->argc) { + if (callData->args[0].as<RegExpObject>()) + THROW_TYPE_ERROR(); + searchString = callData->args[0].toQString(); } int pos = 0; - if (context->argc() > 1) - pos = (int) context->args()[1].toInteger(); + if (callData->argc > 1) + pos = (int) callData->args[1].toInteger(); if (pos == 0) - return Encode(value.startsWith(searchString)); + RETURN_RESULT(Encode(value.startsWith(searchString))); QStringRef stringToSearch = value.midRef(pos); - return Encode(stringToSearch.startsWith(searchString)); + RETURN_RESULT(Encode(stringToSearch.startsWith(searchString))); } -ReturnedValue StringPrototype::method_substr(CallContext *context) +void StringPrototype::method_substr(const BuiltinFunction *, Scope &scope, CallData *callData) { - const QString value = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + const QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); double start = 0; - if (context->argc() > 0) - start = context->args()[0].toInteger(); + if (callData->argc > 0) + start = callData->args[0].toInteger(); double length = +qInf(); - if (context->argc() > 1) - length = context->args()[1].toInteger(); + if (callData->argc > 1) + length = callData->args[1].toInteger(); double count = value.length(); if (start < 0) @@ -817,24 +794,23 @@ ReturnedValue StringPrototype::method_substr(CallContext *context) qint32 x = Primitive::toInt32(start); qint32 y = Primitive::toInt32(length); - return context->d()->engine->newString(value.mid(x, y))->asReturnedValue(); + scope.result = scope.engine->newString(value.mid(x, y)); } -ReturnedValue StringPrototype::method_substring(CallContext *context) +void StringPrototype::method_substring(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString value = getThisString(context); - if (context->d()->engine->hasException) - return Encode::undefined(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); + int length = value.length(); double start = 0; double end = length; - if (context->argc() > 0) - start = context->args()[0].toInteger(); + if (callData->argc > 0) + start = callData->args[0].toInteger(); - Scope scope(context); - ScopedValue endValue(scope, context->argument(1)); + ScopedValue endValue(scope, callData->argument(1)); if (!endValue->isUndefined()) end = endValue->toInteger(); @@ -858,51 +834,50 @@ ReturnedValue StringPrototype::method_substring(CallContext *context) qint32 x = (int)start; qint32 y = (int)(end - start); - return context->d()->engine->newString(value.mid(x, y))->asReturnedValue(); + scope.result = scope.engine->newString(value.mid(x, y)); } -ReturnedValue StringPrototype::method_toLowerCase(CallContext *ctx) +void StringPrototype::method_toLowerCase(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString value = getThisString(ctx); - if (ctx->d()->engine->hasException) - return Encode::undefined(); - return ctx->d()->engine->newString(value.toLower())->asReturnedValue(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); + + scope.result = scope.engine->newString(value.toLower()); } -ReturnedValue StringPrototype::method_toLocaleLowerCase(CallContext *ctx) +void StringPrototype::method_toLocaleLowerCase(const BuiltinFunction *b, Scope &scope, CallData *callData) { - return method_toLowerCase(ctx); + method_toLowerCase(b, scope, callData); } -ReturnedValue StringPrototype::method_toUpperCase(CallContext *ctx) +void StringPrototype::method_toUpperCase(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString value = getThisString(ctx); - if (ctx->d()->engine->hasException) - return Encode::undefined(); - return ctx->d()->engine->newString(value.toUpper())->asReturnedValue(); + QString value = getThisString(scope, callData); + CHECK_EXCEPTION(); + + scope.result = scope.engine->newString(value.toUpper()); } -ReturnedValue StringPrototype::method_toLocaleUpperCase(CallContext *ctx) +void StringPrototype::method_toLocaleUpperCase(const BuiltinFunction *b, Scope &scope, CallData *callData) { - return method_toUpperCase(ctx); + return method_toUpperCase(b, scope, callData); } -ReturnedValue StringPrototype::method_fromCharCode(CallContext *context) +void StringPrototype::method_fromCharCode(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString str(context->argc(), Qt::Uninitialized); + QString str(callData->argc, Qt::Uninitialized); QChar *ch = str.data(); - for (int i = 0; i < context->argc(); ++i) { - *ch = QChar(context->args()[i].toUInt16()); + for (int i = 0; i < callData->argc; ++i) { + *ch = QChar(callData->args[i].toUInt16()); ++ch; } - return context->d()->engine->newString(str)->asReturnedValue(); + scope.result = scope.engine->newString(str); } -ReturnedValue StringPrototype::method_trim(CallContext *ctx) +void StringPrototype::method_trim(const BuiltinFunction *, Scope &scope, CallData *callData) { - QString s = getThisString(ctx); - if (ctx->d()->engine->hasException) - return Encode::undefined(); + QString s = getThisString(scope, callData); + CHECK_EXCEPTION(); const QChar *chars = s.constData(); int start, end; @@ -915,5 +890,5 @@ ReturnedValue StringPrototype::method_trim(CallContext *ctx) break; } - return ctx->d()->engine->newString(QString(chars + start, end - start + 1))->asReturnedValue(); + scope.result = scope.engine->newString(QString(chars + start, end - start + 1)); } diff --git a/src/qml/jsruntime/qv4stringobject_p.h b/src/qml/jsruntime/qv4stringobject_p.h index b9f9d44fe8..0ee7a6ece9 100644 --- a/src/qml/jsruntime/qv4stringobject_p.h +++ b/src/qml/jsruntime/qv4stringobject_p.h @@ -111,29 +111,29 @@ struct StringPrototype: StringObject { void init(ExecutionEngine *engine, Object *ctor); - static ReturnedValue method_toString(CallContext *context); - static ReturnedValue method_charAt(CallContext *context); - static ReturnedValue method_charCodeAt(CallContext *context); - static ReturnedValue method_concat(CallContext *context); - static ReturnedValue method_endsWith(CallContext *ctx); - static ReturnedValue method_indexOf(CallContext *context); - static ReturnedValue method_includes(CallContext *context); - static ReturnedValue method_lastIndexOf(CallContext *context); - static ReturnedValue method_localeCompare(CallContext *context); - static ReturnedValue method_match(CallContext *context); - static ReturnedValue method_replace(CallContext *ctx); - static ReturnedValue method_search(CallContext *ctx); - static ReturnedValue method_slice(CallContext *ctx); - static ReturnedValue method_split(CallContext *ctx); - static ReturnedValue method_startsWith(CallContext *ctx); - static ReturnedValue method_substr(CallContext *context); - static ReturnedValue method_substring(CallContext *context); - static ReturnedValue method_toLowerCase(CallContext *ctx); - static ReturnedValue method_toLocaleLowerCase(CallContext *ctx); - static ReturnedValue method_toUpperCase(CallContext *ctx); - static ReturnedValue method_toLocaleUpperCase(CallContext *ctx); - static ReturnedValue method_fromCharCode(CallContext *context); - static ReturnedValue method_trim(CallContext *ctx); + static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_charAt(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_charCodeAt(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_concat(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_endsWith(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_indexOf(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_includes(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_lastIndexOf(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_localeCompare(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_match(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_replace(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_search(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_slice(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_split(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_startsWith(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_substr(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_substring(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toLowerCase(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toLocaleLowerCase(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toUpperCase(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toLocaleUpperCase(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_fromCharCode(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_trim(const BuiltinFunction *, Scope &scope, CallData *callData); }; } diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index 3876e774c3..712da78807 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -56,10 +56,17 @@ using namespace QV4; DEFINE_OBJECT_VTABLE(QQmlLocaleData); +#define THROW_ERROR(string) \ + do { \ + scope.result = scope.engine->throwError(QString::fromUtf8(string)); \ + return; \ + } while (false) + + #define GET_LOCALE_DATA_RESOURCE(OBJECT) \ QV4::Scoped<QQmlLocaleData> r(scope, OBJECT.as<QQmlLocaleData>()); \ if (!r) \ - V4THROW_ERROR("Not a valid Locale object") + THROW_ERROR("Not a valid Locale object") static bool isLocaleObject(const QV4::Value &val) { @@ -80,215 +87,219 @@ void QQmlDateExtension::registerExtension(QV4::ExecutionEngine *engine) engine->dateCtor()->defineDefaultProperty(QStringLiteral("timeZoneUpdated"), method_timeZoneUpdated); } -QV4::ReturnedValue QQmlDateExtension::method_toLocaleString(QV4::CallContext *ctx) +void QQmlDateExtension::method_toLocaleString(const BuiltinFunction *b, Scope &scope, CallData *callData) { - if (ctx->argc() > 2) - return QV4::DatePrototype::method_toLocaleString(ctx); - - QV4::Scope scope(ctx); + if (callData->argc > 2) { + QV4::DatePrototype::method_toLocaleString(b, scope, callData); + return; + } - QV4::DateObject *date = ctx->thisObject().as<DateObject>(); - if (!date) - return QV4::DatePrototype::method_toLocaleString(ctx); + QV4::DateObject *date = callData->thisObject.as<DateObject>(); + if (!date) { + QV4::DatePrototype::method_toLocaleString(b, scope, callData); + return; + } QDateTime dt = date->toQDateTime(); - if (ctx->argc() == 0) { + if (callData->argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return ctx->d()->engine->newString(locale.toString(dt))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(locale.toString(dt))); } - if (!isLocaleObject(ctx->args()[0])) - return QV4::DatePrototype::method_toLocaleString(ctx); // Use the default Date toLocaleString() + if (!isLocaleObject(callData->args[0])) { + QV4::DatePrototype::method_toLocaleString(b, scope, callData); // Use the default Date toLocaleString() + return; + } - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QString formattedDt; - if (ctx->argc() == 2) { - if (String *s = ctx->args()[1].stringValue()) { + if (callData->argc == 2) { + if (String *s = callData->args[1].stringValue()) { QString format = s->toQString(); formattedDt = r->d()->locale->toString(dt, format); - } else if (ctx->args()[1].isNumber()) { - quint32 intFormat = ctx->args()[1].toNumber(); + } else if (callData->args[1].isNumber()) { + quint32 intFormat = callData->args[1].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); formattedDt = r->d()->locale->toString(dt, format); } else { - V4THROW_ERROR("Locale: Date.toLocaleString(): Invalid datetime format"); + THROW_ERROR("Locale: Date.toLocaleString(): Invalid datetime format"); } } else { formattedDt = r->d()->locale->toString(dt, enumFormat); } - return ctx->d()->engine->newString(formattedDt)->asReturnedValue(); + scope.result = scope.engine->newString(formattedDt); } -QV4::ReturnedValue QQmlDateExtension::method_toLocaleTimeString(QV4::CallContext *ctx) +void QQmlDateExtension::method_toLocaleTimeString(const BuiltinFunction *b, Scope &scope, CallData *callData) { - if (ctx->argc() > 2) - return QV4::DatePrototype::method_toLocaleTimeString(ctx); - - QV4::Scope scope(ctx); + if (callData->argc > 2) { + QV4::DatePrototype::method_toLocaleTimeString(b, scope, callData); + return; + } - QV4::DateObject *date = ctx->thisObject().as<DateObject>(); - if (!date) - return QV4::DatePrototype::method_toLocaleTimeString(ctx); + QV4::DateObject *date = callData->thisObject.as<DateObject>(); + if (!date) { + QV4::DatePrototype::method_toLocaleTimeString(b, scope, callData); + return; + } QDateTime dt = date->toQDateTime(); QTime time = dt.time(); - if (ctx->argc() == 0) { + if (callData->argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return ctx->d()->engine->newString(locale.toString(time))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(locale.toString(time))); } - if (!isLocaleObject(ctx->args()[0])) - return QV4::DatePrototype::method_toLocaleTimeString(ctx); // Use the default Date toLocaleTimeString() + if (!isLocaleObject(callData->args[0])) + return QV4::DatePrototype::method_toLocaleTimeString(b, scope, callData); // Use the default Date toLocaleTimeString() - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QString formattedTime; - if (ctx->argc() == 2) { - if (String *s = ctx->args()[1].stringValue()) { + if (callData->argc == 2) { + if (String *s = callData->args[1].stringValue()) { QString format = s->toQString(); formattedTime = r->d()->locale->toString(time, format); - } else if (ctx->args()[1].isNumber()) { - quint32 intFormat = ctx->args()[1].toNumber(); + } else if (callData->args[1].isNumber()) { + quint32 intFormat = callData->args[1].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); formattedTime = r->d()->locale->toString(time, format); } else { - V4THROW_ERROR("Locale: Date.toLocaleTimeString(): Invalid time format"); + THROW_ERROR("Locale: Date.toLocaleTimeString(): Invalid time format"); } } else { formattedTime = r->d()->locale->toString(time, enumFormat); } - return ctx->d()->engine->newString(formattedTime)->asReturnedValue(); + scope.result = scope.engine->newString(formattedTime); } -QV4::ReturnedValue QQmlDateExtension::method_toLocaleDateString(QV4::CallContext *ctx) +void QQmlDateExtension::method_toLocaleDateString(const BuiltinFunction *b, Scope &scope, CallData *callData) { - if (ctx->argc() > 2) - return QV4::DatePrototype::method_toLocaleDateString(ctx); - - QV4::Scope scope(ctx); + if (callData->argc > 2) { + QV4::DatePrototype::method_toLocaleDateString(b, scope, callData); + return; + } - QV4::DateObject *dateObj = ctx->thisObject().as<DateObject>(); - if (!dateObj) - return QV4::DatePrototype::method_toLocaleDateString(ctx); + QV4::DateObject *dateObj = callData->thisObject.as<DateObject>(); + if (!dateObj) { + QV4::DatePrototype::method_toLocaleDateString(b, scope, callData); + return; + } QDateTime dt = dateObj->toQDateTime(); QDate date = dt.date(); - if (ctx->argc() == 0) { + if (callData->argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return ctx->d()->engine->newString(locale.toString(date))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(locale.toString(date))); } - if (!isLocaleObject(ctx->args()[0])) - return QV4::DatePrototype::method_toLocaleDateString(ctx); // Use the default Date toLocaleDateString() + if (!isLocaleObject(callData->args[0])) + return QV4::DatePrototype::method_toLocaleDateString(b, scope, callData); // Use the default Date toLocaleDateString() - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QString formattedDate; - if (ctx->argc() == 2) { - if (String *s = ctx->args()[1].stringValue()) { + if (callData->argc == 2) { + if (String *s = callData->args[1].stringValue()) { QString format = s->toQString(); formattedDate = r->d()->locale->toString(date, format); - } else if (ctx->args()[1].isNumber()) { - quint32 intFormat = ctx->args()[1].toNumber(); + } else if (callData->args[1].isNumber()) { + quint32 intFormat = callData->args[1].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); formattedDate = r->d()->locale->toString(date, format); } else { - V4THROW_ERROR("Locale: Date.loLocaleDateString(): Invalid date format"); + THROW_ERROR("Locale: Date.loLocaleDateString(): Invalid date format"); } } else { formattedDate = r->d()->locale->toString(date, enumFormat); } - return ctx->d()->engine->newString(formattedDate)->asReturnedValue(); + scope.result = scope.engine->newString(formattedDate); } -QV4::ReturnedValue QQmlDateExtension::method_fromLocaleString(QV4::CallContext *ctx) +void QQmlDateExtension::method_fromLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData) { - QV4::ExecutionEngine * const engine = ctx->d()->engine; - if (ctx->argc() == 1) { - if (String *s = ctx->args()[0].stringValue()) { + QV4::ExecutionEngine * const engine = scope.engine; + if (callData->argc == 1) { + if (String *s = callData->args[0].stringValue()) { QLocale locale; QString dateString = s->toQString(); QDateTime dt = locale.toDateTime(dateString); - return QV4::Encode(engine->newDateObject(dt)); + RETURN_RESULT(engine->newDateObject(dt)); } } - QV4::Scope scope(ctx); - - if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0])) - V4THROW_ERROR("Locale: Date.fromLocaleString(): Invalid arguments"); + if (callData->argc < 1 || callData->argc > 3 || !isLocaleObject(callData->args[0])) + THROW_ERROR("Locale: Date.fromLocaleString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QDateTime dt; - QString dateString = ctx->args()[1].toQStringNoThrow(); - if (ctx->argc() == 3) { - if (String *s = ctx->args()[2].stringValue()) { + QString dateString = callData->args[1].toQStringNoThrow(); + if (callData->argc == 3) { + if (String *s = callData->args[2].stringValue()) { QString format = s->toQString(); dt = r->d()->locale->toDateTime(dateString, format); - } else if (ctx->args()[2].isNumber()) { - quint32 intFormat = ctx->args()[2].toNumber(); + } else if (callData->args[2].isNumber()) { + quint32 intFormat = callData->args[2].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); dt = r->d()->locale->toDateTime(dateString, format); } else { - V4THROW_ERROR("Locale: Date.fromLocaleString(): Invalid datetime format"); + THROW_ERROR("Locale: Date.fromLocaleString(): Invalid datetime format"); } } else { dt = r->d()->locale->toDateTime(dateString, enumFormat); } - return QV4::Encode(engine->newDateObject(dt)); + scope.result = engine->newDateObject(dt); } -QV4::ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(QV4::CallContext *ctx) +void QQmlDateExtension::method_fromLocaleTimeString(const BuiltinFunction *, Scope &scope, CallData *callData) { - QV4::ExecutionEngine * const engine = ctx->d()->engine; + QV4::ExecutionEngine * const engine = scope.engine; - if (ctx->argc() == 1) { - if (String *s = ctx->args()[0].stringValue()) { + if (callData->argc == 1) { + if (String *s = callData->args[0].stringValue()) { QLocale locale; QString timeString = s->toQString(); QTime time = locale.toTime(timeString); QDateTime dt = QDateTime::currentDateTime(); dt.setTime(time); - return QV4::Encode(engine->newDateObject(dt)); + RETURN_RESULT(engine->newDateObject(dt)); } } - if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0])) - V4THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid arguments"); - - QV4::Scope scope(ctx); + if (callData->argc < 1 || callData->argc > 3 || !isLocaleObject(callData->args[0])) + THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QTime tm; - QString dateString = ctx->args()[1].toQStringNoThrow(); - if (ctx->argc() == 3) { - if (String *s = ctx->args()[2].stringValue()) { + QString dateString = callData->args[1].toQStringNoThrow(); + if (callData->argc == 3) { + if (String *s = callData->args[2].stringValue()) { QString format = s->toQString(); tm = r->d()->locale->toTime(dateString, format); - } else if (ctx->args()[2].isNumber()) { - quint32 intFormat = ctx->args()[2].toNumber(); + } else if (callData->args[2].isNumber()) { + quint32 intFormat = callData->args[2].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); tm = r->d()->locale->toTime(dateString, format); } else { - V4THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid datetime format"); + THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid datetime format"); } } else { tm = r->d()->locale->toTime(dateString, enumFormat); @@ -300,58 +311,56 @@ QV4::ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(QV4::CallConte dt.setTime(tm); } - return QV4::Encode(engine->newDateObject(dt)); + RETURN_RESULT(engine->newDateObject(dt)); } -QV4::ReturnedValue QQmlDateExtension::method_fromLocaleDateString(QV4::CallContext *ctx) +void QQmlDateExtension::method_fromLocaleDateString(const BuiltinFunction *, Scope &scope, CallData *callData) { - QV4::ExecutionEngine * const engine = ctx->d()->engine; + QV4::ExecutionEngine * const engine = scope.engine; - if (ctx->argc() == 1) { - if (String *s = ctx->args()[0].stringValue()) { + if (callData->argc == 1) { + if (String *s = callData->args[0].stringValue()) { QLocale locale; QString dateString = s->toQString(); QDate date = locale.toDate(dateString); - return QV4::Encode(engine->newDateObject(QDateTime(date))); + RETURN_RESULT(engine->newDateObject(QDateTime(date))); } } - if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0])) - V4THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid arguments"); + if (callData->argc < 1 || callData->argc > 3 || !isLocaleObject(callData->args[0])) + THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid arguments"); - QV4::Scope scope(ctx); - - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QDate dt; - QString dateString = ctx->args()[1].toQStringNoThrow(); - if (ctx->argc() == 3) { - if (String *s = ctx->args()[2].stringValue()) { + QString dateString = callData->args[1].toQStringNoThrow(); + if (callData->argc == 3) { + if (String *s = callData->args[2].stringValue()) { QString format = s->toQString(); dt = r->d()->locale->toDate(dateString, format); - } else if (ctx->args()[2].isNumber()) { - quint32 intFormat = ctx->args()[2].toNumber(); + } else if (callData->args[2].isNumber()) { + quint32 intFormat = callData->args[2].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); dt = r->d()->locale->toDate(dateString, format); } else { - V4THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid datetime format"); + THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid datetime format"); } } else { dt = r->d()->locale->toDate(dateString, enumFormat); } - return QV4::Encode(engine->newDateObject(QDateTime(dt))); + RETURN_RESULT(engine->newDateObject(QDateTime(dt))); } -QV4::ReturnedValue QQmlDateExtension::method_timeZoneUpdated(QV4::CallContext *ctx) +void QQmlDateExtension::method_timeZoneUpdated(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (ctx->argc() != 0) - V4THROW_ERROR("Locale: Date.timeZoneUpdated(): Invalid arguments"); + if (callData->argc != 0) + THROW_ERROR("Locale: Date.timeZoneUpdated(): Invalid arguments"); QV4::DatePrototype::timezoneUpdated(); - return QV4::Encode::undefined(); + RETURN_UNDEFINED(); } //----------------- @@ -364,148 +373,143 @@ void QQmlNumberExtension::registerExtension(QV4::ExecutionEngine *engine) engine->numberCtor()->defineDefaultProperty(QStringLiteral("fromLocaleString"), method_fromLocaleString); } -QV4::ReturnedValue QQmlNumberExtension::method_toLocaleString(QV4::CallContext *ctx) +void QQmlNumberExtension::method_toLocaleString(const BuiltinFunction *b, Scope &scope, CallData *callData) { - if (ctx->argc() > 3) - V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); + if (callData->argc > 3) + THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - double number = ctx->thisObject().toNumber(); + double number = callData->thisObject.toNumber(); - if (ctx->argc() == 0) { + if (callData->argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return ctx->d()->engine->newString(locale.toString(number))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(locale.toString(number))); } - if (!isLocaleObject(ctx->args()[0])) - return QV4::NumberPrototype::method_toLocaleString(ctx); // Use the default Number toLocaleString() - - QV4::Scope scope(ctx); + if (!isLocaleObject(callData->args[0])) { + QV4::NumberPrototype::method_toLocaleString(b, scope, callData); // Use the default Number toLocaleString() + return; + } - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); quint16 format = 'f'; - if (ctx->argc() > 1) { - if (!ctx->args()[1].isString()) - V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - QString fs = ctx->args()[1].toQString(); + if (callData->argc > 1) { + if (!callData->args[1].isString()) + THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); + QString fs = callData->args[1].toQString(); if (fs.length()) format = fs.at(0).unicode(); } int prec = 2; - if (ctx->argc() > 2) { - if (!ctx->args()[2].isNumber()) - V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - prec = ctx->args()[2].toInt32(); + if (callData->argc > 2) { + if (!callData->args[2].isNumber()) + THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); + prec = callData->args[2].toInt32(); } - return ctx->d()->engine->newString(r->d()->locale->toString(number, (char)format, prec))->asReturnedValue(); + scope.result = scope.engine->newString(r->d()->locale->toString(number, (char)format, prec)); } -QV4::ReturnedValue QQmlNumberExtension::method_toLocaleCurrencyString(QV4::CallContext *ctx) +void QQmlNumberExtension::method_toLocaleCurrencyString(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (ctx->argc() > 2) - V4THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments"); + if (callData->argc > 2) + THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments"); - double number = ctx->thisObject().toNumber(); + double number = callData->thisObject.toNumber(); - if (ctx->argc() == 0) { + if (callData->argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; - return ctx->d()->engine->newString(locale.toString(number))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(locale.toString(number))); } - if (!isLocaleObject(ctx->args()[0])) - V4THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments"); - - QV4::Scope scope(ctx); + if (!isLocaleObject(callData->args[0])) + THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); QString symbol; - if (ctx->argc() > 1) { - if (!ctx->args()[1].isString()) - V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - symbol = ctx->args()[1].toQStringNoThrow(); + if (callData->argc > 1) { + if (!callData->args[1].isString()) + THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); + symbol = callData->args[1].toQStringNoThrow(); } - return ctx->d()->engine->newString(r->d()->locale->toCurrencyString(number, symbol))->asReturnedValue(); + RETURN_RESULT(scope.engine->newString(r->d()->locale->toCurrencyString(number, symbol))); } -QV4::ReturnedValue QQmlNumberExtension::method_fromLocaleString(QV4::CallContext *ctx) +void QQmlNumberExtension::method_fromLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (ctx->argc() < 1 || ctx->argc() > 2) - V4THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments"); + if (callData->argc < 1 || callData->argc > 2) + THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments"); int numberIdx = 0; QLocale locale; - QV4::Scope scope(ctx); - - if (ctx->argc() == 2) { - if (!isLocaleObject(ctx->args()[0])) - V4THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments"); + if (callData->argc == 2) { + if (!isLocaleObject(callData->args[0])) + THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(ctx->args()[0]); + GET_LOCALE_DATA_RESOURCE(callData->args[0]); locale = *r->d()->locale; numberIdx = 1; } - QString ns = ctx->args()[numberIdx].toQString(); + QString ns = callData->args[numberIdx].toQString(); if (!ns.length()) - return QV4::Encode(Q_QNAN); + RETURN_RESULT(QV4::Encode(Q_QNAN)); bool ok = false; double val = locale.toDouble(ns, &ok); if (!ok) - V4THROW_ERROR("Locale: Number.fromLocaleString(): Invalid format") + THROW_ERROR("Locale: Number.fromLocaleString(): Invalid format"); - return QV4::Encode(val); + scope.result = QV4::Encode(val); } //-------------- // Locale object -QV4::ReturnedValue QQmlLocaleData::method_get_firstDayOfWeek(QV4::CallContext *ctx) +void QQmlLocaleData::method_get_firstDayOfWeek(const BuiltinFunction *, Scope &scope, CallData *callData) { - QLocale *locale = getThisLocale(ctx); + QLocale *locale = getThisLocale(scope, callData); if (!locale) - return QV4::Encode::undefined(); + return; int fdow = int(locale->firstDayOfWeek()); if (fdow == 7) fdow = 0; // Qt::Sunday = 7, but Sunday is 0 in JS Date - return QV4::Encode(fdow); + scope.result = QV4::Encode(fdow); } -QV4::ReturnedValue QQmlLocaleData::method_get_measurementSystem(QV4::CallContext *ctx) +void QQmlLocaleData::method_get_measurementSystem(const BuiltinFunction *, Scope &scope, CallData *callData) { - QLocale *locale = getThisLocale(ctx); + QLocale *locale = getThisLocale(scope, callData); if (!locale) - return QV4::Encode::undefined(); - return QV4::Encode(locale->measurementSystem()); + return; + scope.result = QV4::Encode(locale->measurementSystem()); } -QV4::ReturnedValue QQmlLocaleData::method_get_textDirection(QV4::CallContext *ctx) +void QQmlLocaleData::method_get_textDirection(const BuiltinFunction *, Scope &scope, CallData *callData) { - QLocale *locale = getThisLocale(ctx); + QLocale *locale = getThisLocale(scope, callData); if (!locale) - return QV4::Encode::undefined(); + return; - return QV4::Encode(locale->textDirection()); + scope.result = QV4::Encode(locale->textDirection()); } -QV4::ReturnedValue QQmlLocaleData::method_get_weekDays(QV4::CallContext *ctx) +void QQmlLocaleData::method_get_weekDays(const BuiltinFunction *, Scope &scope, CallData *callData) { - QV4::Scope scope(ctx); - QLocale *locale = getThisLocale(ctx); + QLocale *locale = getThisLocale(scope, callData); if (!locale) - return QV4::Encode::undefined(); + return; QList<Qt::DayOfWeek> days = locale->weekdays(); - QV4::ScopedArrayObject result(scope, ctx->d()->engine->newArrayObject()); + QV4::ScopedArrayObject result(scope, scope.engine->newArrayObject()); result->arrayReserve(days.size()); for (int i = 0; i < days.size(); ++i) { int day = days.at(i); @@ -515,59 +519,58 @@ QV4::ReturnedValue QQmlLocaleData::method_get_weekDays(QV4::CallContext *ctx) } result->setArrayLengthUnchecked(days.size()); - return result.asReturnedValue(); + scope.result = result.asReturnedValue(); } -QV4::ReturnedValue QQmlLocaleData::method_get_uiLanguages(QV4::CallContext *ctx) +void QQmlLocaleData::method_get_uiLanguages(const BuiltinFunction *, Scope &scope, CallData *callData) { - QV4::Scope scope(ctx); - QLocale *locale = getThisLocale(ctx); + QLocale *locale = getThisLocale(scope, callData); if (!locale) - return QV4::Encode::undefined(); + return; QStringList langs = locale->uiLanguages(); - QV4::ScopedArrayObject result(scope, ctx->d()->engine->newArrayObject()); + QV4::ScopedArrayObject result(scope, scope.engine->newArrayObject()); result->arrayReserve(langs.size()); QV4::ScopedValue v(scope); for (int i = 0; i < langs.size(); ++i) - result->arrayPut(i, (v = ctx->d()->engine->newString(langs.at(i)))); + result->arrayPut(i, (v = scope.engine->newString(langs.at(i)))); result->setArrayLengthUnchecked(langs.size()); - return result.asReturnedValue(); + scope.result = result.asReturnedValue(); } -QV4::ReturnedValue QQmlLocaleData::method_currencySymbol(QV4::CallContext *ctx) +void QQmlLocaleData::method_currencySymbol(const BuiltinFunction *, Scope &scope, CallData *callData) { - QLocale *locale = getThisLocale(ctx); + QLocale *locale = getThisLocale(scope, callData); if (!locale) - return QV4::Encode::undefined(); + return; - if (ctx->argc() > 1) - V4THROW_ERROR("Locale: currencySymbol(): Invalid arguments"); + if (callData->argc > 1) + THROW_ERROR("Locale: currencySymbol(): Invalid arguments"); QLocale::CurrencySymbolFormat format = QLocale::CurrencySymbol; - if (ctx->argc() == 1) { - quint32 intFormat = ctx->args()[0].toNumber(); + if (callData->argc == 1) { + quint32 intFormat = callData->args[0].toNumber(); format = QLocale::CurrencySymbolFormat(intFormat); } - return ctx->d()->engine->newString(locale->currencySymbol(format))->asReturnedValue(); + scope.result = scope.engine->newString(locale->currencySymbol(format)); } #define LOCALE_FORMAT(FUNC) \ -QV4::ReturnedValue QQmlLocaleData::method_ ##FUNC (QV4::CallContext *ctx) { \ - QLocale *locale = getThisLocale(ctx); \ +void QQmlLocaleData::method_ ##FUNC (const BuiltinFunction *, Scope &scope, CallData *callData) { \ + QLocale *locale = getThisLocale(scope, callData); \ if (!locale) \ - return QV4::Encode::undefined(); \ - if (ctx->argc() > 1) \ - V4THROW_ERROR("Locale: " #FUNC "(): Invalid arguments"); \ + return; \ + if (callData->argc > 1) \ + THROW_ERROR("Locale: " #FUNC "(): Invalid arguments"); \ QLocale::FormatType format = QLocale::LongFormat;\ - if (ctx->argc() == 1) { \ - quint32 intFormat = ctx->args()[0].toUInt32(); \ + if (callData->argc == 1) { \ + quint32 intFormat = callData->args[0].toUInt32(); \ format = QLocale::FormatType(intFormat); \ } \ - return ctx->engine()->newString(locale-> FUNC (format))->asReturnedValue(); \ + scope.result = scope.engine->newString(locale-> FUNC (format)); \ } LOCALE_FORMAT(dateTimeFormat) @@ -576,57 +579,57 @@ LOCALE_FORMAT(dateFormat) // +1 added to idx because JS is 0-based, whereas QLocale months begin at 1. #define LOCALE_FORMATTED_MONTHNAME(VARIABLE) \ -QV4::ReturnedValue QQmlLocaleData::method_ ## VARIABLE (QV4::CallContext *ctx) {\ - QLocale *locale = getThisLocale(ctx); \ +void QQmlLocaleData::method_ ## VARIABLE (const BuiltinFunction *, Scope &scope, CallData *callData) {\ + QLocale *locale = getThisLocale(scope, callData); \ if (!locale) \ - return QV4::Encode::undefined(); \ - if (ctx->argc() < 1 || ctx->argc() > 2) \ - V4THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \ + return; \ + if (callData->argc < 1 || callData->argc > 2) \ + THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \ QLocale::FormatType enumFormat = QLocale::LongFormat; \ - int idx = ctx->args()[0].toInt32() + 1; \ + int idx = callData->args[0].toInt32() + 1; \ if (idx < 1 || idx > 12) \ - V4THROW_ERROR("Locale: Invalid month"); \ + THROW_ERROR("Locale: Invalid month"); \ QString name; \ - if (ctx->argc() == 2) { \ - if (ctx->args()[1].isNumber()) { \ - quint32 intFormat = ctx->args()[1].toUInt32(); \ + if (callData->argc == 2) { \ + if (callData->args[1].isNumber()) { \ + quint32 intFormat = callData->args[1].toUInt32(); \ QLocale::FormatType format = QLocale::FormatType(intFormat); \ name = locale-> VARIABLE(idx, format); \ } else { \ - V4THROW_ERROR("Locale: Invalid datetime format"); \ + THROW_ERROR("Locale: Invalid datetime format"); \ } \ } else { \ name = locale-> VARIABLE(idx, enumFormat); \ } \ - return ctx->engine()->newString(name)->asReturnedValue(); \ + scope.result = scope.engine->newString(name); \ } // 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date #define LOCALE_FORMATTED_DAYNAME(VARIABLE) \ -QV4::ReturnedValue QQmlLocaleData::method_ ## VARIABLE (QV4::CallContext *ctx) {\ - QLocale *locale = getThisLocale(ctx); \ +void QQmlLocaleData::method_ ## VARIABLE (const BuiltinFunction *, Scope &scope, CallData *callData) {\ + QLocale *locale = getThisLocale(scope, callData); \ if (!locale) \ - return QV4::Encode::undefined(); \ - if (ctx->argc() < 1 || ctx->argc() > 2) \ - V4THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \ + return; \ + if (callData->argc < 1 || callData->argc > 2) \ + THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \ QLocale::FormatType enumFormat = QLocale::LongFormat; \ - int idx = ctx->args()[0].toInt32(); \ + int idx = callData->args[0].toInt32(); \ if (idx < 0 || idx > 7) \ - V4THROW_ERROR("Locale: Invalid day"); \ + THROW_ERROR("Locale: Invalid day"); \ if (idx == 0) idx = 7; \ QString name; \ - if (ctx->argc() == 2) { \ - if (ctx->args()[1].isNumber()) { \ - quint32 intFormat = ctx->args()[1].toUInt32(); \ + if (callData->argc == 2) { \ + if (callData->args[1].isNumber()) { \ + quint32 intFormat = callData->args[1].toUInt32(); \ QLocale::FormatType format = QLocale::FormatType(intFormat); \ name = locale-> VARIABLE(idx, format); \ } else { \ - V4THROW_ERROR("Locale: Invalid datetime format"); \ + THROW_ERROR("Locale: Invalid datetime format"); \ } \ } else { \ name = locale-> VARIABLE(idx, enumFormat); \ } \ - return ctx->engine()->newString(name)->asReturnedValue(); \ + scope.result = scope.engine->newString(name); \ } LOCALE_FORMATTED_MONTHNAME(monthName) @@ -634,12 +637,12 @@ LOCALE_FORMATTED_MONTHNAME(standaloneMonthName) LOCALE_FORMATTED_DAYNAME(dayName) LOCALE_FORMATTED_DAYNAME(standaloneDayName) -#define LOCALE_STRING_PROPERTY(VARIABLE) QV4::ReturnedValue QQmlLocaleData::method_get_ ## VARIABLE (QV4::CallContext* ctx) \ +#define LOCALE_STRING_PROPERTY(VARIABLE) void QQmlLocaleData::method_get_ ## VARIABLE (const BuiltinFunction *, Scope &scope, CallData *callData) \ { \ - QLocale *locale = getThisLocale(ctx); \ + QLocale *locale = getThisLocale(scope, callData); \ if (!locale) \ - return QV4::Encode::undefined(); \ - return ctx->engine()->newString(locale-> VARIABLE())->asReturnedValue();\ + return; \ + scope.result = scope.engine->newString(locale-> VARIABLE());\ } LOCALE_STRING_PROPERTY(name) @@ -830,18 +833,22 @@ void QQmlLocale::registerStringLocaleCompare(QV4::ExecutionEngine *engine) engine->stringPrototype()->defineDefaultProperty(QStringLiteral("localeCompare"), method_localeCompare); } -QV4::ReturnedValue QQmlLocale::method_localeCompare(QV4::CallContext *ctx) +void QQmlLocale::method_localeCompare(const BuiltinFunction *b, Scope &scope, CallData *callData) { - if (ctx->argc() != 1 || (!ctx->args()[0].isString() && !ctx->args()[0].as<StringObject>())) - return QV4::StringPrototype::method_localeCompare(ctx); + if (callData->argc != 1 || (!callData->args[0].isString() && !callData->args[0].as<StringObject>())) { + QV4::StringPrototype::method_localeCompare(b, scope, callData); + return; + } - if (!ctx->thisObject().isString() && !ctx->thisObject().as<StringObject>()) - return QV4::StringPrototype::method_localeCompare(ctx); + if (!callData->thisObject.isString() && !callData->thisObject.as<StringObject>()) { + QV4::StringPrototype::method_localeCompare(b, scope, callData); + return; + } - QString thisString = ctx->thisObject().toQStringNoThrow(); - QString thatString = ctx->args()[0].toQStringNoThrow(); + QString thisString = callData->thisObject.toQStringNoThrow(); + QString thatString = callData->args[0].toQStringNoThrow(); - return QV4::Encode(QString::localeAwareCompare(thisString, thatString)); + scope.result = QV4::Encode(QString::localeAwareCompare(thisString, thatString)); } /*! diff --git a/src/qml/qml/qqmllocale_p.h b/src/qml/qml/qqmllocale_p.h index 275f58db7d..1a2ffc72b0 100644 --- a/src/qml/qml/qqmllocale_p.h +++ b/src/qml/qml/qqmllocale_p.h @@ -67,13 +67,13 @@ public: static void registerExtension(QV4::ExecutionEngine *engine); private: - static QV4::ReturnedValue method_toLocaleString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_toLocaleTimeString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_toLocaleDateString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_fromLocaleString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_fromLocaleTimeString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_fromLocaleDateString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_timeZoneUpdated(QV4::CallContext *ctx); + static void method_toLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_toLocaleTimeString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_toLocaleDateString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_fromLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_fromLocaleTimeString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_fromLocaleDateString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_timeZoneUpdated(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); }; @@ -83,9 +83,9 @@ public: static void registerExtension(QV4::ExecutionEngine *engine); private: - static QV4::ReturnedValue method_toLocaleString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_fromLocaleString(QV4::CallContext *ctx); - static QV4::ReturnedValue method_toLocaleCurrencyString(QV4::CallContext *ctx); + static void method_toLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_fromLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_toLocaleCurrencyString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); }; @@ -135,7 +135,7 @@ public: private: QQmlLocale(); - static QV4::ReturnedValue method_localeCompare(QV4::CallContext *ctx); + static void method_localeCompare(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); }; namespace QV4 { @@ -158,43 +158,43 @@ struct QQmlLocaleData : public QV4::Object V4_OBJECT2(QQmlLocaleData, Object) V4_NEEDS_DESTROY - static QLocale *getThisLocale(QV4::CallContext *ctx) { - QV4::Object *o = ctx->thisObject().as<Object>(); + static QLocale *getThisLocale(QV4::Scope &scope, QV4::CallData *callData) { + QV4::Object *o = callData->thisObject.as<Object>(); QQmlLocaleData *thisObject = o ? o->as<QQmlLocaleData>() : 0; if (!thisObject) { - ctx->engine()->throwTypeError(); + scope.engine->throwTypeError(); return 0; } return thisObject->d()->locale; } - static QV4::ReturnedValue method_currencySymbol(QV4::CallContext *ctx); - static QV4::ReturnedValue method_dateTimeFormat(QV4::CallContext *ctx); - static QV4::ReturnedValue method_timeFormat(QV4::CallContext *ctx); - static QV4::ReturnedValue method_dateFormat(QV4::CallContext *ctx); - static QV4::ReturnedValue method_monthName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_standaloneMonthName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_dayName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_standaloneDayName(QV4::CallContext *ctx); - - static QV4::ReturnedValue method_get_firstDayOfWeek(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_measurementSystem(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_textDirection(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_weekDays(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_uiLanguages(QV4::CallContext *ctx); - - static QV4::ReturnedValue method_get_name(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_nativeLanguageName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_nativeCountryName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_decimalPoint(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_groupSeparator(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_percent(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_zeroDigit(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_negativeSign(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_positiveSign(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_exponential(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_amText(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_pmText(QV4::CallContext *ctx); + static void method_currencySymbol(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_dateTimeFormat(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_timeFormat(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_dateFormat(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_monthName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_standaloneMonthName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_dayName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_standaloneDayName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + + static void method_get_firstDayOfWeek(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_measurementSystem(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_textDirection(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_weekDays(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_uiLanguages(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + + static void method_get_name(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_nativeLanguageName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_nativeCountryName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_decimalPoint(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_groupSeparator(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_percent(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_zeroDigit(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_negativeSign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_positiveSign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_exponential(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_amText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); + static void method_get_pmText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData); }; } |