aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlengine.cpp
Commit message (Collapse)AuthorAgeFilesLines
* V4: Slim down FunctionObjectUlf Hermann13 days1-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Most FunctionObjects do not actually need their custom jsCall members. They will only call the functions from the vtable anyway. FunctionObject can therefore be split into a static and a dynamic variant. Only the dyanmic variant needs to carry (and invoke) the extra pointer. The jsCallWithMetaTypes pointer is completely pointless because none of the dynamic functions actually implement it. Furthermore, the QV4::Function and QV4::ExecutionContext pointers in FunctionObject are only needed by actual JavaScript functions. The builtins that like to be dynamic functions never need them. Therefore, split out another class for this. In the generic FunctionObject, we need the capability to decide at run time whether the function shall be a constructor or not. Add a flag to replace the check for jsCallAsConstructor. Also, where we can, avoid the pessimization of checking whether a function is a constructor before trying to call it as constructor. Rather have the default implementation throw the exception. As a side effect, for most functions we don't need an ExecutionContext anymore. The engine is enough. Task-number: QTBUG-124662 Change-Id: Iac657fa71288dd6ec230a33de2986ba3bcf4628c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Clear context objects more thoroughly on destructionUlf Hermann2024-02-011-15/+6
| | | | | | | | | | | | The same object can be the context object of a hierarchy of contexts. So far we would only clear one of them, leaving dangling pointers in the others. Clear all the contexts. Pick-to: 6.7 6.6 6.5 6.2 5.15 Fixes: QTBUG-119326 Change-Id: I509f257672813866e3736b51f430f1243a8577f0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Use CompiledData::CompilationUnit in more placesUlf Hermann2024-01-201-4/+13
| | | | | | | | | | We rarely actually need the executable CU, and where we need it, we can dynamically create or retrieve it from the engine. To that end, store all the CUs in the same container in the engine. Change-Id: I0b786048c578ac4f41ae4aee601da850fa400f2e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Move dependentScripts into base CUUlf Hermann2024-01-181-6/+6
| | | | | Change-Id: Ia332a691a4a5f04fcca50eb1c3e2018f8368dbe6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Move type name cache into base CUUlf Hermann2024-01-181-1/+1
| | | | | Change-Id: Ie3504f16b34859cdef72f8138e6058dcc2d1f58f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Move BindingPropertyData into the base CUUlf Hermann2024-01-131-2/+3
| | | | | Change-Id: I2edcb2c324919a1131ae490bee9c9b1140097b09 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Clear stale compilation units more thoroughlyUlf Hermann2024-01-111-0/+10
| | | | | | | | | There are various places where we can still hold references. Clean them up when asked to do so. Also, free unused types and caches outside the type loader mutex, and only once on engine shutdown. Change-Id: Iae77cd6f50ad847d29a7eae4ac5c7c1c2524065d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Remove QQmlTypeLoader from QQmlImportUlf Hermann2024-01-111-3/+2
| | | | | | | | | The type loader belongs to the engine and we must not store it in engine-independent data structures. We do want the import cache to be stored in the type registry, though (in a separate change). Change-Id: I2828f5098b27bf1fc96852fc2bd160db44b109e7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Always link executable CU on creationUlf Hermann2024-01-101-2/+3
| | | | | | | | | | | | | | | We don't want floating unlinked executable CUs. They should always be tied to an engine, and the engine should not change. This gives us one definite point where to register them with the engine (to be done in subsequent change). Unfortunately, due to the refcounting, we need to remove the engine from any still-referenced CUs when the engine itself is destructed. We will be able to drop the refcounting and make the engine fully own its executable CUs once we can hold base CUs in most places. Change-Id: I9a53e83d5c4746c2b2bca896b51baa4fe7fee757 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Doc: Fix linking issues and missing QDoc commandsTopi Reinio2024-01-061-1/+1
| | | | | | | | | | | | | | | Fix multiple incorrect \l (link) command arguments that were not captured by documentation testing in CI. Add missing \endqml and \endcode commands to code snippets. Convert \sa commands that are meant to be related to specific \section commands into manual 'See also' paragraphs. Otherwise, they are listed at the bottom of the page. Pick-to: 6.7 Change-Id: Icf2a97f63b8b8cdec2d9398448d28759dabdb06b Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
* Long live incremental garbage collection in QML!Fabian Kosmale2023-12-201-0/+1
| | | | | | | | | | | | | | | | | The design of the garbage collector is described in src/qml/memory/design.md. The gc and gcdone test helpers are adjusted to drive the gc to completion, even when in incremental mode. Parts of tst_qv4mm and tst_qqmlqt need to run with the incremental gc disabled, as they call gc inside QML and assumes that the GC finishes before returning. Initial-patch-by: Rafal Chomentowski <rafal.chomentowski@ge.com> Task-number: QTBUG-119274 Change-Id: I1d94f41bc7a434fad67de0fd46454b6db285f2eb Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Make builtins an actual moduleUlf Hermann2023-11-241-83/+4
| | | | | | | | | | | | | | | | | | | | | | This way we can eventually use the metatypes generated by the builtins to validate other module using qmltyperegistrar, and throw informed warnings if types are missing. qmltyperegistrar automatically picks up the metatypes of any library linked into a target. This means it always picks up the builtins metatypes now when QtQml is linked in. We now have to check more closely whether an object binding is actually a group property. QVariant now has a value type metaobject and does not pass as "unknown thing" anymore. We also have to move the QML_FOREIGN macros to QQmlIntegration since we want QML_FOREIGN to declare the builtins but we don't want to depend on QtQml. Task-number: QTBUG-101143 Change-Id: I9f1a2713797291b6624aef0ade599d19e0766907 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
* QtQml: Have QtQml.Base formally import QMLUlf Hermann2023-11-171-3/+8
| | | | | | | | | | | | This way we don't have to register QtObject and Component twice. The QML_NAMED_ELEMENT etc. will return when we make the builtins a proper module. The imperative registration is a stop gap measure. Task-number: QTBUG-101143 Change-Id: I726aa77156b31aa624ac44d30e180ace6cb9d790 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QQmlEngine: Fix documentationUlf Hermann2023-10-201-21/+8
| | | | | | | | | | The documentation should not recommend passing data via the context. Rather, it should at least mention what a QQmlEngine actually is. Pick-to: 6.6 6.5 Change-Id: Iee4faba7bb4e3bbbe385474badcb9781688f7147 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QtQml: Key singletons by singleton instance infoUlf Hermann2023-08-301-9/+8
| | | | | | | | | | | | | | | | | | | | We can keep the singleton instance info the same across multiple types created in a single registration call. The result is that we only get one singleton instance per engine, rather than separate ones for each version. If you invoke qmlRegisterSingletonType separately, you still get separate instances, though. [ChangeLog][QtQml][Important Behavior Changes] The QML engine will now refrain from creating separate instances of a singleton type for each version it is registered for if the singleton is registered declaratively (using QML_SINGLETON). The behavior of procedurally registered singletons (using the qmlRegisterSingletonType() family of functions) remains the same: For each registration call, a separate singleton instance is created. Task-number: QTBUG-116432 Change-Id: Ic8a5de0f88ef530670cfd81b192201a8ab49b2f7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Make notify list thread safeUlf Hermann2023-08-101-29/+56
| | | | | | | | | | | | | | | We keep the notifyList itself alive until the QQmlData itself is deleted. This way any isSignalConnected() called while an intermediate dtor runs can safely access it. We use atomics to make the concurrent access to the pointer and the connection mask defined behavior. However, we never need anything but relaxed semantics when accessing it. Pick-to: 5.15 6.2 6.5 6.6 Fixes: QTBUG-105090 Change-Id: I82537be86e5cc33c2a3d76ec639fcbac87eb45ad Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtQml: Clean up QQmlData ctorUlf Hermann2023-07-101-5/+2
| | | | | | | | | | | | Initialize the "dummy" member even though we never use it. Static analyzers complain about it and we may appreciate it having a defined value in the future. Also, initialize other members inline where possible. Coverity-Id: 415867 Change-Id: Ie428eb3294d6363afe9d7ab2d2bed6e52df0b304 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* LoadHelper: Output load errorsFriedemann Kleint2023-06-281-1/+3
| | | | | | | | | | Loading currently fails silently for certain errors in qmldir files (for example, duplicated entries). Output the errors for tracing. Pick-to: 6.6 6.5 Change-Id: I1bd69d1cf895776c020a3ae16c995bbd6b63dae4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* LoadHelper: Avoid unnecessary string allocationsFriedemann Kleint2023-06-281-2/+2
| | | | | | Pick-to: 6.6 6.5 Change-Id: I71d10f447dc12a2a65a883764a015bb854f0453f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Do not leak memory if QQmlData is manipulated from ctorUlf Hermann2023-06-261-3/+3
| | | | | | | | | | | | | | | This creates another QQmlData object on the heap, which is rather wasteful. However, we cannot really avoid it since it's all too easy to trigger an operation like this. If it happens, use the QQmlData it has created, and ignore the memory we've allocated inline. While we're at it, make the memory ownership a required argument to the ctor. Pick-to: 6.5 6.6 Fixes: QTBUG-114186 Change-Id: I0568768c9ec13c94db79bb162c9eeb76f75f2a55 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Doc: Small improvements for ~QQmlEngine, ~QJSEngineKai Köhne2023-06-201-1/+1
| | | | | | Pick-to: 6.5 6.6 Change-Id: I31bfa44ee2a026c2ab0dbdbbd9c349937f2662b2 Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
* Doc: Fix ambiguous linkAndreas Eliasson2023-06-071-1/+2
| | | | | | | | | | | Using square brackets to disambiguate a link doesn't seem to work with the \sa command. For now, re-write to use \l to make sure the link goes to where it's supposed to. Task-number: QTBUG-114073 Pick-to: 6.6 6.5 Change-Id: Id23844df752c30a8d02a362e91632ad2339ad8e8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Register all builtinsUlf Hermann2023-05-221-7/+99
| | | | | | | | | | | | We need run time access to the QQmlType instances of all the builtins in order to properly coerce types without special casing everything all the time. Since we can now have QML types without metaobjects, we need to check for the metaobject in a few places where we didn't need to check before. Change-Id: Ib22cbb12c60ebdce4897c3f3338851e8b925926f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlData: Implement markAsDeleted without recursionFabian Kosmale2023-04-281-5/+9
| | | | | | | | | | | | | | | | | | | While a normal QML scene should not feature extremely deep object trees, one can still encounter them in some test cases. Those test cases might then run out of (C++) stack space with the previous recursive version of markAsDeleted. Thus, we change the implementation to use an explicit workqueue instead of relying on recursion. This changes the visitation order, but code is not supposed to rely on the order of Component.onDestroyed calls anyway (and we keep at least the order in so far that the parent emits the "signal" before it's children. Pick-to: 6.5 Change-Id: I93b30cc26b984d1a21cff92df1dd68cd45e67477 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QQmlEngine: Introduce markCurrentFunctionAsTranslationBindingFabian Kosmale2023-04-241-0/+39
| | | | | | | | | | | | | | | The general recommendation to handle language changes in QML is to handle the LanguageChange event. However, if one is willing to tie themselves to the QQmlEngine, we can offer a way to ensure that calling a function will result in a traslation binding. This might also be helpful for anyone implementing a translation system different from Qt's, e.g. KDE's i18n. Fixes: QTBUG-102393 Change-Id: Id4d7a401e0be9d65e1769c8471b26689f44bf66a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlEngine: Improve import path method documentationFabian Kosmale2023-03-021-7/+8
| | | | | | | | | | | | Instead of (partially) repeating the defaults listed in "QML Import Path", link to that section. Moreover, warn that setImportPath doesn't preserve the default paths. Task-number: QTBUG-109799 Pick-to: 6.5 6.5.0 6.2 Change-Id: I6c2acb6efd1bd0984b3b540a75c7bced44127050 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* loadFromModule: Properly handle QML only modulesFabian Kosmale2023-02-021-6/+21
| | | | | | | | | | | | | | | QQmlMetaType::typeModule only returns a sensible result for modules with some C++ integration. That is not the case for a pure QML module (qmldir put into an import path). Detect the missing module case by instead checking whether addImport failed to handle the module (either returning false, or returning true but with unresolved imports). Fixes: QTBUG-110882 Pick-to: 6.5 Change-Id: I7b25e225e1a34ec91f7ce4d9f4a182a24168ba47 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Doc: Document QQmlEngine::offlineStoragePathChanged separatelyKai Köhne2023-01-311-0/+7
| | | | | | | | | The signal is new in Qt 6.5, so better list it separately (with \since tag). Pick-to: 6.5 Change-Id: If83cc1d48f0fdeafbd6a67691170932ec9ea5e04 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Document that internal contexts are read-onlyUlf Hermann2023-01-111-4/+5
| | | | | | | Pick-to: 6.5 Fixes: QTBUG-69075 Change-Id: Ia671a74ede08f71e73344e2a4fe135cda6a95a64 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QQmlEngine: Add module + type based singletonInstance overloadFabian Kosmale2022-12-081-0/+72
| | | | | | | | | This makes it consistent with QQmlComponent::loadFromModule. It also avoids the issue the qmlTypeId does currently only work if the module has been imported; though that will be fixed in a separate commit. Change-Id: Id284f7ed2de7af461b782c5b5d71d9bfc0039844 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QML: Monkey-patch thread safety issue with dynamic metaobjectsUlf Hermann2022-11-241-2/+13
| | | | | | | | | | | | | | | | Not deleting the dynamic metaobject should at least prevent the crashes in the CI that have appeared lately. We can still race for the validity flag this way. While this is still technically UB, in practice it will work. We may yet find a better solution to this. Amends commit 3ba1496a65a06b38ee324b5ac10ffec98b22b0c1. Change-Id: I512051953bdbb832ced9ef26d1d3e6ea2ff21226 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Clean up VME and interceptor metaobjects on destructionVolker Hilsheimer2022-11-221-1/+8
| | | | | | | | | | | | | The dynamically created meta object is stored in the QObject private until the very end of the object's destruction. It takes precedence in the moc-generated QObject::metaObject implementation, essentially side-tracking virtual dispatch during object destruction. If we don't clean it up this allows qobject_cast'ing down the class tree when the object is already partially destroyed, even though it shouldn't. Done-with: Ulf Hermann <ulf.hermann@qt.io> Change-Id: I64f6533747bb99b977702c050e5dc78a7c6428a5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Do not parent QQmlGadgetPtrWrapper instances to the engineUlf Hermann2022-11-221-0/+1
| | | | | | | | | | children of the QQmlEngine can be detected by user code or by the QML debugger. QQmlGadgetPtrWrapper is a particularly dangerous thing to stumble upon. Task-number: QTBUG-108704 Change-Id: I502419e03571f176b1223386635c97f5f9982549 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-071-7/+7
| | | | | | | | | | | | | | | | | | | | 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>
* QQmlEngine: add signal for offlineStoragePathFabian Kosmale2022-10-041-1/+6
| | | | | | | | | | | That might be helpful if someone wishes to heed the advise in the documentation, and to always call mkdir (in a slot) on offlineStoragePath change). Change-Id: I3970b2ff9104f4966fddf67b02754e123a87c6cd Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Remove unused includes in qml, final partSemih Yavuz2022-09-141-10/+4
| | | | | | | | | | | | | | 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: JsRuntime, Qml Fixes: QTBUG-106473 Change-Id: I483da15d42a8e3ce6cd3b654909665fff3075d6b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Allow const and non-const QObjectWrappers to coexistUlf Hermann2022-09-071-1/+1
| | | | | | | | | | | | | 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>
* Use SPDX license identifiersLucie Gérard2022-06-111-38/+2
| | | | | | | | | | | | 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>
* Fix race condition on QQmlEnginePrivate::qml_debugging_enabledMarc Mutz2022-05-311-1/+1
| | | | | | | | | | | | | C++11 allows static dynamic initialization from different TUs to happen concurrently, which means the QQmlDebuggingEnabler ctor must be re-entrant and synchronized with other users of qml_debugging_enabled. Thankfully, this is just a flag, so the fix is to simply make it atomic<> and use relaxed loads and stores on it. Pick-to: 6.3 6.2 5.15 Change-Id: I0305ab55be86a0e286016a3d1d97ee9bc0e28070 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Port QV4::CompiledData::Binding to new special integer bitfieldUlf Hermann2022-05-111-1/+1
| | | | | | | Pick-to: 5.15 6.2 6.3 Task-number: QTBUG-99545 Change-Id: I9f8bc5fa45c61f77ee95b055a3d8de001da8f8c5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: includemocsMarc Mutz2022-04-291-0/+2
| | | | | | | | | | | | Including moc files directly into their classes' TU tends to improve codegen and enables extended compiler warnings, e.g. about unused private functions or fields. Pick-to: 6.3 6.2 5.15 Task-number: QTBUG-102948 Change-Id: Ie39c60a19ba562affe6bd52ba68b38db95298cf3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Make QQmlEngine resolve closures when executing runtime functionsAndrei Golubev2022-04-271-3/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Use const QQmlPropertyCache wherever possibleUlf Hermann2022-03-141-1/+1
| | | | | | | | We're not supposed to modify property caches after they've been created. Task-number: QTBUG-73271 Change-Id: I0ab8ed6750508fa4e28931995142f56cd5fa3061 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix deprecated uses of QScopedPointerMårten Nordheim2022-03-101-4/+4
| | | | | | | | Which is uses of take() and swap(). And replace it with std::unique_ptr. Change-Id: I2580383c1d2af0ba6103a66f034235905e0988ac Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Space optimize QQmlStrongJSQObjectReferenceFabian Kosmale2022-02-211-0/+2
| | | | | | | | | | We can get rid of the boolean member by reusing the objectDestroyed function pointer. Change-Id: Idb9e4d0ddfb04b109126378a6c18799018c74785 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Cleanup QQmlGuard and related classesFabian Kosmale2022-02-211-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An investigation of uses of QQmlGuard (+ related classes) yielded the following results: - objectDestroyed is the only virtual method of QQmlGuard (besides the dtor) - we never have an owning pointer of type QQmlGuard * to one of its subclasess => Therefore, we can replace the use of virtual methods with a function pointer, which avoids the issue of duplicated vtables. None of the objectDestroyed actually cares about the object we pass to them, so we can leave it out in the function pointer. As everything is private API, we could easily bring it back if the need arises in the future. By moving the function pointer into QQmlGuardImpl we also avoid UB in qqmlengine.cpp, which cast any QQmlGuardImpl pointer to QQmlGuard<QObject>. This, however, is wrong as QQmlGuard<T> does not inherit from QQmlGuard<QObject>, even if T inherits from QObject. As we now can sipmly access the pointer from QQmlGuardImpl, we can side-step any casting woes alltogether. Moreover, we use this opportunity to let QQmlStrongJSObjectReference drectly inherit from QQmlGuardImpl. This requires duplicating some of the QQmlGuard API, but on the other hand avoids busy-work to hide no longer desired API. Unfortunately, we can no longer inherit privately from QQmlGuardImpl, as otherwise the various subclasses can no longer cast the QQmlGuardImpl we pass to them to their own type in the objectDestroyed(Impl) methods. QQmlGuard(Impl) still could benefit from a move ctor/assignment operator; those will be added in a later commit. Task-number: QTBUG-45582 Change-Id: I995148a428e541ced5c79b3a61d91c4bb7e03308 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Clean up sequence registrations for value typesUlf Hermann2022-02-111-8/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We want to be able to construct a meaningful list type by surrounding the internal name of the type with QList<>. Usually this works because of the way we auto-register sequential containers for types. Only for the builtins we need to do some special casing. That special casing should happen in the builtins, not in QtQml, though. The generic QList<foo> sequence type is implicitly given for any value type foo these days. There is no need to mention it in .qmltypes. QtQml retains some extra container declarations that are not straight QList<foo> for a value type foo. Everything that's registered by the value type registration anyway is dropped. We keep the aliases QStringList and QVariantList in the builtins because they are really common. Since we now register QVariantList the way it's mandated by the builtins, we also have to handle it correctly in qv4sequenceobject.cpp. In particular, we need to append variants as-is rather than poking into them. As QStringList is an additional builtin now, we need to teach the type resolver about it. Change-Id: I0dfb5b780b27250f36f6886bc4e0926a03c114b4 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Avoid ping-pong between plain pointers and QQmlRefPointerUlf Hermann2022-01-251-7/+7
| | | | | | | | | | | | | | | We want to deal in QQmlRefPointer as much as possible. In particular, assigning nullptr to a QQmlRefPointer triggers the creation of an empty QQmlRefPointer and the assignment of that one. Provide a reset() method to do this in a cleaner way. In turn, make QQmlGuardedContextData::reset() private. It's really dangerous and should not be called from outside. setContextData() is safer but may do additional work. The only place from where reset() was previously called in its public capacity is probably dead code, though. Change-Id: Idb72e255dbfad6e5dd963dc76d719bb9edc10471 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Move propertyCache- and metaObject-related functions into QQmlMetaTypeUlf Hermann2022-01-181-85/+0
| | | | | | | | | | | | That's where the data resides. This allows us to lock the mutex only once for all those methods, and it makes a large number of engine pointers unnecessary. Finally, we can now find the element type of a QQmlListProperty without supplying an engine. Change-Id: If1ae8eafe8762a112d1ca06f9c92ab8a727d1bda Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Move QJSEnginePrivate::cache() to QQmlMetaTypeUlf Hermann2022-01-181-3/+3
| | | | | | | | | It is just in line with the other propertyCache() methods, and should be treated the same way. The comment made no sense anymore. This allows us to drop more engine pointers. Change-Id: I2e9b479b555c7f771b619e4693d59cbfcf244df6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>