Commit Graph

660 Commits

Author SHA1 Message Date
Ulf Hermann e3e8008ec3 Allow retrieval of sequences from QJSValue
As we can store sequence types in QJSValue, we should be able to
retrieve them, too.

Move the declaration of the QV4::Sequence struct into a header to make
it less of a hassle to identify sequences.

Change-Id: I3e45bfe193c669107f90cd6c502765c0c9f60fb0
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-06-02 02:42:51 +02:00
Ulf Hermann 2bed3d5f0f V4 Engine: Don't try to convert JS functions to other types
When converting a JS value to a variant, if we notice that we get a
QJSValue again, there is no point in trying to convert it further. We'll
just run into infinite recursion.

Pick-to: 6.3
Fixes: QTBUG-102545
Change-Id: I0a40e21287e5460e5e214101aabe8d2b4bf0afad
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-05-09 11:59:49 +02:00
Andrei Golubev b4d5b64359 Make QQmlEngine resolve closures when executing runtime functions
QML can create a function which holds a closure in the cases like:

onSignal: function() { ... }

If the left-hand side is a signal handler (or similar), we want to
execute the *inner* function when a signal is called, not the outer
one. However, under certain conditions (e.g. we use `this`), the
outer function must also be called beforehand to correctly setup the
calling scope for the inner function

Thus, make the QQmlEnginePrivate::executeRuntimeFunction() do that:
always call an outer function first and then the inner one if present.
This creates an overhead when dealing with certain signal handlers but
we could optimize it later if needed

Note that the case `property var prop: function() { return 42; }` where
a property contains a callable function is no longer supported by the
executeRuntimeFunction() routine (we always call the inner code now).
This is fine since qmltc (the main beneficiary of the routine) does not
rely on this functionality when dealing with property bindings

Given the change, qmltc can be simplified to only work with absolute
function indices, ignoring the nesting problem altogether

Change-Id: I61f61587b6fe700cb695b3b7a213d9cfab0eb746
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-04-27 15:29:24 +02:00
Andreas Buhr 38d455dca0 Adapt qv4engine to stack size on Android
Adapt maximum stack size to not run into segfaults
due to stack overflow.

Pick-to: 6.2 6.3
Task-number: QTBUG-102384
Task-number: QTBUG-96788
Change-Id: I4ba3518369c822b1b2d93388817beb7f86d19cdc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-13 18:17:08 +02:00
Ulf Hermann 6fb6303296 ExecutionEngine: Move initialization of statics into separate method
... and do it only for the first engine (ie engineId == 1). The engineId
is determined using atomic operations, so this is safe now.

Pick-to: 6.3
Task-number: QTBUG-73271
Change-Id: Ife38213fe04e26f35425a29230a2e3b586572dd2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-05 07:19:33 +01:00
Ulf Hermann 7680fc7bee Adjust default max call depth for QNX
QNX by default has smaller stacks than other platforms.

Pick-to: 5.15 6.2 6.3
Change-Id: Ia83d4e12c0fd24c51069777db2283d456c49800f
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Pasi Petäjäjärvi <pasi.petajajarvi@qt.io>
2022-01-25 23:55:27 +01:00
Ulf Hermann f73e294472 Remove the qml_sequence_object feature flag
QML sequences are required for named lists of value types. The original
reason for the introduction of this feature was the template code
explosion caused by the way the sequence types were registered in Qt5.
As we register them differently now, the code size overhead should be
smaller. It makes very little sense to switch sequence types off these
days.

[ChangeLog][QtQml][Important Behavior Changes] The qml_sequence_object
feature flag has been removed. Omitting sequences from the QML language
does not make much sense now that we use them for lists of value types.
The original reason to allow it was that the sequence support took up a
lot of space in the binary. This is not the case anymore since 6.0.

Change-Id: I2f1d43cdd29ba63853316b06113cb49ed30aa410
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-15 14:22:42 +01:00
Ulf Hermann bf115a446c Improve type conversions from/to QJSValue
We can convert everything into a QJSValue if we have an engine and we
can save a binding function in a QVariant by wrapping it into QJSValue.

