aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
Commit message (Collapse)AuthorAgeFilesLines
* QtQml: Check return field for toString()Ulf Hermann4 days1-0/+2
| | | | | | | | | | | | | In theory you could call toString() without providing space for the return value. We generally check argv[0] before writing to it. Pick-to: 6.8 6.5 Change-Id: I496eca3f428d0f8452a5bc0b1cb8ea78ee3805bb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 88dbb39e3b347e67eb0e5ee059c2545a1fbcaed9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit b7dd55a9bedbd127e63808a171aed3edf8a87803)
* QtQml: Invalidate fallback lookups after each call from AOT codeUlf Hermann2025-12-091-0/+4
| | | | | | | | | | | | Fallback property lookups are created for completely dynamic metaobjects. Anything about them may change between any two calls. Pick-to: 6.8 6.5 Fixes: QTBUG-142331 Change-Id: Ib732c37a6f27ab8105bea0eeae000af7eb9c36d7 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 9af6d2d6d0046b3c8369e15eb4791957cdc7ab7b) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Fill in the const iterator functions in the empty sequenceUlf Hermann2025-11-251-0/+11
| | | | | | | | | | | | Without these you may get an infinite sequence when trying to iterate using const iterators. Pick-to: 6.8 Task-number: QTBUG-142097 Change-Id: Iae93063b240ebe9426804197533ed7efd8e007bc Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 5d0bd461db7e67ea4233ab07aa0a879b99ea09d1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* JSRuntime: Don't immediately connect reference objectsOlivier De Cannière2025-11-203-47/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The change in a7349e6433d092398d76cafa5408753f06892cd7 reduced the number of readbacks of reference objects by using connections to set the dirty state only when necessary. Establishing connections, however, comes at a cost and this introduced a regression in the delegates_item_childrenRect QmlBench benchmark. The mitigation introduced in this patch is to delay creating the connection. When a reference object is created, it does not read or create a connection but is simply marked as dirty. Only on a subsequent read from within a different statement than the reference object's creation's statement, does a connection get created. This keeps the benefit of reducing unnecessary reads on objects that are used multiple times while not spending too much on creating connections. This brings back the benchmark to its original level of performance. The referenceObjectChainReadsBackAsRequiredBasedOnParentSignals test was changed to expect 8 reads instead of 4. Since all the accesses are part of the same statement, no connection is ever created and more reads are required than before. The referenceObjectDoesNotFetchWithoutNotifyEventDateObject test is reformatted to separate the assignment from the reads. Otherwise no connection is ever created. The referenceObjectDoesNotLeakAConnectionToTheDestroyedSignalOnANotifyBindable test can be updated to expect 0 connections. With this change, we only connect if the reference object is read again from a different statement. Amends a7349e6433d092398d76cafa5408753f06892cd7 Pick-to: 6.8 Fixes: QTBUG-140757 Change-Id: I5d02ec6266c51fbbe5f2e01405081dd5a167a833 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit f33d72c73ad6ab54ddfa2f73e721e600b7a43702) Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* JSRuntime: Extract ReferenceObject::init lambdas into functionsOlivier De Cannière2025-11-202-65/+68
| | | | | | | | Pick-to: 6.8 Change-Id: I489b515388f9aba9250bfb05687331c92578ca57 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 869bf6ffc03484ddf10ba405b7345120510d434c) Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* QtQml: Try harder to find a propertyCache for destroy() and toString()Ulf Hermann2025-11-103-11/+15
| | | | | | | | | | | | | | Those are conceptually part of the QObject property cache, even though they have no property data. So, if the object at hand does not have a property cache of itself (e.g. because its fully dynamic), look up the QObject one and use that. Fixes: QTBUG-141704 Pick-to: 6.8 6.5 Change-Id: Ia333ac8c29f3797fb4b3ff37863b7c01fae8b076 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Joshua GPBeta <studiocghibli@gmail.com> (cherry picked from commit c7191c9ef66acb897cecd49949def6c16e230240)
* QtQml: Don't delete the Qt object when clearing singletonsUlf Hermann2025-11-051-1/+12
| | | | | | | | | | | | | | | | | | | We need the object not only as singleton but also as member of the global object. If there is a QJSEngine, parent it to the engine and make it explicitly C++-owned. This way clearSingletons() won't delete it. If there is no QJSEngine, there can't be any clearSingletons(). Therefore we're safe in that case. The only known example for an ExecutionEngine without a QJSEngine is the WorkerScript case, but since ExecutionEngine is exported, it could be instantiated on its own in other Qt modules. Amends commit 9dc7a22b212c18215942b9a4bfa17bd16dd5151b. Pick-to: 6.8 Task-number: QTBUG-95788 Change-Id: I5a0aa35fadd552af208538ab2715efaff77f8f4e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit a57af3001f4388b1679482c1f1191fd312d44dac) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* V4 Date: Support more nonstandard date formatsSami Shalayel2025-10-211-1/+4
| | | | | | | | | | | | | | | | Introduce support for obsolete RFC2822 dates that has 2 digitted years, or 1-digited hours (2 instead of 02), which now should be rejected by qdatetime and instead parsed via a custom string format in ParseString(). Amends 43eaa77e8ed03153335c0002dcc8b660c39a0beb and 41a5c7b223d958bd40240aee81bb8fb96540735d. Pick-to: 6.8 Task-number: QTBUG-100377 Change-Id: I802af9edc7f755b7dba345bf60548714a7335545 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 741f4b1262f867a8c3d935eac6b5532058093ddd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Set default stack size safety margin for VxWorksKarim Pinter2025-10-212-9/+23
| | | | | | | | | | | | | | | The default safety margin for VxWorks is 1/8 of the stack size, which is read from the OS. Also adds environment variable QV4_STACK_SOFT_LIMIT, to overwrite V4 stack safety margin. These can be used to finetune the application with limited resources, also on other OSes. Task-number: QTBUG-115777 Change-Id: I82b5b02e75fae3f5d1971504d16a3dc0f1d5f3fd Pick-to: 6.9 6.8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 3192915698fa5f383f37055df854a39161852506) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* CRA review qml/jsruntimeFabian Kosmale2025-09-18156-0/+161
| | | | | | | | | | | | | | | | | | | | This relies heavily on the documented fact that we only support trusted QML/JS content, meaning most files are only significant, not critical. This also extends to the handling of qmlc files (as in compilationunitmapper), as we store them in a user owned, non-shared cache directory – so any vulnerability there would already mean that an attacker has write-priviledges on user data. An exception is ArrayBuffer, which can be used with arbitrary user data, and should create a valid QBA. Fixes: QTBUG-136970 Pick-to: 6.9 6.8 QUIP: 23 Change-Id: I22033fe6ab4acf8362a8183e25b92331d45cb32c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 22df353c14800d2e9b6d57a9a0cb9c6baa337999) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Empty SimpleArrayData vacant space when truncatingUlf Hermann2025-09-131-2/+7
| | | | | | | | | | | | | Without this we effectively soft-leak the contents of any SimpleArrayData whenever we truncate it. Only when the array was either completely dropped or re-filled would the extra objects be reclaimed. Task-number: QTBUG-139025 Pick-to: 6.9 6.8 Change-Id: I88e9dc3ea8ec57c1de71b7b5417ebcfbaa75bb61 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit e0f65fe66f0cc17eaf4c6c41d1b2f65ab2737e3c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Avoid double-wrapping when converting to QVariantListUlf Hermann2025-09-111-3/+17
| | | | | | | | | | | Amends commit 1b89c1edcae68351632c2755e5408410c2ff98e3 Fixes: QTBUG-139764 Pick-to: 6.9 6.8 Change-Id: I1488527a235d74fc0352c72b9bfb69589c2f3d93 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit ce266fbcddc48edd63c4ba8c4a6f43fb2df48153) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix JS URL behavior when setting an empty search stringAndreas Hartmetz2025-09-061-1/+7
| | | | | | | | | | | | | | | | | This code needs to bridge the following difference: In JS: "" search string -> "" "?" search string -> "?" In QUrl: null search string -> "" "" search string -> "?" Change-Id: I0b1bf64f0b251eba75b852adee5db05abe87f6fe Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 3444922a93b8087a474ef063217a2199178a551d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Mark values on the AOT-compiled stack during gcUlf Hermann2025-09-031-1/+11
| | | | | | | | | | | | Keep them in a special generated struct with virtual method that gets called from the GC for each frame. Pick-to: 6.9 6.8 Fixes: QTBUG-139059 Change-Id: I81bcbeab6531e174a5207d03f57d241461ae9ba3 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 2d016a2653c59f10a57dc1903b817f71d16d0622) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Store detached Sequence objects on the JS heapUlf Hermann2025-09-032-37/+259
| | | | | | | | | | | | | | | | | | | | | | While the Sequence is detached it is subject to the GC or unrelated C++ code deleting objects from its internals. Since it's then not the owning object's responsibility to track this anymore, we need to track it ourselves. The way to do it is to use the existing V4 objects. We don't have to store the sequence on the JS heap if it cannot store a QObject. Only lists of variants or pointers are affected. This independently fixes QTBUG-129972 for 6.8 where VariantAssociationObject does not exist, yet. This is because the detached sequence shown in that bug won't need to be written back to anymore in order to stay up to date. Pick-to: 6.9 6.8 Fixes: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: Ib469c6c65f2f96041e2ad2fd106f8cd60a182e13 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 9148ab4d8dd2fe4221aca1f1e2af1ad17835b6bd)
* QtQml: Extract method to create the inline storage for SequenceUlf Hermann2025-09-022-9/+20
| | | | | | | | | | | | | | | | | | We will get a different kind of storage in addition. The unification of the different init() methods uncovers a bug: The storage can indeed be nullptr when querying the size later. If you construct a detached sequence from a null container, there is no reason to create the internal storage. The size is evidently 0 in that case. Fix sizeInline() to tell us as much. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I33347805fc79f81c69c3191a76ff9167186b43f0 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 706e479e3b7a71f070ef6c05f00143e1842f2ec8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Avoid repeated retrieval of Heap::Sequence::storagePointer()Ulf Hermann2025-09-021-4/+5
| | | | | | | | | | | | Each of those incurs a null check. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I7bc96755629d57e1a8f0bf69e0db8de8df737665 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit c9d95333468b5aedb7d83089df40208946164c00) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Rephrase Sequence's appendInline()Ulf Hermann2025-09-021-12/+9
| | | | | | | | | | | | | | What we actually want is append default constructed elements. Doing this the natural way avoids needless complication. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I97318b0e093a76a3d67539ea0d4e28614db4879b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit a99022e243059c564a53978120cfc9bd54289034) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Heap::Sequence::isReference() where appropriateUlf Hermann2025-09-021-6/+6
| | | | | | | | | | | | | | | In order to determine whether we need to write back, conceptually we need to know whether the sequence is a reference. That happens to be the case if there is an object to write back to, but that's not how object() was meant to be used. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: Ie3e0e0318ecabd6f25d545d1198c07a0037b68fe Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 2aeafa46990c4211ece4ee173de69ec2b88577ac) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Inline Sequence's shiftInline into its ownly userUlf Hermann2025-09-021-30/+21
| | | | | | | | | | | | It gets in the way if kept seperate. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I105ee78e89ce561ec27e8badc27aa94a717ace39 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 609a06be462088044cb84999d86eb5fd2fbb0e81) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Accept Heap::Sequence in doGetIndexed()Ulf Hermann2025-09-021-8/+6
| | | | | | | | | | | | It only operates on the heap object anyway. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I7e6c232fd68893429533e1b10363ef9922a33ae7 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 64d64968956410990f4ef702a92f820a31f68a29) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Eliminate Heap::Sequence::hasData()Ulf Hermann2025-09-022-4/+4
| | | | | | | | | | | | We want to encapsulate the container as much as possible. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I7cf991ea7a3a879584066e7121c49e102ebadf08 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 2ce3b7bf0a2ee94593273ae897dd91e3cef21eba) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Inline Sequence::containerIsEqualTo into its only userUlf Hermann2025-09-022-19/+21
| | | | | | | | | | | | We don't want to expose it from Sequence's interface. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: Iae144bb8a66a24660dd8da490edb0b4bd7cdc81e Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 476ee7f5a3b1c4ac027f8dbba35e864158c57d17) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Inline containerDeleteIndexedProperty into its only userUlf Hermann2025-09-022-26/+24
| | | | | | | | | | | | We don't want to expose it from Sequence's interface. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I35c37ea1da675a83a1a8d3a4af08e4301c8cd60c Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 8953a873fa279a88a0ac45ad722ac229acf7bd24) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Inline Sequence::containerPutIndex into its only userUlf Hermann2025-09-023-46/+40
| | | | | | | | | | | | We don't want to expose it from Sequence's interface. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I12453fed0143e5e75dfc749b87b197ec328085f7 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 308305c86ad655c1194faee99f45277d22591c79) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Inline Sequence::containerGetIndexed() into its only userUlf Hermann2025-09-022-22/+20
| | | | | | | | | | | | We don't want to expose it from Sequence's interface. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: Ic001925c7fc1ae3be623e2fd7451f99d17899471 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit f3b565a1db51c3368988bdc35cac4bdf1929c3e6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Remove some methods from Sequence's public APIUlf Hermann2025-09-022-67/+50
| | | | | | | | | | | | | | | Inline at() into its only caller, move size() further up to be visible from all callers, and make them all static functions taking a Heap::Sequence. This prevents them from being called from elsewhere and improves encapsulation. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I65c724119c0df95f2d26116b3ff6ab0a4218d91f Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 28d6d704e7212c91f5aee7cdb61d809a7de85902) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Move Sequence's {load|store}Reference into the heap objectUlf Hermann2025-09-022-42/+58
| | | | | | | | | | | | | It's fine to call them from Sequence and its helper classes, but it shouldn't be called from outside. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I0bfe5d813ec8fdee6c814269df069935fe304ccd Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 48fc94ac74f33481570f5426f6ea9f3277e1cfd7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Move Sequence's length accessors into SequencePrototypeUlf Hermann2025-09-022-3/+9
| | | | | | | | | | | | We will need to befriend them. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I0d877627f2b838f2bf06a7049cd51927e13bd24d Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 1f2c87f754eb5fcedd92ab522243b4d3d953393e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Inline containerOwnPropertyKeys into its only userUlf Hermann2025-09-021-7/+2
| | | | | | | | | | Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I2062b537c1c00908b7cc86f394d95ffdf2eabbee Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit dec8d8d6ab824538c6c119949dadfb369f9d311a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Factor out Sequence's variant data creationUlf Hermann2025-09-021-10/+10
| | | | | | | | | | | | We want to use it in other places. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I720c4a71144ab634d70a1ec0115ca81b8030d083 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 68e35325165378a01bdf8ffddbe7450dbc6ebaba) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Refactor QV4::Sequence's raw container operationsUlf Hermann2025-09-014-27/+88
| | | | | | | | | | | | We want to encapsulate the container as well as possible. Pick-to: 6.9 6.8 Task-number: QTBUG-129972 Task-number: QTBUG-139025 Change-Id: I87841fbe9a9c9f1756eddc979b82ec8b90eec8e2 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 76dccf589d932f04af0faf00613a1951ac0dbd3b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Store detached VariantAssociation objects on the JS heapUlf Hermann2025-08-233-165/+247
| | | | | | | | | | | | | | While the VariantAssociation is detached it is subject to the GC or unrelated C++ code deleting objects from its internals. Since it's then not the owning object's responsibility to track this anymore, we need to track it ourselves. The way to do it is to use the existing V4 objects. Pick-to: 6.9 Task-number: QTBUG-139025 Change-Id: Ic1d5aa85171b5d91c2b9d546963268b6f09c2802 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 2547e8be4d507361527d422184d3cae205aa76ff) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Add method to generate a QVariantHash from a JS objectUlf Hermann2025-08-172-7/+20
| | | | | | | | | | | | This generalizes the QVariantMap code path. Pick-to: 6.9 6.8 Task-number: QTBUG-139025 Change-Id: Ibbdc1da974d3c166474c4bd02fb4c70d8df3e688 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit a007f6e0d36d46cee32a62876fc3c812f2cfadae) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Deduplicate enum handling in QtObject and clean up APIOlivier De Cannière2025-08-121-4/+29
| | | | | | | | | | | | | QJSValue is slow and can be avoided. Use more specific types. Also, switch to an exception based error handling instead of returning undefined. Amends 5e312953f6c41f244344bbd05a41f205a8d3f86d, found in API review Change-Id: Ie7c304a0dd76c8096e7c1f9b7cc3cfe7471649da Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 1392a245a0800c5653e73d43704a32b2716f9834)
* Harden namespacingTim Blechmann2025-08-108-16/+35
| | | | | | | | | | | | | | | | When using namespaced Qt, we need to prevent symbol clashes with symbols of the same name. * namespace some publicly visible classes * hide classes in implementation in an anonymous namespace * rename read/write to readValue/writeValue to avoid name clash with c functions. Task-number: QTBUG-138543 Change-Id: Ica77462c1f81f1e01cc60477e5b56ecfe3c1abb4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit c11d9459d87a4b981123709415e3563bdda66423) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Guard against missing NAM in XmlHttpRequestUlf Hermann2025-08-071-1/+3
| | | | | | | | | | | This can happen if you run it without a QML engine. Amends commit aa40108a2ed01338c1c0d596c1313daf43a41ded. Applies only to 6.10 since dev stores the NAM elsewhere. Change-Id: I5a4cca08328c219c69db8e9ec0ff2125ee93b680 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Allow eval() in global contextUlf Hermann2025-08-051-9/+9
| | | | | | | | | | | | We don't have to crash if we can't determine a function to query for strictness or if there is no explicit "this" object. Pick-to: 6.9 6.8 6.5 Fixes: QTBUG-136688 Change-Id: I541f2d906e10a7512d8364a9286885bd6afa4423 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit d5bab6381e2107e2d8fb305a54302ca69ba891a2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Avoid accessing garbage memory on the js stackLuca Di Sera2025-07-232-7/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When allocating an object on the JS heap the garbage collector might be run as part of the allocation, in particular as a way to possibly make space when the memory space is starting to get filled up. When the garbage collector runs, it is possible, as part of its normal processing, that it will access the JS stack, and try to interact with the objects that are stored on it. In particular, while collecting from the JS stack, the garbage collector will need to mark all Managed objects that are found on it. When allocating on the JS stack it is possible that the allocation and the initialization of the allocated memory are performed in separate steps. When this is so, it is possible for the allocated element on the stack to represent garbage memory in between being allocated and being initialized. Since the garbage collector can inspect all elements on the stack as part of its processing, it is possible for it to inspect an element that represents garbage memory if it runs in between the allocation and initialization of that stack element. Furthermore, since each allocation might run the garbage collector, then any allocation in between the allocation and initialization of such a stack element can access garbage memory. In particular, if the garbage memory represents a pointer to a previously existing Managed object that was swept, the garbage collector might try to mark an object that shouldn't be marked. There are a few cases of this currently in the code-base. While instantiating a QML file, `QQmlObjectCreator` keeps track of objects that are created in the process, to avoid premature collection. As part of this, `ObjectInCreationGCAnchoList::trackObject` will be called, in turn allocating on an element on the js stack and then initializing it separately by the creation of `QObjectWrapper`. The creation of a `QObjectWrapper` generally allocates, such that it can incur into the above problem. As part of dealing with the JS spread operator, in particular when processing the spread element, we juggle with multiple allocation of uninitialized elements on the js stack. During this processing multiple part of the code can allocate. For example, the spread element is handled through the use of an iterator that, during its creation, might allocate as during the creation process we might convert the spread argument to object so that the iterator can deal with it, which would be the case for a spread argument that is a string. When allocating an element on the js stack that is bound to a certain scope, we sometime allow a conversion to be performed on the original element. This conversion routine might allocate, and it does do so for the currently existing conversion to a String and to an Object. The conversion routine is called after an uninitialized element is pushed on the stack, and can thus incur into the above issue. To fix the issue, an additional method was added, `construct`, that ensures that allocation and initialization happen sequentially with no allocation in-between, using an initialization value that is passed as an argument. The new method was applied to the code affected by the bug, in practice, reordering the operations in the affected cases such that the bug-producing allocations happens before the allocation on the stack such as to avoid the bug while keeping the same semantics. An exception was taken for the handling of the spread argument, which has a more complex control flow, where the solution that was used is to initialize the memory to the empty value as part of the allocation. A series of test cases showing an example of the issues were added to `tst_qv4mm`. The tests make use of the fact that we assert when we find a Managed object on the js stack that is not in use, as that is a logical error for the garbage collector, to observe the issue and are thus skipped when assertions are not enabled. Change-Id: Id478e16ee22e20e77d01fdfae9a0269d6d709892 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 64b3748b39db6241a914da8c358d245061977409) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Expose XMLHttpRequest to qmltypesFabian Kosmale2025-07-222-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In QML, one can use XMLHttpRequest. Not so with a plain JS engine. The reason for that lies in the fact that a JS engine did not have any network access, because all network functionality was in the type loader, and the type loader was coupled to the QV4::Engine. This has changed in d2bc4a4330254c0c68a0ade51b59a71c4b67b470, but we stil don't expose XMLHttpRequest to a plain QJSEngine. Nevertheless, it conceptually lives in the global object, and we need to collect information about it to enable code completion and linting. Consequently, expose a function in QV4::Engine, which allows us to manually trigger the registration, and call it in qmljsrootgen. Going forward, we should arguably have a QJSEngine::Extension for XMLHttpReuqest, after which we could remove the hack. Note that as before, qmljsrootgen prints a few warnings, because we call functions in contexts in which they must not be called. As before, we ignore this for now. As a side-effect, this adds a few more entries to the qmltypes file for new entries on the global Qt object. Task-number: QTBUG-137075 Change-Id: I21e9d62bf075e8d4356db8f357502feb927717e7 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 8effdd97d967fbeec4f143885dcd671516383740) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Avoid infinite recursion in Array.joinFabian Kosmale2025-06-281-0/+1
| | | | | | | | | | | | | | | So far, self-referencing arrays can lead to infinite recursion in Array.join. The standard allows us to throw an exception in this case, just like we already do in ObjectPrototype.toString(). This is not what browsers do, but arguably they are diverging from the spec. Pick-to: 6.9 6.8 6.5 Fixes: QTBUG-124157 Change-Id: Iac241a90ba7e583e53f52ec635add7b5cf05b200 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit b1bdad8096a45098d6ac668142493cccfd019579) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Mark QML's JSON parser as criticalFabian Kosmale2025-06-251-0/+1
| | | | | | | | | | | | | We're doing fully custom parsing here, and external JSON must not cause security issues. Pick-to: 6.9 6.8 QUIP: 23 Task-number: QTBUG-136970 Change-Id: I43f8280a31ebc170382485e6f5f3e7c06aa7db1a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit c9f9e70da7e7e11394a3daeb1bc80fa8d41c9f0d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Allow access to base object members from VariantAssociationObjectUlf Hermann2025-06-251-1/+9
| | | | | | | | | Pick-to: 6.9 Fixes: QTBUG-137328 Change-Id: I6bb58dc58a8e29eed4d73b51104deb4d58f4cec0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit e0620d4d67a6167b28fcf2c9de66f03aa664eea5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtQml: Do not crash when registering native modules on QQmlEngineUlf Hermann2025-06-121-2/+3
| | | | | | | | | | | | | | We need to tell the type loader that this is an ECMAScript module since it cannot determine it from the file name. Amends commit dc60c305a20d518012d4f034c4fa2a7395ebf31f Pick-to: 6.9 6.8 Change-Id: Ie91bce86a08a81ff3df6c11d016308e3e380f15f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 5137c85f1b187a9110976c2f7f807a18cea073e6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Qml: Warn about using enums as type annotations in functionsOlivier De Cannière2025-06-111-2/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The warning emitted when calling functions with parameters type annotated with enums does not communicate what's wrong or how to fix it: "1 should be coerced to void because the function called is insufficiently annotated. The original value is retained. This will change in a future version of Qt." Until we support a proper representation of enums in the type system, all we can do is warn the user that this does not work. Add another warning that fires once when the function is constructed that has a better description of what is going wrong. This should provide the user with the info to solve the issue unlike the original warning. This does mean that we warn more for the same issue but it should still be beneficial overall. Task-number: QTBUG-135255 Pick-to: 6.9 6.8 6.5 Change-Id: Icd8f8d80c6a4b9bd2b33c660394b9cf5a228a346 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit f64ba5dec875927163bb917597bac51540eb4097) Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* gc: Assume less if hasConstWrapper is setFabian Kosmale2025-06-101-16/+14
| | | | | | | | | | | | | | | | | | | | | | | QQmlData is attached to a QObject, and consequently can't be used to track engine local state. Whether a _given_ engine has a const wrapper for a QObject is an example of such local state. False assumptions based on hasConstWrapper in turn led to asserts when using multiple engines. Fix this by changing the meaning of hasConstWrapper: It now only indicates that at some point, a given engine had created a const wrapper. If that flag is not set, we know that we can skip lookups in m_multiplyWrappedQObjects. If it is set, we can't assume anything, and have to consult our engines m_multiplyWrappedQObjects to truly know whether we have a const wrapper or not. Pick-to: 6.9 6.8 Change-Id: Id26823bdc942b227c991571334f45f45b8b109c3 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 5bec6a1d0c3d5f647a2a5c9375f2bf5e9647c24b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* VariantAssociationObject: mark own member during gcFabian Kosmale2025-06-041-0/+2
| | | | | | | | | | | | We were missing the DECLARE_MARKOBJECTS macro, which could lead to heap corruption if the mapping was actually in use. Pick-to: 6.9 Fixes: QTBUG-137350 Change-Id: Idd9184a3a3c35faa7caf35d0e3ac8c901f99afb7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 217439c2d13b67e238cbf7c6bb2bc6f3b71fe547) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Qml: Allow accessing unscoped enums values as <Component>.<Enum>.<Key>Olivier De Cannière2025-05-311-5/+5
| | | | | | | | | | [ChangeLog][QML] It is now possible to access unscoped enum values in a scoped way as <component name>.<enum name>.<key>. Previously, it was only possible to access them in an unscoped way. Task-number: QTBUG-116513 Change-Id: Iff56cd3365516215e1e195a147fae66ee17d39e3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Guard against missing root property cachesUlf Hermann2025-05-222-16/+6
| | | | | | | | | | | | | | A compilation unit can be created from a script, in which case there is no property cache. We shouldn't crash then. Amends commit c1bd8ee91fd1462235d4bccbcf5286864d0fcbf7 Pick-to: 6.9 6.8 Fixes: QTBUG-137072 Change-Id: Ic10dfd7a640067639894f885496dfa13719b4bf5 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Waqar Ahmed <waqar.ahmed@kdab.com>
* QtQml: Remove object/binding/parser status counts from CUsUlf Hermann2025-05-201-4/+0
| | | | | | | | | | | | | | Calculating those is a rather complex affair, and unlikely to pay off. Previously they were used to pre-allocate space in the object creator. We use standard containers with standard allocation strategies everywhere else. If this turns out to be an actual problem, we could record the actual numbers when we create a component and record those in the ExecutableCompilationUnit for next time. Task-number: QTBUG-135286 Change-Id: Ia44bbc9c49cbfb638f5d4bbbb345c48124e4fb09 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>