Commit Graph

660 Commits

Author SHA1 Message Date
Ulf Hermann 98a31ff6b9 Adapt to changes in qtbase
Due to qiterable.h specializing a template declared in qmetatype.h we
temporarily need to include it in a few tests so that the iterables
work.

Change-Id: Ia32392419dead76eaf2b91b2ec4157b726d8de74
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-09-15 13:32:47 +02:00
Edward Welbourne 5234bed6a2 Use QDate::startOfDay() rather than assuming midnight exists
When converting a QDate to a QDateTime, startOfDay() takes care of
avoiding any gaps in time at the start of the day, where naively
asking for QTime(0, 0, 0) can produce an invalid date-time.

Change-Id: I24f3d230eb1ee7396600b030ad1305e060215cbd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-01 16:57:08 +02:00
Edward Welbourne fa03166871 V4 Date: pass QDate, QTime by value, not by const reference
They're value types, packaging qint64 and int respectively.

Change-Id: I78a0097f77238751ac3ef9f928537f719a6d05d6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-01 16:56:42 +02:00
Lars Knoll 2afed94c70 Fix QtQml after QMetaType/QVariant changes in Qt Core
Change-Id: I2a983cf8188e88d80d3b7726208d821427eb8f3c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-08-28 13:49:11 +02:00
Fabian Kosmale 48b4c1f450 Adapt to qtbase changes
The internal QVariant constructor taking a QMetaTypeId has been removed.
Thus, construct QMetaTypes where necessary from the id, or avoid a
QMetaType -> ID -> QMetaType roundtrip where we already have a metatype.
Also fix a few missing includse that were previously transitively
included.

Change-Id: I56ce92281d616108a4ff80fe5052b919d1282357
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2020-08-23 20:50:04 +02:00
Fabian Kosmale d911034f46 QV4Engine: Fix type conversion
When converting JS arrays to sequence<T> type, check first for the
existence of a QJSValue -> T converter function. This restores the
behavior from Qt <= 5.14. Amends ecdb4ed275

Fixes: QTBUG-84104
Change-Id: I14c86ab37e34a3c8cff072574d4b90fe9e558535
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-05-19 09:21:00 +02:00
Fabian Kosmale c7d3ab0d05 QJSEngine: support char16_t
Now that char16_t is used in Qt (for instance in QChar::unicode()), we
need to support it.