Change-Id: I48e7c13f3f744f1c50bf673b427fe9331250f313
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-20 15:51:23 +02:00
Ulf Hermann 9d9df8073d Use value type providers in metaTypeFromJS
Pick-to: 6.2
Task-number: QTBUG-96144
Change-Id: If12f669ae33bb8ae4768ca79e4ca985f70a2651d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-09-06 11:03:09 +02:00
Andrei Golubev 2c730b211b QV4Engine: Do not use currentContext() when calling JavaScript from C++
This turns out to be not quite valid since context hierarchy is
afffected. It was fine before since all the generated classes either
had the same context or a dead-simple hierarchy + the tests for
comprehensive usage were lacking. The problems arise when contexts are
meant to be different for unrelated JS calls e.g. in property bindings
with non-trivial cross-context dependencies (e.g. derived property
uses both neighbor property and base class property in a binding)

As a drive by, simplify QQmlEnginePrivate::executeRuntimeFunction():
* Expect function index to always be valid (in range), it's a very bad
  otherwise anyway
* Use QQmlData::outerContext directly as a context argument for
  callInContext(). This is what was done anyhow, just through a
  QQmlContext -> QQmlContextData conversion, which is actually needless

Change-Id: I8ac6b181363a5d03e468c2b6f35db2dac188ea8b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-06-21 16:51:17 +02:00
Ulf Hermann dbe34dfa0d Fix conversion of entries to be added to QVariantLists
We should pass the variants themselves, not their constData().

Fixes: QTBUG-94502
Pick-to: 6.1 6.2
Change-Id: I92688348d7b46d74935dc11080b26290f5e8be86
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-17 10:22:32 +02:00
Ulf Hermann e20650e070 Eliminate JS call frame from metatypes calls
If we call an AOT-compiled function we never need the JavaScript call
frame. We can just skip its setup and save some overhead.

Change-Id: I39dc2ca6eea5b5a66f3b87b642a310534cecf6cd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-10 11:53:19 +02:00
Ulf Hermann c4addf7d0e Pass QMetaType by value rather than by ID in more places
This saves us some ping-pong between the IDs and the QMetaTypes, and
avoids possible ambiguities if multiple metatypes are registered for the
same C++ type.

Change-Id: I81cec94a9cd05d69927dc884f65574f0ab2ddc22
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-09 14:47:13 +02:00
Ulf Hermann 2bedff619c Rename QQmlMetaType::metaObjectForMetaType into metaObjectForValueType
It really only works for value types and it's not intended to do
anythign else. The name should reflect this.

Change-Id: Ib73bf7e9655971f7826fe72145e2d2fab363363c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-08 08:26:06 +02:00
Ulf Hermann 28c4d536e2 Allow value type conversion in metaTypeFromJS
We implicitly do the same when calling toVariant().

Change-Id: I288326125d88bc658dcaf12d3ee623e0e529bb69
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-02 10:18:03 +02:00
Edward Welbourne 0a673d257a Make QDate handling consistent in its use of UTC
Due to the quirk of ECMAScript's Date.parse() spec [0] stipulating the
use of UTC for date-only strings, in contrast to most other ways of
creating a Date using local time, reasonable users get surprised by
the behavior of QDate properties initialized from strings. This can't
be avoided without breaking other uses of Date, so document the
work-around needed to cope with it (use UTC-specific methods to access
the Date object).

[0] https://tc39.es/ecma262/#sec-date.parse

Make conversions back to QDate from Date work round the possibility
that the Date, seen as a QDateTime(,, LocalTime), needs to be handled
as UTC when extracting the date, and catch two more places that
conversion from QDate neglected to use UTC's start of day, for
consistency.

Revised tests to call UTC-specific methods instead of the local-time
ones, where appropriate. Drive-by: some tests were (entirely bogusly)
constructing a fresh Date using the UTC-fields of the Date they had,
in order to then test the non-UTC fields of this fresh Date; instead,
simply test that the UTC fields are as expected.

[ChangeLog][QML][Behavior change] Where a QDate is represented in
QML's JavaScript as a Date, it is now more consistently associated
with the start of the UTC day it describes. Previously cases where it
was represented as the start of local time's day could lead to a Date
turning into a QDate for the preceding day. Inconsistencies in the
specified behavior of Date preclude eliminating such problems
entirely, but they should now be limited to cases where (perversely
for a date property or parameter) the date is specified with a local
time late enough to make it coincide with the start of the next UTC
day (in which case that next day's QDate will be its C++
representation).

