diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-11-05 10:18:53 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-11-22 08:47:08 +0000 |
commit | 33c13efd91954fb50019e82f3ab8e8e1d8458332 (patch) | |
tree | 6d91724990f49fc4f04f012599cfa3241b98f4ec /tests/auto/qml/v4misc | |
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 <erik.verbruggen@qt.io>
Diffstat (limited to 'tests/auto/qml/v4misc')
-rw-r--r-- | tests/auto/qml/v4misc/tst_v4misc.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/qml/v4misc/tst_v4misc.cpp b/tests/auto/qml/v4misc/tst_v4misc.cpp index 5aac91aae9..ecc3a4100c 100644 --- a/tests/auto/qml/v4misc/tst_v4misc.cpp +++ b/tests/auto/qml/v4misc/tst_v4misc.cpp @@ -40,6 +40,9 @@ private slots: void parserMisc_data(); void parserMisc(); + + void subClassing_data(); + void subClassing(); }; void tst_v4misc::tdzOptimizations_data() @@ -130,6 +133,46 @@ void tst_v4misc::parserMisc() QCOMPARE(result.toString(), error); } +void tst_v4misc::subClassing_data() +{ + QTest::addColumn<QString>("script"); + + QString code( + "class Foo extends %1 {" + " constructor() { super(); this.reset(); }" + " reset() { }" + "}" + "new Foo();"); + + + QTest::newRow("Array") << code.arg("Array"); + QTest::newRow("Boolean") << code.arg("Boolean"); + QTest::newRow("Date") << code.arg("Date"); + QTest::newRow("Function") << code.arg("Function"); + QTest::newRow("Number") << code.arg("Number"); + QTest::newRow("Map") << code.arg("Map"); + QTest::newRow("Promise") << QString( + "class Foo extends Promise {" + " constructor() { super(Function()); this.reset(); }" + " reset() { }" + "}" + "new Foo();"); + QTest::newRow("RegExp") << code.arg("RegExp"); + QTest::newRow("Set") << code.arg("Set"); + QTest::newRow("String") << code.arg("String"); + QTest::newRow("WeakMap") << code.arg("WeakMap"); + QTest::newRow("WeakSet") << code.arg("WeakSet"); +} + +void tst_v4misc::subClassing() +{ + QFETCH(QString, script); + + QJSEngine engine; + QJSValue result = engine.evaluate(script); + QVERIFY(!result.isError()); +} + QTEST_MAIN(tst_v4misc); #include "tst_v4misc.moc" |