diff options
author | Lars Knoll <[email protected]> | 2018-11-05 10:18:53 +0100 |
---|---|---|
committer | Lars Knoll <[email protected]> | 2018-11-22 08:47:08 +0000 |
commit | 33c13efd91954fb50019e82f3ab8e8e1d8458332 (patch) | |
tree | 6d91724990f49fc4f04f012599cfa3241b98f4ec /src/qml/jsruntime/qv4numberobject.cpp | |
parent | 03f492f91a9ac6d33be05488f7ea6fb5decaf873 (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 <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4numberobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4numberobject.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index 11ec53ced5..d26e888069 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -78,10 +78,18 @@ void Heap::NumberCtor::init(QV4::ExecutionContext *scope) Heap::FunctionObject::init(scope, QStringLiteral("Number")); } -ReturnedValue NumberCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *) +ReturnedValue NumberCtor::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *newTarget) { + auto v4 = f->engine(); double dbl = argc ? argv[0].toNumber() : 0.; - return Encode(f->engine()->newNumberObject(dbl)); + + ReturnedValue o = Encode(f->engine()->newNumberObject(dbl)); + if (!newTarget) + return o; + Scope scope(v4); + ScopedObject obj(scope, o); + obj->setProtoFromNewTarget(newTarget); + return obj->asReturnedValue(); } ReturnedValue NumberCtor::virtualCall(const FunctionObject *, const Value *, const Value *argv, int argc) |