Fixes: QTBUG-92466
Change-Id: I2306dd9ecef0d5c2d59b562762392e51bb6d66ca
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-18 16:24:13 +02:00
Andrei Golubev 2f9b62ea59 QQmlEngine::executeRuntimeFunction: pass return value as input argument
Use the newer version of QV4::Function::call() that does not require
manual JSCallData setup and is more optimal for AOT function calls

Change-Id: I5a5e2d0477c0603b05b7213f1b2adcc34d156bf5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-11 08:48:11 +02:00
Maximilian Goldstein 0fef848468 qv4engine: Fix enums getting turned into objects when passed in lists
Previously passing a QList of a registered enum would result in an array of objects instead of the array of numbers which usually represent enum values in QML.
You now get an array of numbers as you would expect.

[ChangeLog][QtQml][Important Behavior Changes] QJSEngine::toScriptValue() used to return a QVariant containing an enum, now it returns the enum directly. If you still wish to use valueOf() on the resulting value use QJSEngine::toManagedValue() instead.
[ChangeLog][QtQml][Important Behavior Changes] A QList containing enums will now result in an array of numbers instead of an array of objects.

Fixes: QTBUG-85861
Change-Id: I5c28f4489dfd02d8256aa818e27b1dd6b7d3113d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-05-06 17:13:51 +02:00
Alex Shaw 3464655f5e Add QJSEngine::registerModule
Some applications that use JavaScript as a scripting language may want
to extend JS through C++ code. The current way to do that is with
global objects.
ES6 provides a better way of encapsulating code: modules.
registerModule() allows an application to provide a QJSValue as a named module.
Developers familiar with Node.js will find this very easy to use.

Example:
```c++
QJSValue num(666);
myEngine.registerModule("themarkofthebeast", num);
```
```js
import badnews from "themarkofthebeast";
```

[ChangeLog][QtQml][QJSEngine] Adds the ability to register QJSValues in
C++ as modules for importing in MJS files.

Change-Id: I0c98dcb746aa2aa15aa2ab3082129d106413a23b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-01 17:26:00 -04:00
Ulf Hermann 3c9339f3c8 Support native transformation between UrlObject and QVariant/QUrl
URL has become a builtin type. We should support it on the same level as
QString/String and QDateTime/Date.

In order to continue support for comparing URL properties with the
JavaScript equality operators, we still pass URLs as variants when
using them in JavaScript. However, we now create proper URL objects for
QJSValue and QJSManagedValue, and we allow transforming the URL-carrying
variant objects back into QUrls.

Change-Id: I78cb2d7d51ac720877217d2d4b4d0ab17cdd2a4b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-22 22:15:36 +02:00
Fabian Kosmale d009c0088b QV4::Engine::toVariant: Use metatype instead of metatype id
This way, we can avoid the costly id to metatype lookup in case where we
actually need the full metatype.

Task-number: QTBUG-88766
Change-Id: Ibe29b323007f00d2f8d1807fb9b64f9a8f87e807
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-25 21:25:28 +01:00
Ulf Hermann 3e277e2292 Allow creation of QJSValues from QQmlListProperty
This is pretty much the same as creating them from QQmlListReference.

Change-Id: I8d873840fc08887655d19a61b028f3eb60eaf938
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-25 21:25:24 +01:00
Ulf Hermann 8fe127129b Inline retrieval of QML contexts
In the good case this is just reading a few members of the relevant
classes. No need to call functions for this.

Change-Id: I9908cd6437cf9a1ca840f9aa0e524d3976272d67
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-25 11:31:09 +01:00
Ulf Hermann 2943eb3b11 Use QMetaType for ExecutionEngine::metaTypeFromJS()
We should avoid looking up metatypes by ID. That's expensive.

Change-Id: I00ce0a7f95ec82b0db6e7eb976e39e50522a7fe4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-24 10:17:35 +01:00
Ulf Hermann dcf0d1d94e Avoid qMetaTypeId() in ExecutionEngine::fromData()
It's expensive.

Change-Id: Ib892027869286772da53e989954063c94505ddbd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-23 21:37:01 +01:00
Ulf Hermann daf296d639 Support more type conversions
We need to be able to retrieve QQmlListReference and attached objects
from QJSValues.

Change-Id: I39679317da4066b054e86f767fc5f723ead2b2e7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-23 16:09:50 +01:00
Ulf Hermann 165b3aa086 Avoid string operations on type signatures where possible
Parsing the type from a signature is expensive and we can do better in
most cases.

