Commit Graph

660 Commits

Author SHA1 Message Date
Tarja Sundqvist 7ac842cba1 Merge tag 'v6.5.5-lts' into tqtc/lts-6.5-opensource
Qt 6.5.5-lts release

Conflicts solved:
	dependencies.yaml
	src/quick/doc/snippets/qml/treeview/qml-customdelegate.qml

Change-Id: Ifa297315fa0e6e70d9f26312f9183da4769d18fc
2025-01-29 16:12:28 +02:00
Tarja Sundqvist eee1fcc18b Revert "Update commercial SPDX-License-Identifier"
This reverts commit da5933f22c.

Revert of commercial SPDX license identifiers is required for the
Qt 6.5.x opensource releases, Qt 6.5.4 onwards.

Change-Id: Ic056fb761f242af0ec4c883ecb35d50804c1c67c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2025-01-03 19:25:16 +02:00
Fabian Kosmale 301cae0a70 QJSValue: convert more aggressively to QVariant
Normally, we don't want to convert aggressively between JS objects and
QVariant, as that is prone to losing information. However,
QJSValue::toVariant is documented to attempt lossy conversions. Restore
the behavior of Qt < 6.5.3 for it. This is done by replacing the boolean
indicating we should wrap JS objects into QJSValue with an enum instead.
That enum introduces a third state ("Aggressive"), which is only used
for QJSValue::toVariant. All other users of QJSEngine::toVariant behave
as before (post 6.5.3).
Function objects are still not converted, as we know that this would be
a futile attempt, and more importantly, to keep the behavior that
existed  before Qt 6.5.3.
Amends 4307755655 which introduced the
regression and afe96c4d63 which  fixed the
issue only partially.

Fixes: QTBUG-119963
Change-Id: I07d9901437812579ac5b873a4dff4de60c8f617e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 4d7ce35bd2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit bc4e1d74eb)
(cherry picked from commit 2b3997e292)
2023-12-20 17:18:26 +00:00
Dmitrii Akshintsev cc95e11f86 QML: Add missing metaType-s to ExecutionEngine::metaTypeFromJS
After debugging QTBUG-117384 it was found out that ExecutionEnginge is
failing to convert Long and ULong types to a meta-type, because they were
missing from the switch statement.

Fixes: QTBUG-117384
Change-Id: Idcd7325e783df45d27323cb9d9d8372ddde25c3e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit c7fc870aa5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit eb9f0f1bcc)
2023-10-25 06:39:44 +00:00
Ulf Hermann 18acf22095 QtQml: Correctly convert to QQmlListProperty<QObject>
If we have a QQmlListWrapper, we can extract its property.

Fixes: QTBUG-117829
Pick-to: 6.2
Change-Id: I46ae8db1aabf7c1b617a22f371ce4f060cf4bb38
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit bb698b7f2e)
(cherry picked from commit 20fd12d7f5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-10-24 10:32:45 +00:00
Tarja Sundqvist da5933f22c Update commercial SPDX-License-Identifier
Updated the commercial SPDX-License-Identifier to
the files in tqtc-qtdeclarative. Examples, tests, or
documentation files were not updated.

Task-number: QTQAINFRA-5900
Change-Id: I74e2ac15b270b503edc80369b126913dd2ec33e1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-10-23 12:34:14 +03:00
Ulf Hermann 5dc4a90e35 QML: Allow conversion from JS Array to QByteArray
Since QByteArray is sequentially iterable and we allow any sequentially
iterable type to be constructed from a JS array, we also need to allow
this.

Fixes: QTBUG-115733
Change-Id: I6ffd5eaad0e587ea1cafbe0c1b0179202f3f28cf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 9599f4c553)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-08-08 22:20:02 +00:00
Ulf Hermann 79175ef102 QML: Do convert objects with prototypes to QVariantMap
While we shouldn't convert to QVariantMap if only QVariant is requested,
we should convert if QVariantMap is explicitly requested. QVariant can
hold QJSValue which is a better fit for objects with properties.
QVariantMap cannot hold QJSValue. A best effort conversion is still
better than an empty map.

Amends commit 47678c682f.

