From f15cc9f1df8e17f049c111e3147d6c63c07eb756 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 18 Aug 2018 15:26:45 +0200 Subject: 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 --- src/qml/jsruntime/qv4arrayobject.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/qml/jsruntime/qv4arrayobject.cpp') diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index 9be744038c..c162a38e9d 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -165,23 +165,13 @@ ScopedObject createObjectFromCtorOrArray(Scope &scope, ScopedFunctionObject ctor { ScopedObject a(scope, Primitive::undefinedValue()); - if (ctor) { - // ### the spec says that we should only call constructors if - // IsConstructor(that), but we have no way of knowing if a builtin is a - // constructor. so for the time being, just try call it, and silence any - // exceptions-- this is not ideal, as the spec also says that we should - // return on exception. - // - // this also isn't completely kosher. for instance: + if (ctor && ctor->isConstructor()) { + // this isn't completely kosher. for instance: // Array.from.call(Object, []).constructor == Object // is expected by the tests, but naturally, we get Number. ScopedValue argument(scope, useLen ? QV4::Encode(len) : Primitive::undefinedValue()); a = ctor->callAsConstructor(argument, useLen ? 1 : 0); - if (scope.engine->hasException) - scope.engine->catchException(); // probably not a constructor, then. - } - - if (!a) { + } else { a = scope.engine->newArrayObject(len); } -- cgit v1.2.3