Change-Id: I527a70795524bfd883fc4d729aac714708b51181
Reviewed-by: Liang Qi <liang.qi@qt.io>
2020-05-16 23:50:40 +02:00
Maximilian Goldstein a714a3a446 Implement URLSearchParams
Implements URLSearchParams (https://url.spec.whatwg.org/#urlsearchparams),
completing our implementation of the URL object.

Still needs the for..of iterator to get implemented.

Change-Id: Iad33ed2f3fe0b2598ca2b0b21a4743f5f7dc19fd
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-05-06 10:45:48 +02:00
Simon Hausmann 505863e700 Add a hook that allows for ahead-of-time compiled functions
Use the unused field in the CachedUnit structure provided by qmlcachegen
to allow for providing function pointers for functions and bindings that
are compiled ahead of time.

Provided is the pointer into an array that is terminated with a {index:
0, functionPtr: nullptr} entry. The array index field in each array
entry allows for gaps.

Change-Id: I7457f5eea5f14e5f94431b9cc6da042cb03517a0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-04-22 06:35:26 +02:00
Simon Hausmann fc3f603d00 Prepare for new members in QQmlPrivate::CachedQmlUnit
Pass the address of the entire structure through to the compiler, so
that when adding new members we can easily access them.

Change-Id: I5da75ba4e64d3e0e750a3ff3df4edbb88cdb6937
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-04-21 22:34:46 +02:00
Qt Forward Merge Bot 2812184e1b Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
	src/qml/jsruntime/qv4executablecompilationunit.cpp
	src/qml/jsruntime/qv4executablecompilationunit_p.h
	src/qml/qml/qqmlobjectcreator.cpp
	src/qml/qml/qqmlpropertycachecreator_p.h
	src/qml/qml/qqmltypecompiler.cpp
	src/qml/qml/qqmltypedata.cpp
	tests/auto/qml/qmlformat/tst_qmlformat.cpp
	tools/qmllint/scopetree.cpp
	src/qml/qml/qqmlapplicationengine_p.h

Adjusted tools/qmllint/findunqualified.cpp to use newer API

Change-Id: Ibfb4678ca39d626d47527265e3c96e43313873d4
2020-04-09 10:08:41 +02:00
Maximilian Goldstein faa3e0b41e Implement URL object
Implements the JavaScript URL object (https://url.spec.whatwg.org/#api).
Except that it does not currently implement the searchParams field.

Task-number: QTBUG-54988
Change-Id: I19abc69e075cbf84bd15e6791be195ce16f3fe73
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-04-08 14:53:30 +02:00
Lars Knoll fb3552e0d1 Remove QRegExp support from QtQml
Remove all code that supported converting between JS RegExp's and
QRegExp, as QRegExp is going away in Qt6.

Change-Id: I4863e68dd87a337d7e836d1b26c28ee3bb914e9f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-04-03 21:02:23 +02:00
Fabian Kosmale 2b8042182d Check that QJSValue to set conversion works
Also, fix the check to actually test the correct capabilities by using
the containerCapabilities function; testing _iteratorCapabilities only
worked by chance so far.

Task-number: QTBUG-82743
Change-Id: I64f20c6bf1e47737c7b927f79e1e78c1a1603741
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-03-24 21:30:14 +01:00
Ulf Hermann d51c007ecc Encapsulate QQmlContextData
This class is not a private detail of QQmlContext. And it is incredibly
hard to see who owns what in there. Let's add some civilization ...

We enforce refcounting for QQmlContextData across the code base, with
two exceptions:

1. QQmlContextPrivate may or may not own its QQmlContextData.
2. We may request a QQmlContextData owned by its parent QQmlContextData.

For these two cases we keep flags in QQmlContextData and when the
respective field (m_parent or m_publicContext) is reset, we release()
once.

Furthermore, QQmlContextData and QQmlGuardedContextData are moved to
their own files, in order to de-spaghettify qqmlcontext_p.h and
qqmlcontext.cpp.

When the QQmlEngine is deleted, any QQmlComponents drop their object
creators now, in order to release any context data held by those.
Before, the context data would be deleted, but the object creators would
retain the dangling pointer.

[ChangeLog][QML][Important Behavior Changes] QQmlContext::baseUrl() does
what the documentation says now: It prefers explicitly set baseUrls over
compilation unit URLs. Only if no baseUrl is set, the CU's URL is
returned. It used to prefer the CU's URL.

Change-Id: Ieeb5dcb07b45d891526191321386d5443b8f5738
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-23 12:00:33 +01:00
Ulf Hermann 748411fa64 Store a QV4::ReturnedValue in QJSValue
Being careful, we can now save primitive values inline. We use the heap
pointer of QV4::Value as either QString* or QV4::Value* for complex
types. We cannot store persistent managed QV4::Value without the double
indirection as those need to be allocated in a special place.

The generic QVariant case is not supported anymore. The only place where
it was actually needed were the stream operators for QJSValue. Those
were fundamentally broken:

* A managed QJSValue saved and loaded from a stream was converted to a
  QVariant-type QJSValue
* QVariant-type QJSValues were not callable, could not be objects or
  arrays, or any of the special types.
* Cyclic references were forcibly broken when saving to a data stream.

In general the support for saving and loading of managed types to/from
a data stream was so abysmally bad that we don't lose much by dropping
it.

[ChangeLog][QML][Important Behavior Changes] When saving a QJSValue to a
QDataStream only primitive values or strings will be retained. Support
for objects and arrays was incomplete and unreliable already before. It
cannot work correctly as we don't necessarily have a JavaScript heap
when loading a QJSValue from a stream. Therefore, we don't have a proper
place to keep any managed values. Using QVariant to keep them instead is
a bad idea because QVariant cannot represent everything a QJSValue can
contain.

Fixes: QTBUG-75174
Change-Id: I75697670639bca8d4b1668763d7020c4cf871bda
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-18 16:35:02 +01:00
Qt Forward Merge Bot 04e3918f0f Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/qmlmodels/qqmltableinstancemodel.cpp
	src/qmlmodels/qqmltableinstancemodel_p.h

Change-Id: I89339b1cb41ba27fe30c79530859a1c2bfbecc69
2020-03-03 12:23:20 +01:00
Simon Hausmann 8ab237edf1 Restore offset/length in QQmlJS::DiagnosticMessage
This is needed in a few places outside of declarative, so this change
restores the loc member in DiagnosticMessage and moves
QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory.
QQmlError is unaffected and retains only line/column.

Amends d4d197d062

Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-02 10:35:50 +01:00
Ulf Hermann 2b5e0f9011 V4: Fix mark stack overruns
Instead of applying a heuristic on when to call drain() in unrelated
code, we check the stack limit on each push(). If the soft limit is
reached we try to drain. As drain() itself can push again, we try to
limit the stack size by allowing at most 65 recursions of drain(). If
none of that helps, we crash with a meaningful error message.

This allows us to remove all the hacky drain() calls in other parts of
the code.

Change-Id: Ib979339470da0e85981de8131e7997755b757c71
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2020-02-27 15:08:29 +01:00
Ulf Hermann deb74c609e Fix build with -no-feature-network
Fixes: QTBUG-82418
Change-Id: Ibceeefed75941d963e6b79b44e9231d0d8053221
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2020-02-24 10:27:26 +01:00
Ulf Hermann 5884c214dc Avoid cast from ASCII to QString
The previous attempt to fix this was lost in a merge resolution.

Change-Id: I0638c434543d231352c44687b06bf429b7be7a04
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-02-20 15:29:38 +01:00
Fabian Kosmale 78fd438f15 QV4Engine: Avoid memory leak in toVariant conversion
Change-Id: I2c713fd759ac40aaaac0c0943edb993d3e27686b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-02-20 10:39:39 +01:00
Qt Forward Merge Bot d5a5e9dcd5 Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/qml/jsruntime/qv4engine.cpp

Change-Id: I61f41672e2dfe7e542ca30fed5f173d0a9ee3412
2020-02-13 13:09:47 +01:00
Fawzi Mohamed cc918272bb Avoid cast from ASCII in qv4engine warning message
Change-Id: Idb48122c4e7e294de820cd40036d7a6537ea2cac
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-02-12 10:17:57 +01:00
Fabian Kosmale 19cc92d170 QV4Engine: Do not construct invalid QVariant
If the provided typeHint is -1, it does not make sense to construct a
QVariant of this type and to check whether it is appendable.

Fixes: QTBUG-81945
Change-Id: I32cbb9e70e210a7eca8d55801c1783338d1173b7
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-02-07 09:14:15 +00:00
Qt Forward Merge Bot 7d86b35dc6 Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	.qmake.conf
	src/qml/types/qqmlbind.cpp
	src/quick/items/qquicklistview.cpp
	tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp

Change-Id: Id6805c13256ad13d5651011e5dd09bba0ec02987
2020-02-06 08:41:57 +01:00
Fabian Kosmale ecdb4ed275 Enable conversion from QJSValues containing arrays to container types
We started to convert containers to QJSValues, so that we could use them
as JavaScript arrays. Unfortunately, this would then lead to a type missmatch
when those same values where to be stored in a property of the container
type. This commit fixes this by converting them back to the original
type.

Fixes: QTBUG-80916
Change-Id: I30a3b03e17c34b171d4a6881dfd7801c13e94d80
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-01-31 14:48:28 +01:00
Simon Hausmann 020a6e6776 Add Qt.uiLanguage and QJSEngine::uiLanguage properties
[ChangeLog][QtQml] Added Qt.uiLanguage and QJSEngine::uiLanguage properties

These properties mirror the same value in QML and C++ and can be used
freely. They also provide API symmetry to Qt for MCUs.
QQmlApplicationEngine binds to this property and applies translations
accordingly by constructing a QLocale with the value and using
QTranslator::load(locale).

Change-Id: Id87d6ee64679b07ff3cb47844594e8eeebd8c8b6
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Christian Kamm <mail@ckamm.de>
2020-01-23 15:56:40 +01:00
Olivier Goffart c6899f1638 Replace QVariant::type with QVariant::userType
as type is going to be deprecated.

This change was done automatically with the help of clazy.
In addition, ColumnRoleMetadata was changed to take an int instead
of a QVariant::Type

Change-Id: Ibc02d7b52e7d931a56c19fdebc4788b5e6df2a39
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-01-17 11:31:35 +01:00
Qt Forward Merge Bot ba10b0b9ed Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/particles/qquickitemparticle.cpp
	src/qmlmodels/qqmladaptormodel.cpp
	tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp

Change-Id: Ibd8fbb91da6893a09f4ffe61ad0b95d8149bbc87
2020-01-09 07:24:26 +00:00
Fabian Kosmale e72b032cc1 QV4MM: Fix crash caused by MarkStack overflow
MemoryManager::collectFromJSStack did push to the mark stack without
checking if there is actually still space available. To fix this, we now
drain the stack once we hit the limit.

The test case is a slightly modified version compared to the reported
one, removing one loop. This was required as our regular expression does
not throw an exception when there are too many capture groups. However,
to trigger the bug, looping was not actually necessary.

Change-Id: I4d00865f25a989c380f4f5b221f4068c80b71d2b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-01-07 10:20:30 +01:00
Fabian Kosmale 01bbd7e41a QV4::ExecutionEngine: provide QNAM accessor
In XMLHttpRequest, we need to get the QNetworkAccessManager from the
engine. However, if the request originates from a WorkerScript, there
exists no qmlEngine. We therefore add a new indirection to access the
QNAM, and set it up accordinly in registerWorkerScript.

Fixes: QTBUG-81055
Change-Id: I8915202b6d6b7139c8386304b3d1d7a22a82045e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2020-01-03 12:02:18 +00:00
Fabian Kosmale ea3bfc91e2 QV4Engine: support conversion of QJSValue to SequenceType
8704c64094 introduced new conversions
via sequentialIterableToJS. Due to that, QVariant properties which
formerly stored e.g. std::vector<QObject*> now would store a QJSValue.
Those would still claim to support a conversion to QVariantList, but
-contrary to what our documentation says-, we were not able to do a
conversion to QSequentialIterable. The default constructed
QSequentialIterable would then crash when calling begin(), as that
function pointer was null.

This patch fixes this by adding the necessary support to convert a
QJSValue containing an array.
Non-array QJSValues will still return an "empty" QSequentialIterable.

Note that this changes what happens when a QJSValue is converted to a
QVariantList, as QVariantValueHelperInterface<QVariantList> will check
first if there is a converter to QSequentialIterableImpl before
attempting to call any directly installed converter to QVariantList. In
order to not change the existing behavior, the QSequentialIterable
returns the QVariant corresponding to the QJSValue at a given array
position, intead of a QVariant containing the QJSValue.

Fixes: QTBUG-80609
Change-Id: I8101229c0d2043b3f2d618ed035b279844802dd8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-12-20 10:51:21 +01:00
Liang Qi e7650520ef Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	.qmake.conf
	src/qml/jsruntime/qv4engine.cpp
	src/qml/parser/qqmljs.g

Change-Id: I5f89199ef7a846032a3118cba1298de992c22f8f
2019-12-17 07:25:13 +01:00
Tor Arne Vestbø 67417e8bc9 Remove use of wrapper macros for feature detection
Change-Id: Ic9cd7e4ff2c5d253879b0aeaa15dbc25cad82891
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2019-12-16 00:57:22 +01:00
Qt Forward Merge Bot 9c7121df15 Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/imports/qtquick2/plugins.qmltypes
	src/quick/items/qquickitemsmodule.cpp

Change-Id: I841c65c9c131354788b4f3fcfe3d7ed27be316d5
2019-10-04 11:29:16 +02:00
Ulf Hermann 873f13164d V4: Provide an environment variable to disable runtime stack size checks
With QV4_CRASH_ON_STACKOVERFLOW set you can use up all the stack
provided by the operating system to parse and execute JavaScript. Once
the stack space is exhausted the program crashes like it would in case
of a C++ stack overflow.

We cannot reliably determine either the maximum stack size or the amount
of stack space currently in use at runtime. Therefore, the guards we
usually put in place are necessarily conservative.

[ChangeLog][QtQml] There is now an option to disable the (necessarily)
conservative stack size checks when parsing and executing JavaScript. If
the environment variable QV4_CRASH_ON_STACKOVERFLOW is set, JavaScript
stack overflows crash the program the same way C++ stack overflows do.
On the flip side, more stack space is made available that way.

Task-number: QTBUG-74087
Change-Id: I5e9d9ec6c0c9c6258c31d9e2d04a5c1819fbf400
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-09-17 10:05:04 +02:00
Liang Qi c80eb38354 Merge remote-tracking branch 'origin/5.13' into 5.14
Conflicts:
	src/qml/jsruntime/qv4engine.cpp
	src/quick/handlers/qquicktaphandler.cpp
	src/quick/items/qquicktableview.cpp

Done-With: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Done-With: Ulf Hermann <ulf.hermann@qt.io>
Done-With: Shawn Rutledge <shawn.rutledge@qt.io>
Change-Id: If9558a33f01693ce96420c094e0b57dfff0626cd
2019-09-12 08:01:21 +02:00
Qt Forward Merge Bot f6ab93a9f9 Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I0ae0a162e133cffd8fb1a2c6b70826e50f06facd
2019-08-28 07:34:06 +02:00
Simon Hausmann 4b944cb61f Fix loading of ES modules when using CONFIG += qtquickcompiler
Added the missing lookup for cached .mjs files in
ExecutionEngine::compileModule. This allows using .mjs files in
WorkerScript {} elements in conjunction with the Qt Quick Compiler and
also fixes the use when using QJSEngine::importModule.

[ChangeLog][QtQml] Fix loading of EcmaScript modules when using the Qt
Quick Compiler.

Fixes: QTBUG-77761
Change-Id: I58130b0468f4920b2f6c49b98a2f51d5ae3a0491
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-08-26 12:42:05 +02:00
Ulf Hermann dbb38f35da Remove some unneeded includes
Change-Id: Id05059dfc9910dad206e511b08f18487e241e508
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-08 13:55:22 +02:00
Mikhail Svetkin 2392172394 Add environment variable for configure maxJSStackSize and maxGCStackSize
QMLEngine by default allocates 4 MB for javascript stack and garbage
collection stack takes 2 MB. It is a lot of memory for platforms without
virtual memory.

Change-Id: I1575dd9584898dca33df66704f716c7b5a7c01c1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-06-28 12:50:29 +02:00
Ulf Hermann d4d197d062 Simplify errors and diagnostics
We only need two classes to describe all possible diagnostics:

* A low-level private POD DiagnosticMessage. This is easily copied and
  passed around internally. It doesn't need to adhere to a stable API
  and it doesn't carry any extra baggage.

* The high-level public QQmlError with its stable interface. This can
  internally also use a DiagnosticMessage as storage.

Change-Id: I52be88d9b5d9855a661b8032b01eedb43a0fb0b3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-06-14 19:08:51 +02:00
Ulf Hermann 67191c2b32 Remove qqmlmemoryprofiler*
I've never seen it used and I've never seen the companion library
required to operate it.

Change-Id: I5a0e6aed9a416f1bd26dea97def9667a11a4d77d
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Michael Brasser <michael.brasser@live.com>
2019-06-13 12:58:39 +02:00
Ulf Hermann 9e6a8598e5 Clean up frozen(), sealed(), nonExtensible() and propertiesFrozen()
They all had some interesting bugs and duplicated each other:
a, propertiesFrozen() changed each property individually, creating a lot
of unnecessary intermediate classes. frozen() changed them all at once.
b, If a class happened to contain only properties that matched the
characteristics of being "sealed" or "frozen", sealed(), frozen() and
propertiesFrozen() would set the flags in place and return the same
class. This is bad because it violates the assumption that an
InternalClass is immutable and it breaks the recursive freezing
algorithm we rely on for the global object. It would stop freezing child
objects at any such class, even if the children were not frozen.
c, propertiesFrozen() did not set any of the flags even though it
effectively sealed and froze the class. Therefore, when requesting the
same class as frozen() it would iterate through all the properties
again.
d, frozen() implicitly also sealed the object and made it
non-extensible. sealed() also implicitly made it non-extensible. This is
impractical as we want to allow objects to be extensible even though all
their properties are frozen. Therefore we only set the flag that belongs
to each method now. We do know, however, that a frozen object is
implicitly sealed. Therefore we can short-circuit this transition.

Furthermore, we need to remove the assert in InternalClass::init() as
you can indeed use frozen objects as prototypes for others, but that
needs to be recorded in the original InternalClass via the isUsedAsProto
flag. In order to set this flag, we need to perform a transition and
therefore, derive from the old InternalClass.

The JavaScript isFrozen() method asks for an _implicitly_, "duck typed",
frozen state, which is different from what our "isFrozen" flag denotes.
Therefore we add a separate const method that just checks whether all
properties are frozen.

Task-number: QTBUG-76033
Change-Id: I375fef83fb99035d470490fdf2348766b090831e
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-05-31 12:31:14 +02:00
Ulf Hermann 7f7d87c68d Split CompiledData::CompilationUnit in two
We need a CompilationUnit that only holds the data needed for
compilation and another one that is executable by the runtime.

Change-Id: I704d859ba028576a18460f5e3a59f210f64535d3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-16 12:09:23 +00:00
Ulf Hermann fd6321c03e Remove last traces of QV8Engine
Change-Id: I59f738402d51e39188bbbca2ef1fbc8a61612372
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-08 12:05:36 +00:00
Ulf Hermann a8b3536d6e Move compileModule() into qv4codegen.cpp
This is a better fit for the method. In turn, remove all the
V4_BOOTSTRAP conditions from qv4engine_p.h and make sure we don't
include or compile it in bootstrap mode.

Change-Id: I5933b0724e561313ca20c420b83e4d70e63bddf5
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-08 12:05:30 +00:00
Qt Forward Merge Bot 0d409333d8 Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: I5d2c3da38df35922b2147c3c0bc55c6c3bae2fe5
2019-05-02 01:00:50 +02:00
Qt Forward Merge Bot ad6061b265 Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: Ic008bf9223a9ac293c925044355ff218f7ed7f78
2019-05-01 01:00:45 +02:00
Simon Hausmann d4239d2bf9 Fix maximum call stack depth for clang ASAN builds
For clang we need to use has_feature to detect the presence of an ASAN
build. Amends commit eb363c3a0b

Task-number: QTBUG-75410
Change-Id: I2adb69deb07f8c6b77be8c2f23751fd0a2bbdb95
Reviewed-by: Erik Verbruggen <erik.verbruggen@me.com>
2019-04-29 09:43:58 +00:00
Ulf Hermann 9e5ca92712 Remove tracing JIT infrastructure
The tracing JIT won't be finished. Therefore, remove the parts that have
already been integrated.

Change-Id: If72036be904bd7fc17ba9bcba0a317f8ed6cb30d
Reviewed-by: Erik Verbruggen <erik.verbruggen@me.com>
2019-04-29 09:16:34 +00:00
Qt Forward Merge Bot 23f988fe48 Merge remote-tracking branch 'origin/5.13' into dev
Conflicts:
	src/qml/compiler/qv4compilercontext.cpp
	src/qml/qml/qqmlmetatype.cpp

Change-Id: I02e0216961b92ff68a3f91a70edc33fe9e8db147
2019-04-29 09:12:31 +02:00
Qt Forward Merge Bot 332e514fb4 Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I552629813ea8100d04ea19e51fe7198931082e19
2019-04-27 01:00:40 +02:00
Simon Hausmann eb363c3a0b Fix maximum call stack depth limits for ASAN builds
ASAN enabled builds require more stack space and therefore our call
depth limits should be lower.

In my measurements with a recursion through arrow functions with the
interpreter, as per the test case in the bug report, different types of
builds require different amounts of stack space. On x86-64 Linux, I
measured, by printing $rsp and subtracting:

    Debug: ~6k
    Debug with -Og: ~590 bytes
    Release with -O2: ~570 bytes
    Release (-O2) with ASAN: ~40k

Fixes: QTBUG-75410
Change-Id: I403b261c677b1adb9f349958339b5a1294ae4d5d
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-04-26 13:36:22 +00:00
Ulf Hermann 561a2cec9b Transform V4_ENABLE_JIT into a feature
This way you can enable or disable the JIT when configuring Qt. The
conditions for the availability of the JIT have also been cleaned up.
There is no reason anymore to artificially restrict availability on x86
and x86_64. The reason for the existence of those clauses are old
problems on windows that have been fixed by now. However, on arm and
arm64, we need a specialization of the cacheFlush() function for each OS
to be supported. Therefore, restrict to the systems for which such a
specialization exists. iOS and tvOS are technically supported and you
can enable the JIT via the feature flag now. Due to Apple's policy we
disable it by default, though.

Change-Id: I5fe2a2bf6799b2d11b7ae7c7a85962bcbf44f919
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-04-25 11:07:36 +00:00
Qt Forward Merge Bot 934f25028a Merge remote-tracking branch 'origin/5.13' into dev
Conflicts:
	src/qml/qml/qqmlimport.cpp

Change-Id: I6add6267297ea50a646d43d212027a168dca8916
2019-04-18 08:01:45 +02:00
Ulf Hermann 68b7a66a6e Don't use UINT_MAX as invalid array index in PropertyKey
Technically UINT_MAX is actually a valid array index, although that is
an academic problem right now. However, we do have a method
isArrayIndex() and should just use that to determine if a PropertyKey is
an array index.

Fixes: QTBUG-73893
Change-Id: I302e7894331ed2ab4717f7d8d6cc7d8974dabb4e
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2019-04-16 08:06:26 +00:00
Qt Forward Merge Bot 8bc3329e2c Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts:
	src/3rdparty/masm/assembler/LinkBuffer.h
	src/qmltest/doc/src/qtquicktest-index.qdoc
	tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp

Change-Id: I7d83ad95cf489dda794dd7a0a33bad3ef3b05609
2019-04-15 09:36:12 +02:00
Ulf Hermann 0af154c41d Don't create value types for QImage and QPixmap
Those are "scarce" resources which need to be kept as QVariant.

Fixes: QTBUG-74751
Change-Id: I28381e2a754ed4bbf4e409dc275f6288b64416cc
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-04-12 12:13:54 +00:00
Friedemann Kleint 34c98070d1 Fix deprecation warnings about QVariant API
Fix warnings like:
sruntime/qv4serialize.cpp:378:45: warning: 'QVariant qVariantFromValue(const T&) [with T = QQmlListModelWorkerAgent::VariantRef]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
qml/qqmlvmemetaobject.cpp:597:61: warning: 'QVariant qVariantFromValue(const T&) [with T = QList<QObject*>]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
jsruntime/qv4engine.cpp:1319:66: warning: 'QVariant qVariantFromValue(const T&) [with T = QObject*]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
jsruntime/qv4engine.cpp:1350:60: warning: 'QVariant qVariantFromValue(const T&) [with T = QList<QObject*>]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
items/qquickitem.cpp:8396:78: warning: 'QVariant qVariantFromValue(const T&) [with T = QObject*]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
items/qquickitem.cpp:8693:80: warning: 'QVariant qVariantFromValue(const T&) [with T = QObject*]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
items/qquickgenericshadereffect.cpp:126:69: warning: 'QVariant qVariantFromValue(const T&) [with T = QObject*]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
items/qquickgenericshadereffect.cpp:127:55: warning: 'QVariant qVariantFromValue(const T&) [with T = QSize]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
items/qquickopenglshadereffect.cpp:713:69: warning: 'QVariant qVariantFromValue(const T&) [with T = QObject*]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
items/qquickopenglshadereffect.cpp:714:55: warning: 'QVariant qVariantFromValue(const T&) [with T = QSize]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
qquickcustomparticle.cpp:416:89: warning: 'QVariant qVariantFromValue(const T&) [with T = double]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]
qqmlenginedebugclient.cpp:403:47: warning: 'QVariant qVariantFromValue(const T&) [with T = QQmlEngineDebugObjectReference]' is deprecated: Use QVariant::fromValue() instead. [-Wdeprecated-declarations]

Task-number: QTBUG-74043
Change-Id: I14cb7d7c1fb8dc6321e32208a7de15f6bdb19065
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-04-08 08:44:15 +00:00
hjk 2895402cf6 Add another helper function for stack extraction
This makes the use of the feature easier and lowers the dependency
on setup of internal structures.

Also, evaluation of expressions is notoriously expensive and unreliable
on the gdb side, so moving the complexity to the compiled side is
an advantage.

Task-number:  QTCREATORBUG-22209
Change-Id: Id43d5c2bf4d852d496ceb59189209d167213afcb
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-04-08 08:28:20 +00:00
Qt Forward Merge Bot f385f6b39f Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: I9ba374f0c652628b7c84c36893c32b22529e384f
2019-03-29 01:00:40 +01:00
Qt Forward Merge Bot 4407f1f818 Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I910618824785f9119b1e1da9a82e998fd645a96f
2019-03-28 01:00:54 +01:00
Ulf Hermann b6d0ed435d Scope intermediate values when allocating objects
Otherwise the garbage collector might interfere and we might end up
with dangling pointers in random places.

Task-number: QTBUG-74190
Change-Id: I253c526ef930b8f0be14e96a42af8b66fda3b22d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-03-27 09:23:03 +00:00
Ulf Hermann a768780f36 Merge remote-tracking branch 'origin/5.13' into HEAD
Conflicts:
	src/qml/compiler/qv4compileddata_p.h
	src/qml/jit/qv4baselinejit.cpp
	src/qml/jit/qv4jithelpers.cpp
	src/qml/jsruntime/qv4lookup.cpp
	src/qml/jsruntime/qv4runtime.cpp
	src/qml/jsruntime/qv4runtimeapi_p.h
	src/qml/jsruntime/qv4vme_moth.cpp
	src/qml/qml/qqmltypemodule_p.h

Change-Id: If28793e9e08418457a11fc2c5832f03cab2fcc76
2019-03-22 14:57:04 +01:00
Qt Forward Merge Bot 7a349710cc Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts:
	src/qml/compiler/qqmltypecompiler.cpp
	src/qml/compiler/qv4bytecodehandler.cpp
	src/qml/compiler/qv4codegen.cpp
	src/qml/compiler/qv4compileddata_p.h
	src/qml/compiler/qv4compiler.cpp
	src/qml/compiler/qv4instr_moth.cpp
	src/qml/compiler/qv4instr_moth_p.h
	src/qml/jit/qv4baselinejit.cpp
	src/qml/jit/qv4baselinejit_p.h
	src/qml/jsruntime/qv4function.cpp
	src/qml/jsruntime/qv4vme_moth.cpp

Change-Id: I8fb4d6f19677bcec0a4593b250f2eda5ae85e3d2
2019-03-21 10:59:45 +01:00
Robin Burchell 8704c64094 QV4Engine: Unify fromValue and metaTypeToJS
Somehow, we ended up with two codepaths doing essentially the same
thing: constructing a JS value from a QVariant. metaTypeToJS is invoked
from QJSEngine::toScriptValue, whereas fromVariant() is used in various
places internally.

metaTypeToJS lacks proper handling for a number of cases, such as
builtin types like QPointF, which lead to toScriptValue(QPointF)
(incorrectly, and uselessly) constructing a VariantObject which couldn't
then do anything useful.

[ChangeLog][QtQml] QJSEngine::toScriptValue will now return correct
JavaScript objects in more cases, for example, for gadget types like
QPointF.

[ChangeLog][QtQml] QJSEngine::toScriptValue now uses the same
behavior as the rest of the engine when building JavaScript values, which
will cause the types of some returned JavaScript objects to change. For
instance, string lists are now returned as sequence objects, not array
objects, and QChar now constructs a JavaScript string.

Change-Id: I0290eb7c9c46e7b508d497cc33cd61d9378f3872
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2019-03-21 03:08:27 +00:00
Simon Hausmann c9e6251cc8 Implement dummy QML lookups for "global" variables
When resolving names in the context of QML bindings, we now direct
runtime access to QQmlContextWrapper::resolveQmlPropertyLookupGetter. At the
moment this does basically the same as Runtime::method_loadName, which
we called earlier. However this now provides the opportunity to optimize
lookups in the QML context in a central place.

When performing a call on a scope or context object property, we also
did not use a CallName() instruction - which would have gotten the
thisObject wrong - but instead we use a dedicated
CallScopeObjectProperty and CallContextObjectProperty instruction. These
rely on identifying these properties at compile time, which goes away
with lookups (and also doesn't work when using ahead-of-time
compilation). Therefore the qml context property lookup is using a
getPropertyAndBase style signature and
Runtime::method_callQmlContextPropertyLookup uses that.

For the tests to pass, some error expectations need adjusting. In
particular the compile-time detection of write attempts to id objects is
now delayed to the run-time.

The old code path is still there and will be removed separately in the
next commit (as it is massive).

Task-number: QTBUG-69898
Change-Id: Iad1ff93d3758c4db984a7c2d003beee21ed2275c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-03-20 09:16:02 +00:00
Ulf Hermann d2fd8010d3 Support QRegularExpression on the same level as QRegExp
QRegularExpression is the recommended way to do regular expressions
nowadays. Support assignment of JavaScript regular expressions to
QRegularExpression properties of QObjects and the other way around.
QJSValue::toVariant() will create a QRegularExpression from a JavaScript
RegExp by default now.

[ChangeLog][QtQml][Important Behavior Changes] QRegularExpression is now
supported the same way QRegExp is in QML. QJSValue::toVariant() creates
a QRegularExpression variant rather than a QRegExp one from a JavaScript
regular expression now.

Fixes: QTBUG-73429
Change-Id: I301a02771cd17903406c2bc5c7aaeca6cce629f0
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-03-20 08:05:04 +00:00
Erik Verbruggen 784a55a15d V4: Collect trace information in the interpreter
Collect type information about values used in a function. These include
all parameters, and the results of many bytecode instructions. For array
loads/stores, it also tracks if the access is in-bounds of a
SimpleArrayData.

Collection is only enabled when the qml-tracing feature is turned on
while configuring.

In subsequent patches this is used to generated optimized JITted code.

Change-Id: I63985c334c3fdc55fca7fb4addfe3e535989aac5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-01-25 10:26:13 +00:00
Liang Qi 1b4d2741f9 Merge remote-tracking branch 'origin/5.12' into dev
Conflicts:
	.qmake.conf
	tests/auto/quick/qquickpathview/tst_qquickpathview.cpp

Change-Id: Ic1f5e219a255d0613f7654368a5ce3eccb8f0ee9
2019-01-22 11:20:29 +01:00
Erik Verbruggen 8fd3cfe7d0 Annotate stack traces when frames are elided through tail calls
Task-number: QTBUG-72407
Change-Id: I98b96852309fc783a945797185f666196513d24b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-01-15 17:35:46 +00:00
Qt Forward Merge Bot 24dfffe33b Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: Ic5a0c02ab45aac18c218dbeb8cd4b4cd3b609eb6
2018-11-17 01:01:00 +01:00
Qt Forward Merge Bot 8a9a907fc9 Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: I85be5e6ef173fa733d7febd3209164bb31762e0d
2018-11-06 01:00:09 +01:00
Lars Knoll 6746417e71 Don't crash when compiling with QT_FORCE_ASSERTS enabled
Change-Id: I9af3dc69cc5baf1c35e836345590baf5b55b1bed
Fixes: QTBUG-70937
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-11-02 13:29:23 +00:00
Allan Sandfeld Jensen 7f0db6d047 Add convenience functions for creating and inspecting error objects
Serves to simplify porting from QtScript by replacing
QScriptContext::Error and QScriptContext::throwError().

Change-Id: I4bfe404c358c50aaf3b5469a4304fec97552bf24
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-10-30 12:41:54 +00:00
Qt Forward Merge Bot 8092a4e247 Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: I0ad1a3aa3a211ef86c4baf605361de860266dde1
2018-10-12 01:00:07 +02:00
Valery Kotov f47c87e75f QML Engine: Support for JavaScript Promises
Support for JavaScript Promises.

Change-Id: I90ce328b35f3bdf3fd666a8829f22b5d56b6f861
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-10-11 08:27:48 +00:00
Jędrzej Nowacki 01ed625542 Teach QML that it is possible to treat custom QObjects as QObject
It is always better to treat a QObject child as QObject then a QVariant.

Change-Id: I4ac069e85232dd4d1411e325bc5b858bd001f9a6
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-10-08 10:02:04 +00:00
Jędrzej Nowacki 5f4b3fa3ca Add support for QSequentialIterable in QML
That means that now QML understand many sequential value types
and it is able to convert it to a JS array.

Fixes: QTBUG-60338
Change-Id: I46943b7c130296bb64c23008ce2e52a55d7f019d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-10-08 10:01:54 +00:00
Lars Knoll 20a434faa8 Speed up instanceof operations
Introduce a shortcut if the rhs is a functionobject with the
regular function proto as prototype.

Add an optimized instanceOf implementation when we already have some
checks done, and inline some methods.

Change-Id: Iab9b648ae7bbec749b319e883b6ae90a23875454
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2018-09-27 08:34:14 +00:00
Lars Knoll 7c59262503 Unify layout of function objects
Ensure we have the proto property at always the same place.
This will be used in a subsequent commit to optimize accesses
to the prototype property e.g. when doing instanceof
operations or constructor calls.

Change-Id: I6e9a19e0b7d0e8ab583648a60d1978f5cf838b06
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2018-09-27 08:34:10 +00:00
Lars Knoll 7cc66a996e Get rid of remaining assumptions about setter being next to getters
The only place where we now assume that getters and setters are
next to each other in the MemberData is in the internal class.

Change-Id: I3285f3abb1cbfe051853e808339cd360eb602262
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2018-09-27 08:33:59 +00:00
Lars Knoll 1804fea889 Refactor InternalClass::find()
Specialize find() into several methods for different purposes.
Prepares for further cleanups and being able to split up
getter and setter for accessor properties.

Change-Id: Id4ec5509ac1a1361e2170bbfc2347b89b520c782
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2018-09-27 08:33:52 +00:00
Lars Knoll a97d118bf5 Better inheritance structure for functions
Give Arrow functions their own representation. This also prepares
for further optimizations especially for the instanceof operator.

Change-Id: I1f70c0271169a237e1acdeb7fe855be957ba2ea5
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-09-23 17:27:43 +00:00
Lars Knoll 1dac47c141 Cleanups in Value/Primitive
Get rid of Primitive and move the corresponding methods
directly into Value. Mark many methods in Value as
constexpr and turn Value into a POD type again.

Keep Primitive as a pure alias to Value for source
compatibility of other modules that might be using it.

Change-Id: Icb47458947dd3482c8852e95782123ea4346f5ec
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-09-17 07:47:09 +00:00
Lars Knoll ff5bc526b4 Add support for yield*
Change-Id: I5b054b59519ed825459a5b0b0a7cd2c6fc8a3797
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-09-07 10:32:01 +00:00
Lars Knoll 656db7a425 Don't define a prototype property for most functions
Only functions that are constructors should have a prototype
property.

Change-Id: Ifcf6f8b6c38de055d871d57ada38a23432974263
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-09-04 18:25:10 +00:00
Lars Knoll 94f0d86b5d Add support for WeakSet
Change-Id: I5cee2bf0c6a45ad2c14b52e1a4fc5ef015e01042
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-28 21:45:48 +00:00
Lars Knoll 464b878b97 Implement support for WeakMap
Change-Id: Id23e80fe5918ba7dc897568123bf3db4d35e9092
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-28 21:45:45 +00:00
Lars Knoll e4e220fb56 Partial Atomics support
Implement support for basic atomic operations on
SharedArrayBuffers.

Half of the methods still need a proper implementation.

Change-Id: Ia88da358e0c2ae6d28e9bcc1feb8980b6f51a812
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-26 16:59:33 +00:00
Lars Knoll 7bdb46c5aa Clean up the code handling reads and writes into typed arrays
This is a preparation for supporting atomic operations on Typed arrays.

Change-Id: I91d00f3aee3f35fc22e74ee010ed2cbec2d46aae
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-25 08:30:04 +00:00
Lars Knoll 860807b22a Implement support for SharedArrayBuffer
We'll still need to hook this up with Worker threads to become
useful.

Change-Id: Iedae7307edd76368aeba163731856ebe9b32c6b6
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-25 08:30:00 +00:00
Lars Knoll 732c25029e 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>
2018-08-23 19:18:19 +00:00
Lars Knoll 34094f6918 Fix toLocaleString implementations in (Typed)Array.prototype
Change-Id: Idcabd68b1651ad3cae315a16cb0e1361cba21253
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-23 08:13:35 +00:00
Simon Hausmann 4b2b1fc121 Add support for compiling ES modules ahead of time
This is also pretty straight-forward by adding .mjs as supported
extension in the qmake and cmake support.

This also tweaks qv4engine.cpp to share the same module compilation
function across all code paths.

Change-Id: Ia0e23c78a794f2330ecf8f991ee6ea948f4ac89d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-08-17 11:06:18 +00:00
Simon Hausmann 29e4b97bad Add support for disk caching of ES modules
Two minor fixes needed for this otherwise straight-forward change:

    (1) When compiling modules, use the full url for the source file of
    the compilation unit, as that's what we use for the relocation check
    when loading the cache file.

    (2) Record the proper source time stamp for cache invalidation.

As a bonus, when importing scripts from .qml files, we now also attempt
to use the cached version that we created on the fly in an effort to
replace heap memory with mmap backed memory - just like we do for .qml
files.

Change-Id: I5b03a18e3c44d537c3242cb1d969636df32fe42a
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-08-17 11:06:16 +00:00
Simon Hausmann f43c1d902d Add support for importing ES modules in .qml files
This is a straight-forward hook into the module implementation in
QV4::ExecutionEngine. Modules are pre-compiled in the QML type loader
thread. That thread keeps track of all pending loading scripts through
the type loader's m_scriptCache. Once a module is compiled, it's
thread-safely registered with the execution engine.

Script instantiation and evaluation is done solely in the QQmlEngine's
thread.

ES Modules are identified in imports as well as qmldir files by the .mjs
extension.

Change-Id: Ie9c59785118afcb49f43a1e176a9f7db00f09428
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-08-17 11:06:12 +00:00
Simon Hausmann 0e45db9a04 Fix order of own property names of module namespace objects
They must be sorted, no duplicates and only one default entry at most.

Change-Id: Ia9c0e54a761ce7cbfebb837330bf3769d505eb3b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-08-15 18:55:53 +00:00
Lars Knoll 5819700e0c Fix spec compliance for the RegExp constructor
Change-Id: I767b27faab912e91962797ca154d929473113cc1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-15 14:24:45 +00:00
Lars Knoll b862d429b1 Fix some details in RegExp handling
Change-Id: If9f7c07ea657ba8503b9188a7b77e301f23423ef
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-15 14:24:41 +00:00
Lars Knoll cda5885efa Improve RegExp.prototype[Symbol.match] implementation
Change-Id: Id632a4f4648f68f3b46d31f84e4ee05c86391f3e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-15 14:24:26 +00:00
Lars Knoll a1964f0b8e Cleanup RegExpObject
Move properties from RegExpObject to getters in RegExp.prototype
to be compliant with the JS spec.

Implement support for the sticky flags ('y') and correctly parse
the flags in the RegExp constructor.

Change-Id: I5cf05d14e8139cf30d46235b8d466fb96084fcb7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-15 14:24:23 +00:00
Simon Hausmann 8bebd12c1b Improve error handling for non-existent file imports
Change-Id: Ic043d30738c97836cf6afada6ee7cade23bf50f9
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-08-14 17:45:41 +00:00
Lars Knoll 886d463061 Enable unicode regular expressions
Add support for the 'u' flag for regular expressions.

Change-Id: I409054eaa9c50183619752d14f2638f5a38c0ea7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-10 14:16:12 +00:00
Simon Hausmann 82da798499 Add initial basic support for ES6 modules
The entry point from the parsing perspective into modules is not
QV4::Script but QV4::ExecutionEngine::compileModule.

For convenience, the ESModule AST node gets a body, which is the
statement list connected between the ModuleItemList items that are not
import/export declarations.

The QV4::Module allocates a call context where the exported variables
are stored as named locals. This will also become the module namespace
object.

The imports in turn is an array of value pointers that point into the
locals array of the context of the imported modules.

The default module loading in ExecutionEngine assumes the accessibility
of module urls via QFile (so local file system or resource). This is
what qmljs also uses and QJSEngine as well via public API in the future.

The test runner compiles the modules manually and injects them, because
they need to be compiled together with the test harness code.

The QML type loader will the mechanism for injection in the future for
module imports from .qml files.

Change-Id: I93be9cfe54c651fdbd08c5e1d22d58f47284e54f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-08-09 13:18:39 +00:00
Lars Knoll d046de0ddb Setup the prototype correctly when subclassing error objects
Change-Id: I5e394ef8d4d6d87bedb26070d51660e3ebe3ab1b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-06 10:00:45 +00:00
Lars Knoll 245cb6b6a3 Fix a couple of test failures related to error objects
Set up the prototype chain for error objects correctly, and make
them inherit from the right classes.

Change-Id: I7bb12b3bb285950a1bff25e5c62954287a95970a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-02 20:25:18 +00:00
Lars Knoll 4ac9cf7896 Fix the remaining test failures with non strict arguments objects
Change-Id: Ib50f602263dd0146d792fb3d12bd5971585fda30
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-07-30 20:45:06 +00:00
Lars Knoll fc01254cf8 Fix class members that are generators
Properly support member functions that are generators in classes.

Change-Id: I5fc8d5b58a17c61a446b43d6576bb83de5ecd920
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-07-03 11:19:03 +00:00
Lars Knoll 2666fe4a14 Move the C++ and JS stack frame definitions into it's own file
Change-Id: I86e89e07197aec6071809c2d32bd5c98cb7ac6f6
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-07-03 08:08:49 +00:00
Lars Knoll 0b6bc89c61 Remove ExecutionEngine::setCurrentContext()
It's unused and shouldn't exist. Also de-inline currentContext()
to avoid a dependency on the CppStackFrame in the header.

Change-Id: I44724f8097883dc1b1064430778f45f7811460df
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-07-03 08:08:46 +00:00
Lars Knoll 32c33ee9ab Get rid of Value::asArrayIndex()
It was only used in a few places now, that can be replaced by
either using a PropertyKey, or by limiting the fast path
optimization in the runtime to array indices smaller than
INT_MAX. Since there are less branches this should even be
faster for pretty much all use cases.

Change-Id: Ib4f2f2f3e27f14ad180b810546e82ac83170b106
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-07-02 19:29:52 +00:00
Lars Knoll 56bff8f7ab Clean up the property key API in StringOrSymbol
Get rid of makeIdentifier(), as toPropertyKey() will take
care of it.

Rename identifier() to propertyKey() and check that the
key is valid.

Remove String/StringOrSymbol::asArrayIndex(), we don't need it
anymore.

Change-Id: I3c490fabc1475c9ea288b49b1638b6fa1bc237b7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-07-02 19:29:43 +00:00
Lars Knoll db695c5b1d Unify the get and getIndexed vtable functions of QV4::Object
This finalizes the refactoring of Object's vtable API. Also added
the receiver argument to the method as required by the ES7 spec.

Change-Id: I36f9989211c47458788fe9f7e929862bcfe7b845
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-07-02 19:29:29 +00:00
Lars Knoll eae4756f74 Add a MemberFunction function object
Member functions in ES7 can not be called as constructors and
will throw a type error when trying.

Some more fixes are needed here, as they also do not have a
prototype property.

Change-Id: Ieb920163acaa68d4ff0ff73ae4c1015e883b406f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-06-26 10:04:18 +00:00
Yulong Bai 74f4065caa Add basic support for EcmaScript classes
Most of the class creation is done inside the runtime
in the CreateClass method. Added a corresponding
instruction to the interpreter and jit.

The compiled data now contains an array of classes
containing the compile time generated layout of the class.

Currently, classes without an explicit constructor and
classes with inheritance are not supported.

Done-with: Yulong Bai <yulong.bai@qt.io>
Change-Id: I0185dcc1e3b0b8f44deff74e44a8262fc646aa9e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-06-26 10:03:56 +00:00
Liang Qi 8597f74e52 Merge "Merge remote-tracking branch 'origin/5.11' into dev" into refs/staging/dev 2018-06-25 10:16:26 +00:00
Ulf Hermann fbf6f7400a Merge remote-tracking branch 'origin/5.11' into dev
Conflicts:
	src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp
	src/quick/handlers/qquickhandlerpoint.cpp
	src/quick/handlers/qquicksinglepointhandler.cpp
	tests/auto/qml/ecmascripttests/test262

Change-Id: I8908ec8c6116ca626fbd269af7625d4c429429ca
2018-06-25 12:15:55 +02:00
Lars Knoll 1596112e14 Add Proxy support for prototype handling
Cleanup get/setPrototypeOf and fix some smaller incompatibilities
in the default implementation for Object.

Add the methods to the vtable and reimplement them according to
spec for ProxyObjects.

Clean up the Object.prototype.get/setPrototypeOf/__proto__ methods
and fix a smaller bug in the Reflect API for those methods.

Change-Id: I6e438753332ec4db963d6cdcf86f340ff212777a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-06-25 07:36:48 +00:00
Lars Knoll f5a7953df3 Partial Proxy support
get, set and deleteProperty proxying is implemented,
the others require some more changes in our engine.

Change-Id: I4dd4b154b1a582f5e36cdc9429fa049fd37d5167
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-06-25 07:36:17 +00:00
Lars Knoll 12bc11e5af Add support for Reflect
Implemented all methods in Reflect, only some smaller
bugs left in there.

Change-Id: I53d2304d0e59566aec64e200cd995e02afcfc33e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-06-21 19:43:41 +00:00
Lars Knoll d1693c14b4 revert change 353164263c
The change was too aggressive in trying to avoid marking
the array data. We didn't catch all cases where on could be
inserting a GC controlled object into the array data. Let's
be safe and always mark the content of array data objects.

Task-number: QTBUG-68894
Change-Id: Ifbb628be898c0903596b1a483212384295b01df5
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2018-06-19 14:20:44 +00:00
Robin Burchell a0fcf724ef Add the start of a Map from ES7
Like Set, for the time being, this is baseed on top of ArrayObject: two
of them, one for keys, one for values. Again, this goes against the
spirit of the spec (which requires nonlinear access), but having the API
present is at least a start, and the implementation is easily changed.

Change-Id: Idcf0ad8d92eb5daac734d52e8e2dd4c8e0dd5109
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-06-01 11:53:37 +00:00
Robin Burchell 19f657d995 Add the start of a Set from ES7
Based on top of an ArrayObject for now, which is admittedly a bit of a
cheat and not matching the "spirit" of the spec. OTOH, that makes it
easy to write, and is presumably quite lightweight, so perhaps this is acceptable
as a starting point.

Change-Id: Ibc98137965b3e75635b960a2f88c251d45e6e837
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-05-30 20:57:17 +00:00
Lars Knoll 3ccd529e35 Implement toPrimitive() the way the ES7 spec wants it
Add Dat.prototype[Symbol.toPrimitive] and make use of those
methods in the toPrimitive implementation.

Change-Id: I82a9a94dcae6822100de364373b3f4de1e3d749b
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
2018-05-28 10:40:08 +00:00
Lars Knoll 6cbc287c06 Cleanup JS stack allocations
Avoid double writes to the stack, and use scope.alloc() for
most allocations on the stack.

Change-Id: I8b89273c1b6796d955fc8eeb72c67cff208ef786
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-26 06:49:04 +00:00
Lars Knoll de95f4da8b Fix the inheritance structure for typed arrays
Change-Id: I8a16c1f5e0252b4ea85ff8f623beb39df747e383
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-24 08:09:33 +00:00
Lars Knoll b254bbb82b Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I0127f2c16de1d930bdd8cbccd42ec6785f31ab96
2018-05-24 09:15:57 +02:00
Lars Knoll 3de014db9e Fixup the throwTypeError internal function
Make the function conform to section 9.2.7.1 of the spec.

Change-Id: Ieb3295198f407d4404e06a54efb51a8b8496bbd7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-23 13:19:28 +00:00
Simon Hausmann 60176efa78 Fix crash when incubating objects with non-existent initial properties
When incubation is triggered from C++ and reaches the state of setting
the initial properties (as supplied to incubateObject), we'd set
engine->currentStackFrame to a CppStackFrame that provides access to the
correct QML context. As we're not called from the interpreter, the
v4Function pointer would be a null pointer. If during the initial
property setting an exception is thrown (due to non-existent property
access) and a back-trace is created, we'd end up dereferencing
v4Function.

Change-Id: I7f6b0ba7893bfb4186f55d4c213b4bb602d29aa0
Task-number: QTBUG-68416
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-05-23 11:06:34 +00:00
Lars Knoll cc8cb4b442 Implement Symbol.species getter functions
Change-Id: I18b3e382e679f95d7cb53b4ed03be2513ea0204b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-15 18:21:10 +00:00
Lars Knoll c4ef0d6e4b Call iterator.return when required in destructuring assignments
Array destructuring assignments require a call to iterator.return if
the iterator hasn't been exhausted during destructuring.

Change-Id: I39fe4bc01bef6fb2ad3bda92caf6779fbbddc8e2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-14 19:32:42 +00:00
Lars Knoll 3d5ba9f86e Add instructions to simplify for-of loops
Added an IteratorNext instruction to fetch the next
iteration value (empty if the iterator is done).

This will also help to implement array destructuring without
requiring huge amounts of byte code.

Change-Id: If96c1e81471e5e2b0b7b2af122238d87741aa371
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-13 12:55:20 +00:00
Lars Knoll 4cf7e80c57 Ensure we have a lexical scope for global code
This requires a bit more work than simply pushing a
new BlockContext for the lexically declared variables,
as eval() and the Function constructor operate on the
global scope (including the lexically declared names).

To fix this introduce Push/PopScriptContext instructions,
that create a BlockContext for the lexically declared
vars and pushes that one as a global script context that
eval and friends use.

Change-Id: I0fd0b0f682f82e250545e874fe93978449fe5e46
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-11 07:17:05 +00:00
Lars Knoll 8e69a9868c Avoid accessing an object with this == nullptr
Get rid of a circular dependency when initializing
StringObject.prototype, by setting it's string value
later during the initialization process.

Change-Id: I5bdaff3936c1f8af12c4d53f95747b8aa43f4ef6
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-04 18:13:09 +00:00
Lars Knoll 4f086e3aac Rename ForeachIterator to ForInIterator
As it's being used for for(... in ...) loops. Also add a ES6
compatible iterator interface to it, so that we can unify
the handling of for-in and for-of.

Change-Id: I264f88ed049484945f5ea7e8bdf0227187456ba2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-04 18:12:50 +00:00
Lars Knoll 1f9fdd1af7 The length property of function objects is configurable
Change-Id: I657be2e2eb4dfd86850bb73e85d4ddd24f0b8986
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-03 20:05:18 +00:00
Lars Knoll 5747a75302 Add Generator support
Add support for ES6 generators. Those are currently
always executed in the interpreter (we never JIT them),
to simplify the initial implementation.

Most functionality, except for 'yield *' expressions
are supported. 'yield *' will have to wait until we
support for(... of ...)

Change-Id: I7c059d1e3b301cbcb79e3746b4bec346738fd426
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-03 20:05:14 +00:00
Lars Knoll 8761cbd4f7 Implement StringIterator
Add support for String.prototype[Symbol.iterator] and the
StringIterator object.

Change-Id: I72c4f988e4f363be1af51f9cc5f8e83af43cd151
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:29 +00:00
Lars Knoll 7d46d72510 Implement support for arguments[Symbol.iterator]
Change-Id: Ieb60e2d8f41c38146b588bc8cd225a2a567e0956
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:25 +00:00
Lars Knoll c7fe748850 Cleanup creation code for builtin functions
Centralize the code in FunctionObject::createBuiltinFunction and setup
function names and length properties there.

Change-Id: I21f1d42b475070ee091d96d97387149af1dc47f2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:21 +00:00
Robin Burchell a4207b2f95 Add Array Iterator objects from ES6 (22.1.5)
And implement / expose them via:
    22.1.3.4 - Array.prototype.entries()
    22.1.3.13 - Array.prototype.keys()
    22.1.3.29 - Array.prototype.values()
    22.1.3.31 - Array.prototype[Symbol.iterator]

Most tests for Array iterators now pass.

At the same time, expose them on TypedArray's prototype:
    - 22.2.3.15 %TypedArray%.prototype.keys
    - 22.2.3.29 %TypedArray%.prototype.values
    - 22.2.3.6 %TypedArray%.prototype.entries
    - 22.2.3.31 %TypedArray%.prototype[Symbol.iterator]

For TypedArray, test coverage improves a tiny bit (3 passing tests), but the
vast majority fail as it seems like the object structure for TypedArray is
currently incomplete as far as ES6 expects.

It seems that ES6 expects the object structure to be:
* %TypedArray% (inherits FunctionObject)
    (this is the TypedArray intrinsic object, and responsible for initializing
    the TypedArray instances)

* All the TypedArray ctors (e.g. UInt8Array)
    These inherit %TypedArray%, and make a super call to it to do their work

* %TypedArrayPrototype% (inherits Object)
    (this is the initial prototype for %TypedArray%)
    * All the ctors have their own separate instance of this
    * The instances also make use it

So, for instance, a lot of the tests attempt to access the prototype like:
    var proto = Object.getPrototypeOf(Int8Array)
    var keys = proto.prototype.keys

As ES6 expects Int8Array.prototype to be %TypedArray% (22.2.5), this expands to:
    Object.getPrototypeOf(%TypedArray%)
which it expects to be %TypedArrayPrototype%.

But since we have no intrinsic object, and the ctors inherit
FunctionObject, we instead return the wrong prototype into 'var proto'.

Change-Id: I5e1a95a0420ecb70a0e35a5df3f65557510c5925
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:13 +00:00
Lars Knoll 37b85ca10e Add SymbolObject, well known symbols and fix most remaining issues
Added SymbolObject, the equivalent to StringObject which was
still missing so far. Added the predefined standard symbols,
and fixed most test failures related to symbols.

Change-Id: I1e28b439e7c4f5141b4a09bd8fb666c60691f192
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:45 +00:00
Lars Knoll 360a48aa3f Implement Symbol.for and Symbol.keyFor
Change-Id: I5fde731b3a1a6d7c15154881ed82549b2800d104
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:41 +00:00
Lars Knoll bab5e5adf5 Partial Symbol support
Added basic infrastructure to create symbols and convert them
back to strings. In addition, storing and retrieving of symbol
based properties in Objects works.

Change-Id: I185f7aa46e7afa19db5a801102142892e03b7bf1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:36 +00:00
Lars Knoll a6da23bb5f Garbage collect identifiers
Implemented by storing a backpointer to the Heap object
in the identifier.

Since identifiers now point back to their originating
String or Symbol, we can now easily mark all identifiers
that are still in use and collect those that aren't.

Since Identifiers are 64bit also add support for holding an
array index in there. With that an identifier can describe
any kind of property that can be accessed in an object. This
helps speed up and simplify some code paths.

To make this possible, we need to register all
IdentifierHash instances with the identifier table, so that
we can properly mark those identifiers.

Change-Id: Icadbaf5712ab9d252d4e71aa4a520e86b14cd2a0
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:32 +00:00
Lars Knoll 3c090c80c5 Remove String dependency from InternalClass
This is required, so we can also use Symbols in
the internal classes.

Change-Id: I630e7aa7b8b16d5a94041f8d18515fd582f94264
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:23 +00:00
Lars Knoll 922e6f42b4 Rework catch context handling
Remove the need for a specialized catch context, instead
use a regular block context, that also captures the
catched variable.

This also removes the need to do lookups by name inside
a catch expression.

Change-Id: I8b037add7f423922e2a76b4c0da646ca7e25813a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:17:51 +00:00