Fixes: QTBUG-115523
Change-Id: Iaa96809ee411dc0db95311c641c4e3f1f51a6026
Reviewed-by: Amanda Hamblin-Trué <amanda.hamblin-true@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit afe96c4d63)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-07-28 07:42:42 +00:00
Ulf Hermann 39297011b5 QML: Allow conversion of symbols to QVariant
We produce their descriptiveString or simply a QVariant containing a
QJSValue, depending on whether we're supposed to convert objects without
equivalent C++ type or not.

Fixes: QTBUG-113854
Change-Id: I22b6038c936d860fdd8aa227f9dfe704e3265a77
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 8c451bba7a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-06-20 10:08:04 +00:00
Ulf Hermann 7f2a203415 QML: Try QML conversion before metatype conversion
and guard against null gadgetPtr. This is what we get for uninitialized
value type properties.

Fixes: QTBUG-114494
Change-Id: I86ad23abcc4fec219017d1aad6b7add1c9a9af5d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit a2104034d4)
2023-06-16 21:02:29 +02:00
Ulf Hermann e6e541c8c4 QML: Allow creating constructible value types from variant objects
VariantObject as source for value type constructions should work the
same way as other types.

Change-Id: I35770adf0486b404673ee00800fb1d3e429a23cf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 0bb0eeeb09)
2023-06-16 09:37:20 +02:00
Ulf Hermann 1d48273786 QML: Allow coercing variant objects to their own type
This allows passing unregistered value types through QML.

Task-number: QTBUG-114340
Change-Id: I6fa5adadf2d406d2d5f3a83fb922e9d547e7ead9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit cd16a5ffb9)
2023-06-09 09:35:32 +02:00
Ulf Hermann 3c1b817261 V4: Unify type conversions for date and time values
We should always use the same conversion to string and we shouldn't
duplicate the code for the date conversion.

Task-number: QTBUG-109380
Change-Id: I1b1959c8e9b5957ddcf287d252b8143511237565
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 330c3e91ee)
2023-06-06 20:20:09 +02:00
Ulf Hermann f3ac335b43 QtQml: Allow coercion to signed char in metaTypeFromJS
So far we rely on QVariant::convert() and that only works in some
places and is expensive.

Change-Id: Ia6be7807c3d245148fcd4f4bed2ebc9e35ad52ff
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 7bcac62265)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-06-05 15:35:30 +00:00
Ulf Hermann 8d7facdce7 QML: Allow conversion from QV4::Sequence to different iterable
Fixes: QTBUG-112291
Change-Id: Idd47ea8daf9c54759af6c1feba68bd52d1163615
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 1b89c1edca)
2023-05-11 09:24:36 +02:00
Ulf Hermann 348a539da7 QML: Encode "missing" line number as negated address of stack frame
This way we can identify which entry in a stack frame to amend when
processing an exception in generated code. However, negative line
numbers are also used to signal the position of "Ret" instructions.
Since you cannot throw an exception from a "Ret" instruction, those
cannot collide, but we cannot qAbs() the line number anymore when saving
it in the stack trace. We have to qAbs() it in all the places where it's
read.

Fixes: QTBUG-112946
Change-Id: I24dc4008fb7eab38e4d24e70211c22e46f1b72a7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 406a9e1301)
2023-05-11 09:24:36 +02:00
Ulf Hermann 47678c682f QML: Don't try to convert objects with prototypes to QVariant
This is likely to lose some properties.

Fixes: QTBUG-106266
Change-Id: Ib5a2567d61635a5cf7b3abee7cfef0c073d59e63
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 4307755655)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-05-10 09:10:27 +00:00
Ulf Hermann ecf96e3388 QmlCompiler: Fix coercion of undefined to float and double
It should result in NaN, not in 0. The typedArray() test exposes that
ExecutionEngine::toVariant() also gets this wrong. Fix that, too.

[ChangeLog][QtQml][Important Behavior Changes] Converting a JavaScript
value to a double or float, for example by inserting it into a typed
array, now assumes JavaScript type coercion semantics. In particular,
converting a value that is not actually a number now results in NaN
where it previously sometimes resulted in 0.

