aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4reflect.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-23 16:06:26 +0200
committerLars Knoll <lars.knoll@qt.io>2018-08-23 19:18:19 +0000
commit732c25029ec95feb27a607ef19bb3b7423a955a1 (patch)
treec53e44cf7b7cd4555bc34aedf0474ca128292d40 /src/qml/jsruntime/qv4reflect.cpp
parentf15cc9f1df8e17f049c111e3147d6c63c07eb756 (diff)
Implement support for call/callAsConstructor in Proxy objects
This adds the last missing piece of functionality for Proxy objects. Also fix a bug where we ignored the newTarget in Reflect.construct. Change-Id: I2443470f2ca13fb6223768c3bf6bdc3766bb4fc3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4reflect.cpp')
-rw-r--r--src/qml/jsruntime/qv4reflect.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4reflect.cpp b/src/qml/jsruntime/qv4reflect.cpp
index 90c39f7c37..3dc0956e0c 100644
--- a/src/qml/jsruntime/qv4reflect.cpp
+++ b/src/qml/jsruntime/qv4reflect.cpp
@@ -103,7 +103,11 @@ ReturnedValue Reflect::method_apply(const FunctionObject *f, const Value *, cons
ReturnedValue Reflect::method_construct(const FunctionObject *f, const Value *, const Value *argv, int argc)
{
Scope scope(f);
- if (argc < 2 || !argv[0].isFunctionObject() || !argv[1].isObject())
+ if (argc < 2 || !argv[1].isObject())
+ return scope.engine->throwTypeError();
+ const FunctionObject *target = argv[0].as<FunctionObject>();
+ const FunctionObject *newTarget = argc == 3 ? argv[2].as<FunctionObject>() : target;
+ if (!target || !target->isConstructor() || !newTarget || !newTarget->isConstructor())
return scope.engine->throwTypeError();
const Object *o = static_cast<const Object *>(argv + 1);
@@ -111,7 +115,7 @@ ReturnedValue Reflect::method_construct(const FunctionObject *f, const Value *,
if (scope.hasException())
return Encode::undefined();
- return static_cast<const FunctionObject &>(argv[0]).callAsConstructor(arguments.argv, arguments.argc);
+ return target->callAsConstructor(arguments.argv, arguments.argc, newTarget);
}
ReturnedValue Reflect::method_defineProperty(const FunctionObject *f, const Value *, const Value *argv, int argc)