aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4dateobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-11-05 10:18:53 +0100
committerLars Knoll <lars.knoll@qt.io>2018-11-22 08:47:08 +0000
commit33c13efd91954fb50019e82f3ab8e8e1d8458332 (patch)
tree6d91724990f49fc4f04f012599cfa3241b98f4ec /src/qml/jsruntime/qv4dateobject.cpp
parent03f492f91a9ac6d33be05488f7ea6fb5decaf873 (diff)
Ensure our builtin constructors are subclassable
Respect the newTarget passed into those constructors and make sure we set up the proto chain correctly. Change-Id: I3d12c7dbef4b33660a6715d73e9fb0f89105167a Fixes: QTBUG-71138 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4dateobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index df3bb37e9c..a13fb37a52 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -755,16 +755,16 @@ void Heap::DateCtor::init(QV4::ExecutionContext *scope)
Heap::FunctionObject::init(scope, QStringLiteral("Date"));
}
-ReturnedValue DateCtor::virtualCallAsConstructor(const FunctionObject *that, const Value *argv, int argc, const Value *)
+ReturnedValue DateCtor::virtualCallAsConstructor(const FunctionObject *that, const Value *argv, int argc, const Value *newTarget)
{
- ExecutionEngine *e = that->engine();
+ ExecutionEngine *v4 = that->engine();
double t = 0;
if (argc == 0)
t = currentTime();
else if (argc == 1) {
- Scope scope(e);
+ Scope scope(v4);
ScopedValue arg(scope, argv[0]);
if (DateObject *d = arg->as<DateObject>()) {
t = d->date();
@@ -772,7 +772,7 @@ ReturnedValue DateCtor::virtualCallAsConstructor(const FunctionObject *that, con
arg = RuntimeHelpers::toPrimitive(arg, PREFERREDTYPE_HINT);
if (String *s = arg->stringValue())
- t = ParseString(s->toQString(), e->localTZA);
+ t = ParseString(s->toQString(), v4->localTZA);
else
t = TimeClip(arg->toNumber());
}
@@ -789,10 +789,16 @@ ReturnedValue DateCtor::virtualCallAsConstructor(const FunctionObject *that, con
if (year >= 0 && year <= 99)
year += 1900;
t = MakeDate(MakeDay(year, month, day), MakeTime(hours, mins, secs, ms));
- t = TimeClip(UTC(t, e->localTZA));
+ t = TimeClip(UTC(t, v4->localTZA));
}
- return Encode(e->newDateObject(Value::fromDouble(t)));
+ ReturnedValue o = Encode(v4->newDateObject(Value::fromDouble(t)));
+ if (!newTarget)
+ return o;
+ Scope scope(v4);
+ ScopedObject obj(scope, o);
+ obj->setProtoFromNewTarget(newTarget);
+ return obj->asReturnedValue();
}
ReturnedValue DateCtor::virtualCall(const FunctionObject *m, const Value *, const Value *, int)