Fixes: QTBUG-111179
Change-Id: If24444ae9014c8972761c565a6920f06699e485c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b9834e0ee9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-02-21 14:36:14 +00:00
Fabian Kosmale 850fdaa79e Remove superfluous Q_DECLARE_METATYPE
It breaks unity builds, and declaring metatypes outside of the actual
class that uses them is generally a bad idea.

Change-Id: I0106667f6075aabc2fa3c9e5271d21b64f41e4c1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit e3831511de)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-02-08 23:00:19 +00:00
Ulf Hermann 29b67d4c34 QML: Treat long and ulong like other numbers
They should either be the same size as int/uint or the same size as
longlong/ulonglong, but for some reason we get them as separate types.

Fixes: QTBUG-110767
Change-Id: I4c5826cfe6108e6f9722e6b3443bde13b2141b04
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 11bc79d7c6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-02-08 07:11:10 +00:00
Ulf Hermann ebd3a76034 QML: Fix write back of Date values
A JavaScript Date object can be backed by QDate, QTime or QDateTime.
Allow those to be written back.

Fixes: QTBUG-28981
Change-Id: Ic46b5c4daf75453f03e99470933cf179820e63ef
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 51089b3389)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-17 03:50:56 +00:00
Ulf Hermann b0a681e084 Allow extraction of V4 values from QJSPrimitiveValue
Since we can produce QJSPrimitiveValue in metaTypeFromJS, we should also
handle the other direction.

Fixes: QTBUG-109867
Change-Id: I2c7598d19eba3e78d071ca3eceb32deda4d0ead8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit e070b5aa39)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-17 03:50:51 +00:00
Ulf Hermann 2b7c811844 QmlCompiler: Fix wrapping of numbers in QJSPrimitiveValue
We need to explicitly cast to double if we are wrapping a number type
that's not natively accepted by the ctors.

As a side effect, correctly run conversions from generic QVariant to
QJSPrimitiveValue through the engine now. For that we need another
clause in metaTypeFromJS().

Since we are calling methods that return list types in the test, we need
to add another clause that converts JS arrays to list types. Otherwise
we cannot run that test in interpreted mode.

Task-number: QTBUG-109111
Change-Id: I87f7aafd24371d2c1ffe85569e1f2cd3a1979742
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b13e22f274)
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2022-12-16 12:09:24 +01:00
Edward Welbourne f01de8f397 Route Qt::TimeSpec usage via QTimeZone
QTimeZone now packages Qt::TimeSpec details, unifying QDateTime APIs.

Task-number: QTBUG-108199
Change-Id: I4a6bfaa213ec6db2fb357d20c7cd59e8c58ad103
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-12-11 14:13:09 +01:00
Ulf Hermann 4677b2bdd6 QML: Add an accurate stack bounds checker
This re-introduces a stack bounds checker. The previous stack bounds
checker was removed in commit 74f75a3a12
because the cost of determining the stack base was deemed too high.

Indeed, determining the stack base on linux using the pthread functions
costs about 200.000 instructions and the cost grows with the number of
concurrently running threads.

However, by reading /proc/self/maps directly we can trim this to about
125k instructions. Furthermore, with the new implementation we only need
to do this once per engine. Calling JavaScript functions of the same
engine from different threads is not supported. So we don't have to
consider the case of checking the bounds of a different thread than the
one the engine was created in. Furthermore, we get a more accurate
number now, which means we don't have to re-check when we get near the
boundary.

Also, change QV4::markChildQObjectsRecursively() to use an actual
QQueue instead of being recursive. This avoids the stack from overflowing when the stack is already almost full, and was leading to
crashes in the stackOverflow tests.

Make the stack smaller for the the tst_qquickloader::stackOverflow{,2} tests to run faster in the CI (and avoid the timeout).

Task-number: QTBUG-106875
Fixes: QTBUG-108182
Change-Id: Ia5d13caa7d072526ff2a3e1713ec7781afc154a9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-12-09 20:04:56 +01:00
Ulf Hermann 1fc939a870 QML: Faithfully convert undefined and null to string
If you do that in JS you get "undefined" and "null", respectively. Our
C++-based conversion methods should do the same. The documentation for
QJSValue also suggests that QJSValue::toFoo() should behave like
qjsvalue_cast<Foo>(x). So far QJSValue::toString() produced "undefined"
and "null" while qjsvalue_cast<String>(x) produced an empty string.