Change-Id: Iae85f4dec9ad6b8de60efeb3469a253fd0862672
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-23 16:09:49 +01:00
Ulf Hermann a5e1a7d70b Optimize stack frame setup for AOT compiled functions
When called via the metaobject system, parameters and return values are
passed as void*, with accompanying type information in the form of
QMetaType. The same format is expected when calling an AOT
compiled function.

Previously, we would first convert all the parameters to QV4::Value,
just to convert them back the moment we notice that there is an AOT
compiled function. This is wasteful.

This change provides a second call infrastructure that accepts void* and
QMetaType as parameter and return value format, and passes them as-is
all the way to any AOT compiled functions. If there is no AOT compiled
function, the conversion is done when detecting this, rather than when
initiating the call. This also passes the information "ignore return
value" all the way down to the actual function call. If the caller is
not interested in the return value, we don't have to marshal it back at
all.

For now, we only add the extra "callWithMetaTypes" vtable entry to
ArrowFunction. However, other callables could also receive variants
optimized for calling with void*/int rather than V4 values.

This required changing the way how function arguments are stored in the
property cache. We squeeze the return type into
QQmlPropertyCacheMethodArguments now, and we use QMetaType instead of
integers. In turn, we remove some unused bits.

Change-Id: I946e603e623d9d985c54d3a15f6f4b7c7b7d8c60
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-23 06:53:10 +01:00
Ulf Hermann 9caea013ce Clean up JSCallData setup
We either have pre-populated arguments and thisObject, then we can just
use them and keep them const. Or, we want to allocate and populate the
arguments and the thisObject. Then, do allocate them in a separate
object, and transform that into JSCallData afterwards if necessary.

Furthermore, avoid alloc(0) as that just returns the current stack top.
Writing to it will clobber other data. Rather, just use nullptr and
crash if it's written to.

Also, remove the useless operator-> from JSCallData. That one just
confuses the reader.

Change-Id: I8310911fcfe005b05a07b78fcb3791d991a0c2ce
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-17 13:10:22 +01:00
Ulf Hermann b0e9c83f99 Don't store the scope in JSCallData
We only need it when generating CallData, or when filling in any
thisObject or arguments that weren't provided. Provide a constructor
that expects thisObject and arguments to be pre-allocated and one that
allocates them in a scope passed as argument.

Change-Id: Iddfba63f4dbc5b09e2b33fb22a94eea88f515902
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-17 13:10:16 +01:00
Ulf Hermann 490257d447 Optimize QML context retrieval for AOT functions
We can cache the QQmlContextWrapper rather than retrieving it twice.

Inline some things, and do not unnecessarily create and destroy ref
pointers.

Change-Id: Ife0980f83b7efe1ea9dc56aacbfbccd029ce77c8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-13 12:56:47 +01:00
Ulf Hermann eb2386a042 Optimize ExecutionEngine::metaTypeToJS()
We almost never need to construct a QVariant to do this. Constructing a
QVariant is excessively expensive if you have something simple like an
integer. This also fixes the unexpected "unwrapping" of variants when we
pass them through QJSValue.

[ChangeLog][QtQml][Important Behavior Changes] If you create a QJSValue
from a nested QVariant (that is, a QVariant containing another
QVariant), then, when retrieving its contents again, the outer variant
is not unwrapped anymore. Rather, you get exactly the value you've
passed in.

Change-Id: I8c16eed4f13e8cfdeced0756eef593b3b8e84dd1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-13 10:08:48 +01:00
Fabian Kosmale 7d65ebf1e6 QV4Engine: remove redundant check
We already covered the case where the metatype's flag indicate that it
is a QObject. That is exactly the same check used in
QQmlMetaType::toQObject, so if the test did not succeed before, it won't
succeed now either.
As a drive-by, avoid useless metatype-id to metatype lookup.

Change-Id: Ie36a07587aa2b899d2a932bcb3f4a0b5da8aa282
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-05 15:54:44 +01:00
Fabian Kosmale fe38b5c906 Engine: Cleanup method argument passing
Instead of arguments around as a pointer to
[argc, metaTypeId1, metaTypeId12, ...]
pass argc and a pointer to [QMetaType1, QMetaType2] around.
Moreover, make use of the fact that we now carry the metatype instead of
only the id in a few places, to avoid id -> metatype lookups.

