aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqml.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* 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>
* Support querying indirect extensions for a given objectAndrei Golubev2022-05-121-2/+7
| | | | | | | | | | | | | | Introduce a private version of qmlExtendedObject() that returns an index-based extension (where 0 represents an extension on the leaf type and N represents a (N - 1)th base type's extension) Teach QQmlProxyMetaObject to distinguish different extension proxies. Its custom metaCall can now query up to 128 extensions (should be enough for the user needs) Change-Id: I5520a1e84501f1f9fe6a8e77d8269009a12c255c Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: In captureLookup(), return false if it failsUlf Hermann2022-03-251-2/+1
| | | | | | | | | | | | | Otherwise the AOT-compiled code will assume the capture succeeded and fail to get notified when the value changes. This went unnoticed because it only applies to direct mode, the tests for which live in a separate repository. Fixes: QTBUG-102022 Change-Id: I23d94ccbef5b00c4c6837c88970a4e40b05a912a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit d52e1d609516d0573bea1acf2d73d811ff25f0e9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Add public API for retrieving the extension objectUlf Hermann2022-03-231-0/+19
| | | | | | Change-Id: I28bc1c177cb78d85d844c7a5cd5b6710db8fd65d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QmlCompiler: Fix a number of warts regarding type lookupUlf Hermann2022-03-231-0/+2
| | | | | | | | | | | There was a condition missing in qqml.cpp making most type lookups crash right away. Furthermore, we need to generate code for type lookups we do need. Finally, the shadow check should skip instructions we don't need anymore. Shadowing in optimized-out code is not very interesting. Pick-to: 6.2 6.3 6.3.0 Change-Id: I34e9de7686528b39a35e59c616e4e28b32a6e031 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Make most QQmlPropertyData constUlf Hermann2022-03-141-1/+1
| | | | | | | You really should not mess with that after creating the property cache. Change-Id: I070200772475bb67f539dbbd85a298020b14ca79 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Unify treatment of invalid revisions on registrationUlf Hermann2022-03-051-10/+12
| | | | | | | | | | | | Revisions before QML_ADDED_IN_VERSION and revisions after QML_REMOVED_IN_VERSION should both result in anonymous types. This way, you can then derive from the type in question and expose the derived type in a different set of versions. Pick-to: 6.3 Change-Id: Ia59258047fc242c809c27525bb75fd2797fe5aab Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Handle dynamic meta objects in AOT lookupsUlf Hermann2022-03-031-78/+254
| | | | | | | | | | | | If we are dealing with dynamic metaobjects, the QML engine may not create property caches. We cannot see this at compile time. Therefore, we need to establish a fallback infrastructure that does the same operations on plain QMetaObject. Pick-to: 6.2 6.3 Fixes: QTBUG-101349 Change-Id: I8c936fc077b0018df71196620b6987825253cb39 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow named lists of value typesUlf Hermann2022-01-281-52/+64
| | | | | | | | | | | | | | | | | | | | | | | | We register QList<T> as sequential container type for any value type T we get. This way we can always find a type to use for list<t> with t being a value type. The metatypes are shuffled around so that we have an easier time associating a type with its list and vice versa. As QQmlPropertyData's isQList flag denotes both QQmlListProperty<T> and QList<T> now, we need to use QMetaType::IsQmlList more often. Conversely, any name given to extra sequential containers registered via QML_SEQUENTIAL_CONTAINER is explicitly ignored now. As you can do list<foo> for any type foo now, there is not much of a point in having further named container registrations for the same type. It would just make things more complicated. Mind that the name had already been ignored before, just not explicitly. [ChangeLog][QtQml] You can now use lists of value types in QML. For example a property of type list<int> will hold a list of integers. Task-number: QTBUG-82443 Change-Id: I7bee61cee3963dae5d231bf59f70b8012984371d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Move propertyCache- and metaObject-related functions into QQmlMetaTypeUlf Hermann2022-01-181-7/+4
| | | | | | | | | | | | 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-2/+1
| | | | | | | | | 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>
* Do not copy lookupsUlf Hermann2021-12-161-7/+7
| | | | | | | | | | | | | It leads to data corruption. Also, be more careful about releasing the property cache. We can only do that if the qobjectlookup member of the union is active. Unfortunately we have to do a number of checks now, to make sure it is. In order to still keep the checks inline, we move some functions around. Pick-to: 6.2 6.3 Fixes: QTBUG-99211 Change-Id: If6dd879e67b172e1a9035e83fbfacbe73c6c7476 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSAotContext: flushPendingBinding() before capturing a propertyUlf Hermann2021-12-101-5/+12
| | | | | | | | This avoids duplicate evaluation and binding loops. Pick-to: 6.2 Change-Id: I5eba42d9dca0782dd964bd64c088c2e158faa9b3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4 Lookup: Do not leak property cachesUlf Hermann2021-12-091-6/+1
| | | | | | | | | | | | | | | | | | | | | | When a function that performs a lookup is called recursively via the flushing of initial bindings, we may initialize the same lookup twice. In that case, make sure to release the old property cache before overwriting it. We might suspect that this can only re-assign the same property cache again and therefore we can skip the whole operation if it has been done before. Yet, considering the dynamic nature of QML, it's very hard to guarantee this. There are cases where we have to revert lookups because the types don't match anymore at the time we call them again. I cannot rule out the possibility of this happening during initialization. Therefore, the code doesn't try to be clever about this case and instead just blindly overwrites the lookup (like it did before, just without leaking). Fixes: QTBUG-99025 Pick-to: 5.15 6.2 Change-Id: I536deef282bbff723f79a82e4d9e694c3d2d32df Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Ensure QQmlData::get const-correctnessFabian Kosmale2021-12-041-1/+1
| | | | | | | | | | | | If we pass in a const pointer, we're not allowed to modify the object, so the create==true case does not make sense there. We therefore provide now two versions of the function: One taking only a const pointer, and one taking a non-const pointer and a bool. The latter no longer provides a default parameter to encourage usage of the the const version wherever possible. Change-Id: Ifb5a7e0605127de429403982b31f754e154b8048 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Allow recursion in AOTCompiledContext::initLoadAttachedLookup()Ulf Hermann2021-12-031-1/+1
| | | | | | | | | Otherwise we cannot find attached types of the same name as the current document. Pick-to: 6.2 Change-Id: I927c49d30e466109cc1ef0c1439435581ee30a53 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Clean up PropertyCache life cycleUlf Hermann2021-11-091-4/+4
| | | | | | | | | | | | | We generally want to use QQmlRefPointer for it, rather than manually calling addref() and release() all over the place. Also, we can completely inline its ctor and drop an unused member. Also, do not keep property caches of dynamic meta objects in type registry. The dynamic metaobjects will change, and the outdated property caches will eventually be retrieved. Change-Id: I8042c85b32f3031b554f97a35c1545a3412d2acb Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* qmltyperegistrar: Register foreign base classes anonymouslyMaximilian Goldstein2021-10-291-30/+34
| | | | | | | | | | This is necessary in order to expose all revisioned properties of foreign base classes regardless of module version. In some instances we will want to follow Qt versioning instead though and only expose those classes that are actually exposed at that version level. This will be handled by a follow up change. Fixes: QTBUG-91706 Change-Id: I9049d5cada812560a4b9e07874954045ee5d5562 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJSTypeResolver: store plain types as metaobjectsUlf Hermann2021-10-071-16/+52
| | | | | | | | | This allows us to discern between instances and types in some more cases. Also, we can provide a lookup mechanism to support the same thing in generated code, now. Change-Id: I9d52036a5d2eb11f214f43f976242f43f8f82358 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Provide a method to retrieve JS global properties from AOT contextUlf Hermann2021-10-051-0/+8
| | | | | | | | This is faster than creating a QJSValue from the global object itself and querying that one. Change-Id: I0cc55103f96019ebbf91b683745d51416da9a3ad Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Long live (the internal) QQmlFinalizerHook!Fabian Kosmale2021-09-291-8/+12
| | | | | | | | | | | | | | | | | | | | | | | QQmlFinalizerHook is meant to replace registerFinalizeCallback. The latter is more powerful: It allows you to register multiple functions, depending on various conditions. Moreover, if the component is already finalized, it directly runs the function. However, that power is not used anywhere: All we currently use and need is the ability to run a function after the component is finalized. By using an inerface instead of some generic registration framework, we can make finalizers visible to tooling. This is especially important for qmltc, which needs to instantiate the compiled components and still must ensure that finalizers do run. We also use this chance to document the existence of finalizers, as well as the difference between componentComplete and finalizers. The interface is kept internal, as asynchronus component instantiation is still an underdocumented corner of the QML engine, and the implications of making the interface public are unclear. Task-number: QTBUG-96054 Change-Id: I876bf9650faac20598cfd6aaea7c6da9bf65d73f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Allow type conversions in storeNameSloppy()Ulf Hermann2021-09-061-2/+13
| | | | | | | | | | That's part of the sloppiness. We have no way of retrieving the lookup metatype here. Pick-to: 6.2 Task-number: QTBUG-96144 Change-Id: Ibd1c0d8e9bb66bfe66e59fd1368f3f8ac663d01c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Check setter == setLookup when retrieving lookup metatypeUlf Hermann2021-09-061-1/+2
| | | | | | | | | | We want the same init/apply mechanics to also work with setObjectLookup, and for that we need lookupResultMetaType to do the same thing there. Task-number: QTBUG-96144 Pick-to: 6.2 Change-Id: I410101b7f13e60c0c2ed156a8cf5813c490d7bf0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Provide a method to clear the singletons from a QQmlEngineUlf Hermann2021-08-201-10/+43
| | | | | | | | | | | This is handy for cases where you want to clearComponentCache(). Singletons may hold on to old types, and using them after clearComponentCache() can produce surprising results. Task-number: QTBUG-95788 Change-Id: I390ff78cf9be9c034573ae848c8ccefa6d6a8817 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* qmlcompiler: Add a content variant for module prefixesUlf Hermann2021-08-191-24/+34
| | | | | | | | | | | The code generator needs to see the modulePrefix as a separate step in order to generate sensible code. The savedPrefix we had before was not exposed to the code generator. As an added benefit we can also check that we don't refer to singletons as properties of objects this way. Task-number: QTBUG-95822 Change-Id: Ia8992dba340bf0552e7647f0d66b441f1ac1b8c8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use QV4::Scope::hasException() where applicableUlf Hermann2021-06-301-2/+2
| | | | | | | It is shorter and encapsulates the exception handling a bit. Change-Id: I8e2dc0eb3b930e222b8cb4852b73d99ca18a0379 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow AOT functions to signal an undefined result via the contextUlf Hermann2021-06-151-0/+7
| | | | | | | | | | | | undefined as value returned from bindings has the special meaning of resetting the binding. As AOT-compiled functions return the actual type of the binding rather than a QV4::Value, we cannot always encode undefined. Therefore, add a flag that tells us whether the result was supposed to be undefined. Pick-to: 6.2 Change-Id: Iac2298869dde80f6d889240dd8200b2ad83e5dc5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix AOT-lookup of values in value typesUlf Hermann2021-06-141-2/+2
| | | | | | | | | | | We cannot use the lookup metatype before we initialize it, and the calling code cannot know the result metatype before the lookup is initialized, either. Pick-to: 6.2 Change-Id: I3c691b41dbdb416aa1822c0ea7c4b887398f7908 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Handle half-deleted scope objects in AOT lookupsUlf Hermann2021-06-121-4/+9
| | | | | | | | | | Apparently we can still call bindings and functions on those. In contrast to the QML engine, we throw a type error here, rather than silently returning undefined. Pick-to: 6.2 Change-Id: I7d7daf1582d891f6acadb705b50dc36e23f8425c Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
* Handle objects without QQmlData and objects being deleted in AOT lookupsUlf Hermann2021-06-111-16/+81
| | | | | | | | | | Otherwise we trigger asserts in various places. We also need to generate exceptions matching those the interpreter generates, and we need to decline capturing of nullptr objects. Pick-to: 6.2 Change-Id: I65744fa3e440939db28d7b16a044f6968500a67b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Eliminate JS call frame from metatypes callsUlf Hermann2021-06-101-4/+3
| | | | | | | | 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>
* Pass QMetaType by value rather than by ID in more placesUlf Hermann2021-06-091-1/+1
| | | | | | | | | | 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>
* Add QML_EXTRA_VERSION for adding extra QML versionsFabian Kosmale2021-06-021-4/+9
| | | | | | | | Currently internal, as the only user might be qtcharts. Change-Id: I40fc5295de6375c082d82ebeeb73bf4cd6dc7e4a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Resolve chicken/egg problem when initializing AOT lookupsUlf Hermann2021-05-181-2/+6
| | | | | | | | | | As long as the lookup isn't initialized, we cannot get its result type. If the AOT code relies on the result type to be retrieved from the lookup, allow an invalid type to be passed to the initialization function. Change-Id: I36a1dbe316010dc466a28bae65c3ed267588fc29 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Accept any QQmlListProperty in place of another as AOT lookup resultUlf Hermann2021-05-181-1/+4
| | | | | | | | We often use QQmlListProperty<QObject> as generic type for any list property. This is somewhat dangerous, but unavoidable for now. Change-Id: I9eba2829eaa84aaffe193365f46f406c30fdbf69 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Accept QObject* base classes as types for results of AOT lookupsUlf Hermann2021-05-181-1/+26
| | | | | | | | The AOT compiled code may be unable to express the true type. Change-Id: Id6a0b0c107aa5f05f6024817a1fdea5179ddf5ca Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Require intended types for setting up AOT lookupsUlf Hermann2021-05-181-38/+66
| | | | | | | | | | | | The object to be used for the lookup can be different from what the caller expects. We need to verify that the caller talks about the same type as the object. If it doesn't, throw an exception. For the same reason, also throw an exception rather than asserting if the property caches don't match. Change-Id: I3b45691bfe2204820d878a624814d412d1358c24 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Be more lenient about property caches when doing AOT lookupsUlf Hermann2021-05-171-4/+12
| | | | | | | | | If we know that a property is final, we don't have to consider overrides. Therefore, we can accept a derived class as subject of the lookup. It doesn't have to be the exact same class. Change-Id: I831c64b661730d78d12cec5c98e39282fc8742d8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Provide an AOT variant of StoreNameSloppyUlf Hermann2021-05-031-0/+13
| | | | | | | Leverage the property cache for efficiency. Change-Id: I99910d6851aa5c3d58b15094fbc092c157c74368 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove caching of recursive AOT context lookupsUlf Hermann2021-04-301-25/+24
| | | | | | | | | Such lookups are usually caused by repeaters or similar constructs where many objects look up something in their parent context. As all those objects have different contexts, we would constantly invalidate the cache. Change-Id: I06c7d337d859e5e6a81f6e9a8693b155b2af7498 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Redesign the AOT lookupsUlf Hermann2021-04-301-205/+449
| | | | | | | | | | | | | | | Each kind of lookup should come with a function that tries to execute the lookup, taking a minimal number of parameters, and another one that initializes the lookup, taking whatever is needed for that. No initialization should be done in the execution step and vice versa. Rather, the execution step should be repeated if an initialization had to be done first. This way, the happy path can be very fast if the lookups have been initialized before. Change-Id: Ic435b3dd4906d00144138cb05161a99a0a9c64ed Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Drop further sanity checks from AOT lookupsUlf Hermann2021-04-231-14/+13
| | | | | | | The caller has to make sure the types match. We only check for QVariant. Change-Id: I17d08cab650f9f4d467fa61e2f285f045b73ba0c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Provide optimized AOT lookups for value type propertiesUlf Hermann2021-04-231-0/+30
| | | | | Change-Id: I4acfce1571bfb2527d2ede43229957b89230022e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Further optimize various AOT lookupsUlf Hermann2021-04-231-29/+55
| | | | | | | | | | We can shortcut some of the lookups if we know what we're looking for. Also, as the lookups are populated from the same code that calls them later, we can drop the sanity checks. The calling code should know what it does. Change-Id: Iae3a5b0e997aa5a90bea7933e7ce1f2415f5299b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Provide optimized variant of QmlContextPropertyLookup for AOTUlf Hermann2021-04-221-0/+15
| | | | | Change-Id: Ie06b029850b74e98d6d6e38b480cedef4e481691 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Optimize property capture for known property cachesUlf Hermann2021-04-191-17/+12
| | | | | | | | If we already know the property cache and data we don't have to look them up again in captureProperty(). Such lookups can be expensive. Change-Id: I94553260311912c5acee3105295f124721203e01 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Don't pre-resolve the QQmlContext for AOT functionsUlf Hermann2021-04-191-4/+8
| | | | | | | | We only ever need it to retrieve the QQmlEngine. However, resolving the context can involve an allocation. Change-Id: I064fd528fa7ab9bd37043c5dd1c62d17ea9380e3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Do not throw an exception in the optimized AOT lookup pathUlf Hermann2021-03-311-5/+1
| | | | | | | | | | | | The method already returns a bool status which tells the caller "something is wrong". If something is wrong, the caller will try a different method to retrieve the value, and that will generate the exception again. We should not shortcut the procedure as generating the exception requires the instruction pointer to be set, which is additional overhead on the caller's side. Change-Id: Ia2d3a90c897b14660a18a5740498a0e5016dc49a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Optimize some common lookups for AOT compiled codeUlf Hermann2021-03-291-0/+67
| | | | | | | | Getting a property of an object and getting an object by ID should not require any type transformations. Change-Id: I7ba06cf7c09cdf4ce7b0093b670fd7879ecf799a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow a bare lookup capture, without executing the lookupUlf Hermann2021-03-291-0/+51
| | | | | | | | This is useful when we know how to read the property directly. Change-Id: Ibc314a8e8bf9e51b3a15d934f6a1f17a53ea168a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>