[ChangeLog][QtQml][Important Behavior Changes] qjsvalue_cast<QString>(x)
now returns "undefined" for undefined JS values, and "null" for null JS
values. This is in line with what QJSValue::toString() does, and also
what JavaScript itself would produce when stringifying such values.
Previously, qjsvalue_cast would return an empty string for both,
undefined and null JS values.

Change-Id: Ib93f4157f092ed769dca946541ffbcfbd7317d4c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-11-15 08:33:19 +01:00
Ulf Hermann fc7824c212 Drop unused includes from qv4engine.cpp
Change-Id: I9123a93e57a0288235fcbb6c521cbbbc875e2407
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-11-03 13:10:03 +01:00
Ulf Hermann a824a6f060 Recursively write back value types and sequences
Both types have functionality to write themselves back to the properties
they were loaded from on change, but so far we could not nest those
writes.

[ChangeLog][QtQml] You can now assign to properties of nested value
types and to elements of containers from QML functions. You cannot,
however, take references of such values and elements. This is in
contrast to non-nested value types and the containers themselves.
However, passing references of value types and containers around
generally leads to very confusing effects. Don't do this.

Fixes: QTBUG-99766
Change-Id: I74cb89e5c3d733b0b61e42969d617b2ecc1562f4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-19 20:32:01 +02:00
Fabian Kosmale 67bb71a051 QV4::Scope: Forbid calling alloc with qint64
Calling  alloc with a qint64 parameter is a good indicator that we got
that value from Object::getLength. In that case, the value needs to be
sanitized with safeForAllocLength.

As a consequence, we notice that method_stringify did indeed use alloc
in an usasafe way; this is now fixed.
In a few other places, variables had to be changed from unsigned to
signed int (as the conversion is now ambiguous).

An even stricter check would be to only accepd a value of (not yet
existing) "sanitized_size_t" type. However, that requires more effort,
at it would each and every call-site, and is thus left as an exercise
for later.

Pick-to: 6.4 6.2 5.15
Fixes: QTBUG-107619
Change-Id: I3bba9be1e0aea72e11ccb6c168219b4591eb8f5b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-10-13 17:27:28 +00:00
Fabian Kosmale 0e963a53c0 QV4: Avoid memory corruption in Reflect.apply
This extracts the check from Function.prototype.apply into a shared
function, and uses it in Reflect.apply, which has the same issue.

Pick-to: 6.4 6.2 5.15
Task-number: QTBUG-107619
Change-Id: I899464c86554f9bbb5270a95bbe3fe27531e9a27
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-10-13 17:27:21 +00:00
Marc Mutz 958cd3ee10 Port from container::count() and length() to size()
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8:

  auto QtContainerClass = anyOf(
      expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o),
      expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o));
  makeRule(cxxMemberCallExpr(on(QtContainerClass),
                             callee(cxxMethodDecl(hasAnyName({"count", "length"),
                                                  parameterCountIs(0))))),
           changeTo(cat(access(o, cat("size"), "()"))),
           cat("use 'size()' instead of 'count()/length()'"))

a.k.a qt-port-to-std-compatible-api with config Scope: 'Container',
with the extended set of container classes recognized.

Change-Id: Idb1f75dfe2323bd1d9e8b4d58d54f1b4b80c7ed7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-07 23:38:48 +02:00
Ulf Hermann e8e0321565 QML: Drop the "succeeded" out parameters from SequencePrototype
The success of the operation is visible from the return value in all
cases.

Change-Id: I93177785f76b8078ddd8eeb7d77143993fe80739
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-07 15:17:06 +02:00
Ulf Hermann 81faddec9c V4: Drop extra QVariant parameter from fromData()
The data needs to be copied anyway if we are going to store it in
ScarceResourceObject. We can just as well copy it from the void pointer.

Change-Id: Ic106221138b1236a6ddea20cfdb468c6fbe3e1c3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-07 15:17:02 +02:00
Ulf Hermann 7c7572259a V4: Optimize more type conversions
When loading from value type properties we left quite a few trivial
conversions on the table and went via QVariant instead. Add them.