Task-number: QTBUG-82931
Change-Id: Ib00e4d793727f85f3358a8162d1aac972daab3d3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-04 18:18:19 +01:00
Fabian Kosmale 8e904d9c8b QML engine: Handle const QObject pointer correctly
[ChangeLog][QML][Important Behavior Changes] If a QObject pointer is
passed to the QML engine and subsequently frozen with Object.freeze,
modifying its QObject properties now fails and throws a TypeError. The
TypeError is thrown even in non-strict mode.

[ChangeLog][QML] It is now possible to pass const QObject derived
pointers to QML in properties, and to call Q_INVOKABLE functions which
take such pointers as arguments. If the QML engine receives such a
pointer, it is treated as if the object was frozen.

Fixes: QTBUG-82354
Change-Id: Ib0dbcdfb2370654505936c3cf391d87dd2c9677b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-01 14:56:39 +01:00
Fabian Kosmale 871d85a1de metaTypeToJS: use QMetaType instead of id
Task-number: QTBUG-82931
Change-Id: I7b663c5f774ef3edbb19d5f2ef53cfe623a8e4cf
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-02-19 18:12:43 +01:00
Fabian Kosmale 3b91f3a69a QV4::populateJSCallArguments: Use v4->metaTypeToJS
It appears that nowadays v4->metaTypeToJS handles QVariant and QObject
derived classes just fine, and in exactly the same way as the custom
code in populateJSCallArguments did.

Task-number: QTBUG-82931
Change-Id: Ic5f97dfc3296a409fdd6a1fcb78d3b9bdba5f3a1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-02-19 18:12:29 +01:00
Ulf Hermann 453be4e606 QJSValue: Allow casting integers to enums
You can also cast enums to integers, after all.

Pick-to: 6.1
Change-Id: I283d3dd280eeb44ba22bb45ca9be69e5358d5781
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-19 00:13:17 +01:00
Andrei Golubev f3281ca869 Support runtime functions evaluation by index through QQmlEngine
Add execution function that can evaluate runtime functions available
in the compilation unit. Private API for now as it's unclear what would
be a comprehensive solution to support all existing use cases

Task-number: QTBUG-84368
Task-number: QTBUG-91039
Change-Id: Icf755b53484587d7983eaae4821c1aa0111d5c05
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-02-12 12:00:09 +01:00
Ulf Hermann 25f765cbd9 Unregister value types when tearing down QML types
Move the value type registry into QQmlMetaTypeData. This way we can
conveniently drop the relevant entries when unregistering a type.

Fixes: QTBUG-86946
Change-Id: Id024a34a8b2b622fd9417fc0e52864b43c66cc01
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-12 11:36:25 +01:00
Ulf Hermann c0b59369ab Respect QML_DISABLE_DISK_CACHE also for caches built into the binary
Previously it would only disable loading of separate cache files.

Change-Id: Iae92fc03d2e5566ef7dc44a6730b788b7512fd3d
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-12-10 12:22:30 +01:00
Fabian Kosmale 77c02343e2 Use QMetaType instead of metatype-id, take 2
This time, the ValueTypeFactory gets converted. As a consequence, many
callers get touched again.

Task-number: QTBUG-88766
Change-Id: I3a8b7d5cfeb7fac85daf1702febba205971d4256
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-12-03 10:38:43 +01:00
Ulf Hermann 6cfe4cbebb Mark url as builtin type
Also, allow conversion from UrlObject and String. We allow the string
conversion because we treat string and url as interchangeable in various
places.

Change-Id: Ib229c6d190e1c5d849ea18798925965b8dbeef7e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-12-02 21:44:16 +01:00
Ulf Hermann 3dc1339dba QV4Engine: Fix conversion of char16_t
This is a single char16_t, not an array of them.

Pick-to: 5.15
Change-Id: I55d23ebb5f2abebd43cd4160a75d373706392ddf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-17 09:44:03 +01:00
Ulf Hermann f0908255c9 QtQml: Integrate sequences with registration macros
You get to write QML_SEQUENTIAL_CONTAINER(value_type) now, and
qmltyperegistrar will generate a sensible registration call from that.
A registration might look like this:

struct MyStringListForeign
{
    Q_GADGET
    QML_ANONYMOUS
    QML_SEQUENTIAL_CONTAINER(QString)
    QML_FOREIGN(MyStringList)
    QML_ADDED_IN_VERSION(3, 1)
};

It's unfortunate that we need to use a metaobject to transfer all of
this information, but there is no other sensible way.

