aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4functionobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-18 15:26:45 +0200
committerLars Knoll <lars.knoll@qt.io>2018-08-23 19:18:15 +0000
commitf15cc9f1df8e17f049c111e3147d6c63c07eb756 (patch)
treeae4daaa5e1cde31c0e412b84e9521f3745911657 /src/qml/jsruntime/qv4functionobject.cpp
parent6e2fc84646987135c96755fbe1c2af20fc722e3d (diff)
Implement IsConstructor for Function objects
Use the jsConstruct member in the function object for this and set it to a nullptr for methods that are not a constructor. Change-Id: I63d2971b23b2596a8e3b6d2781f0d9ed3208693b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 35d8fe18e0..a5dc0ba567 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -73,7 +73,7 @@ DEFINE_OBJECT_VTABLE(FunctionObject);
void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name, VTable::Call call)
{
jsCall = call;
- jsConstruct = QV4::FunctionObject::virtualCallAsConstructor;
+ jsConstruct = nullptr;
Object::init();
this->scope.set(scope->engine(), scope->d());
@@ -165,11 +165,6 @@ ReturnedValue FunctionObject::name() const
return get(scope()->internalClass->engine->id_name());
}
-ReturnedValue FunctionObject::virtualCallAsConstructor(const FunctionObject *f, const Value *, int, const Value *)
-{
- return f->engine()->throwTypeError();
-}
-
ReturnedValue FunctionObject::virtualCall(const FunctionObject *, const Value *, const Value *, int)
{
return Encode::undefined();
@@ -587,11 +582,6 @@ ReturnedValue ConstructorFunction::virtualCall(const FunctionObject *f, const Va
DEFINE_OBJECT_VTABLE(MemberFunction);
-ReturnedValue MemberFunction::virtualCallAsConstructor(const FunctionObject *f, const Value *, int, const Value *)
-{
- return f->engine()->throwTypeError(QStringLiteral("Function is not a constructor."));
-}
-
DEFINE_OBJECT_VTABLE(DefaultClassConstructorFunction);
ReturnedValue DefaultClassConstructorFunction::virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *newTarget)
@@ -652,6 +642,9 @@ void Heap::BoundFunction::init(QV4::ExecutionContext *scope, QV4::FunctionObject
this->boundArgs.set(s.engine, boundArgs ? boundArgs->d() : nullptr);
this->boundThis.set(scope->engine(), boundThis);
+ if (!target->isConstructor())
+ jsConstruct = nullptr;
+
ScopedObject f(s, this);
ScopedValue l(s, target->get(s.engine->id_length()));