It would be nice to unify the various places where we switch over the
trivial types, but I don't see an easy way to do so right now.

Change-Id: I9dcb29ce147a2f282e7ea6903a7af8a4b3038af6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-10-06 22:58:24 +02:00
Ulf Hermann 3195b44e1c Allow more options for creating value types from JS objects
We allow value types to be created
1. by calling Q_INVOKABLE constructors
2. by setting their values from properties of a JS object

Both have to be opted into by setting a class info. If opted into, these
options override the existing methods. When a a type can be created by
setting its properties, that implies you can also initialize it using an
invokable constructor. However, when given a JS object, the properties
method is used.

We keep this internal and undocumented for now. As the last try (the
create(QJSValue) methods and QJSValue ctors) was not that stellar, let's
first wait a bit and see if we're getting it right this time around.

Fixes: QTBUG-106480
Change-Id: I767230924afcba032d501846cc3263dad57b7bf0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-24 07:54:29 +00:00
Ulf Hermann a2db40e6c0 V4: Make ExecutionEngine::toVariant() static
Wherever we need an engine in there, we also have a managed value to get
it from. This relieves us from the requirement to drag an engine around
wherever we want to call toVariant().

Change-Id: Ib95d02b5fbf5eaa494214e337c9b700e97e5e0df
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-20 08:54:42 +02:00
Semih Yavuz 4ad35430dc QtQml: Remove unused includes in qml, first part
Drop unnecessary includes detected by clangd-iwyu.
Add new includes due to the transitive includes. Also, some of the
includes were detected as unused even if they were actually in use.
In those cases, use angular brackets instead of "" which deceives
the tool not to complain.

Affected subfolders: Debugger, Compiler, JsApi, JsRuntime, Memory,
Parser

Task-number: QTBUG-106473
Change-Id: I01d996a2a2ba31cbbc5f60f5454c8f850298f528
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-14 19:43:52 +00:00
Ulf Hermann d577b9e425 Qml: Drop unused value type provider functions
The only thing we still need is createValueType(). That is by itself
debatable, and it can be static.

Change-Id: Id092f547415c600b7d1db01f78661c287e7f4979
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-13 22:25:21 +02:00
Ulf Hermann b6cf0672e6 Allow limited extensions to globals
We can allow

a, overriding data members of globals, such as Error.name
b, adding members that don't clash with any internals
c, any manipulation of toString(), toLocaleString(), valueOf(),
   and constructor

To that effect, add a "Locked" flag to our internal classes. If that is
set, disallow changing prototypes and when defining a property, check if
it shadows any non-configurable property. Furthermore, make all
non-primitive properties that are not meant to be overridden
non-configurable and non-writable.

constructor, toString(), toLocaleString() and valueOf() are exempt
because they are explicitly meant to be overridden by users. Therefore,
we let that happen and refrain from optimizing them or triggering their
implicit invocation in optimized code.

[ChangeLog][QtQml][Important Behavior Changes] The JavaScript global
objects are not frozen anymore in a QML engine. Instead, they are
selectively locked. You can extend the objects with new members as long
as you don't shadow any existing methods, and you can change or override
data members. This also means that most methods of Object.prototype,
which was previously exempt from the freezing, cannot be changed
anymore. You can, however, change or override constructor, toString(),
toLocaleString() and valueOf() on any prototype. Those are clearly meant
to be overridden by user code.

Fixes: QTBUG-101298
Task-number: QTBUG-84341
Change-Id: Id77db971f76c8f48b18e7a93607da5f947ecfc3e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-07 16:57:25 +02:00
Ulf Hermann d3b3fef5a8 Qml: Allow const and non-const QObjectWrappers to coexist
We can access the same QObject in const and non-const contexts. Both
should be possible. Store the const objectwrapper in
m_multiplyWrappedObjects. That's somewhat slow, but const QObjects are
rather rare.