Transform the containers defined in qv4sequenceobject.cpp to use the new
style, and move them out of the builtins, into QtQml. Recognize that
only one of them was ever tested, and add tests for the rest.

Task-number: QTBUG-82443
Change-Id: I3a30f9e27266bb575eea26c5daf5dad1ec461cc5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-11 11:37:49 +01:00
Ulf Hermann cbe1869fbe QML: Rewrite Qt object in actual C++
Quite obviously, the Qt object is a singleton, extended with a
namespace, backed by a member of the JavaScript global object.

Defining all the methods as JavaScript functions is unnecessary and
duplicates the general type transformation code. Also, it makes it
hard to use those same methods from a C++ context as we cannot
properly set up the arguments outside the JS engine.

Rewriting the Qt object reveals some deficiencies in the old
implementation that we need to fix now:

1. The enums of the Qt type were listed as properties of the Qt object,
which means you could iterate them with a for..in loop in in JavaScript.
This is just wrong. Enums are not properties. This functionality
is deleted and the test adapted to check for each enum value separately.
The commit message for the change that introduced the iterability
already mentioned that the author had failed to find any occurrence of
this in the real world.

2. Parsing time objects from strings was done by parsing the string as a
date/time and then picking the time from that. We still support that for
now, but output a (categorized) warning. Parsing the time directly is
preferred where possible.

3. Previously you could create (invalid) dates and times from various
kinds of QML types, like int and color. This does not work anymore as we
now validate the types before calling the functions.

4. Passing more arguments to a function than the function accepted was
unconditionally ignored before. Now, a Q_CLASSINFO on the surrounding
class can specify that the arguments should be checked, in which case a
JavaScript error is thrown if too many arguments are passed. In order
for this to work correctly we also have to ignore JS undefined values as
trailing arguments for overload resolution. This way, if a method
matching the defined arguments exists, it will be preferred over a
method that matches the full argument count, but possibly cannot accept
undefined as parameter.

Consequently a number of error messages change, which is reflected in
the qqmlqt test.

[ChangeLog][QtQMl][Important Behavior Changes] You can not iterate the
enumerations of the Qt object in JavaScript anymore. This does not work
with any other enumeration type either. You can of course still access
them by name, for example as Qt.LeftButton or similar.

[ChangeLog][QtQMl][Important Behavior Changes] The time formatting
functions of the Qt object in QML now allow you to pass an actual time
string, rather than a date/time string as argument. Passing a date/time
string results in a warning now.

[ChangeLog][QtQml][Important Behavior Changes] Functions in the Qt
object for formatting date and time will now throw a JavaScript error
when presented with a value of an incompatible type, such as int or
color.

[ChangeLog][QtQml][Important Behavior Changes] The Qt.resolvedUrl()
function now returns a URL rather than a string. This follows the
documentation.

[ChangeLog][QtQml][Important Behavior Changes] The GlobalColor enum of
the Qt namespace is not exposed to QML anymore. It did not make any
sense before as the enum values could not be used as colors.

Change-Id: I7fc2f24377eb2fde8f63a1ffac5548d652de7b12
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-09 18:10:38 +01:00
Ulf Hermann d621027bab V4: Rewrite qv4sequenceobject based on QMetaSequence
This avoids the template explosion and makes the mechanism extendable.
You can now register additional anonymous sequential containers.

Fixes: QTBUG-71574
Task-number: QTBUG-82443
Change-Id: I5b9ed9af1533a3b7df8fc5bb37bbb73b8304e592
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 13:21:09 +02:00
Ulf Hermann fe27257a07 Adapt to changes in QMetaSequenceInterface and iterables
metaSequence() became metaContainer() and we should ask for canConvert()
as there are two ways to convert to a container.

Change-Id: Iba868491ff9d2cc8fc89de1cab29818b834b53f4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-25 19:09:40 +02:00
Ulf Hermann fb33abddb0 Adapt to change in QMetaSequenceInterface::valueMetaType
valueMetaType is a QMetaTypeInterface* now.

Change-Id: If7e12e89b1801258d9e0892cbfb3b70b85b52376
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2020-09-18 20:56:09 +02:00
Ulf Hermann 0b92a93e8e Avoid various warnings about deprected QMetaType methods
Change-Id: I8f4b2703fdd08ff341904219cec33c321e0511c7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-09-16 08:36:58 +02:00
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