Pick-to: 6.4
Fixes: QTBUG-98479
Change-Id: I047afc121f5c29b955cd833e0a2c8299fc52b021
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-07 16:57:16 +02:00
Ulf Hermann 826b77c8cf V4: Account for the guard pages when allocating stack space
Previously we've assumed the whole allocation can be used, even though
the first and the last page are actually not usable. This makes a
difference when the size of the guard pages grows, such as on macOS,
which these days has 16k pages.

Add the extra guard page size to the amount of memory to be allocated in
order to fix the calculation.

Pick-to: 6.4 6.3 6.2 5.15
Fixes: QTBUG-93188
Change-Id: I0ebece94449da3127e9a78a19d8a22722ad8d698
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-07 16:56:42 +02:00
Ulf Hermann b297e8fccf QML: Make modules imported with registerModule() available in QML
So far, you could only use them from pure JavaScript programs. Also, fix
re-exporting parts of native modules.

Fixes: QTBUG-105901
Change-Id: I170017083284e6457b1aa0c6e606fd26227edae3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-02 15:33:31 +02:00
Ulf Hermann 4c3098ab10 V4: Do not update proto usage before engine is fully initialized
Updating the prototype usage is very expensive. We only need to do it
once there are lookups. Before the engine is fully initialized there are
no lookups.

Change-Id: Ic919a1f8955718d417e7747ea72e009d443c42fd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-08-30 12:40:23 +02:00
Ulf Hermann af1ef35fa0 JSON: Properly handle bad objects in JSON.stringify()
For objects with circular structures we generate a proper error message
and fail earlier. For objects with excessive recursion we throw a range
error rather than crashing.

This behavior is modeled after node's behavior in such circumstances.

We use the existing stack overflow detection to determine when to throw
the range error. Testing shows that on windows the limit was
insufficient. Lower it.

Pick-to: 6.2 6.3 6.4
Fixes: QTBUG-92192
Change-Id: I25dd302f65f359111e42492df3c71549c4ed7157
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-08-07 18:08:49 +00:00
Ulf Hermann 0b9fa18dfe V4: Mark InternalClass parents when running GC
We need to preserve them as they notify us about protoId related
changes. In order to avoid wasting heap space in case many properties
are added and removed from the same object, we put a mechanism in place
to rebuild the InternalClass hierarchy if many redundant transitions are
detected.

Amends commit 69d76d59ce.

Pick-to: 5.15 6.2 6.3 6.4
Fixes: QTBUG-91687
Task-number: QTBUG-58559
Change-Id: I3238931b5919ed2b98059e0b7f928334284ce7bf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-08-03 08:32:33 +02:00
Ulf Hermann 00e95e3506 V4: Allow conversion from string to QByteArray when setting bindables
We allow it everywhere else, too.

Pick-to: 6.2 6.3 6.4
Fixes: QTBUG-105044
Change-Id: I714e5d501a780310791523c5f35a87681c69b1fb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-25 20:31:21 +00:00
Thiago Macieira 268d40b9f7 Remove #include qvariant_p.h
It isn't used.

Change-Id: I3859764fed084846bcb0fffd1704497a9998d30e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-25 10:36:41 -07:00
Ulf Hermann 7e4b179430 Implement array methods for QQmlListProperty
The test revealed that the fill() method of JS arrays did not properly
range-check its parameters. Fix that, too.

[ChangeLog][QtQml][Important Behavior Changes] QQmlListProperty behaves
like a JavaScript Array now. You can use map(), reduce(), forEach() etc
on it. This also includes a slight change of behavior to the push()
method. push() now returns the new list length, and it checks the length
to not exceed UINT_MAX.

Task-number: QTBUG-58831
Fixes: QTBUG-49613
Fixes: QTBUG-99041
Change-Id: Ia64d73fb704449c280fbbc7ddcf20f4698c82e09
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2022-07-16 09:21:27 +02:00
Ulf Hermann 8056df3284 QML: Re-add the Qt namespace enums to the Qt object
They were replaced with an extension to the Qt singleton in Qt6.
However, the singleton is only available when QtQml is imported.
We can easily provide the enums using the metaobject of the Qt
namespace.

Pick-to: 6.4
Change-Id: I5f58d30c749c0cb9e531df180a5cbe75c92e1aa6
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-07-05 23:29:37 +02:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-06-11 08:05:15 +02:00