aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlvaluetypewrapper_p.h
Commit message (Collapse)AuthorAgeFilesLines
* QtQml: Make QLocale an actual value typeUlf Hermann2024-03-021-0/+11
| | | | | | | | | | | | | | | | | | | | We want to be accessible to qmllint and other QML tooling. To this end, make all legal invocations of its methods properly typed invokables. Keep two QQmlV4Function overloads to produce error messages if the methods are called with the wrong parameters. We have to do this because JavaScript is more liberal in its argument coercion than the methods would like. Un-deprecate QJSNumberCoercion::isInteger() since it's actually quite practical here. Pick-to: 6.7 Fixes: QTBUG-112366 Change-Id: I016e5edc47efaade44461c504c1b3e2b1b829b58 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlValueTypeWrapper: Move setData method inlineUlf Hermann2023-06-231-1/+13
| | | | | | | That's a rather common thing to do. Change-Id: I259848b9be5e2a578b0fc1c5f4c6f0f61bd3b723 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Use QMetaType in QQmlValueTypeWrapperUlf Hermann2023-05-171-10/+11
| | | | | | | | | | | Retrieving the QQmlValueType is expensive and there is not a single place where we need anything but its QMetaObject. Retrieving only the meta object, on the other hand, is cheap. Change-Id: I3ad5574d64f1f67a4d4cf2886dc5c396e99ec91a Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QML: Allow as-casting to value typesUlf Hermann2023-03-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | If the "Addressable" option to ValueTypeBehavior is set, you can use the "as" operator to cast a previously unknown type into either undefined or the given type. We can use this in qmlcachegen to generate efficient code for further operations on the same type. In the generated C++ it in fact only works for GetLookup because: a, We generally don't do SetLookup on value types, yet. b, We generally don't call methods on value types, yet. c, We cannot store a union of undefined and a sequence type, yet. However, getting properties of value types is the most important application of the new casts so this is well worth it. As a side effect we can also look up things in potentially undefined results of other operations now. For example list lookups. Task-number: QTBUG-94807 Change-Id: Ifdf34f1f3f67b7a0a8953b9ed0e947b74638a28c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Fix interceptors on value types ignoring fast changesUlf Hermann2023-01-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | If a property is changed and reverted in short order, any animation attached to it may not get a chance to take effect in between. In such a case it looks like we don't have to update the interceptor when reverting, but we actually have to. The animation needs to be canceled, after all. We now have to fix the case of writing different properties of a value type sequentially, where one has an animation attached to it, though. If that happens, we cannot drop the animation when a _different_ property is written later on, but we do still have to update the whole value type. So, pass an additional argument in the relevant metacalls that declares the property we intended to change. Pick-to: 6.5 Fixes: QTBUG-54860 Change-Id: I3b6cad2d4707d30312cda98283928fd419c40345 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Recursively write back value types and sequencesUlf Hermann2022-10-191-30/+38
| | | | | | | | | | | | | | | | | 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>
* V4: Refactor QQmlValueType{Wrapper|Reference} and QV4::SequenceUlf Hermann2022-10-131-47/+16
| | | | | | | | | | | | | Every QQmlValueTypeWrapper is potentially a reference now. Since most were already before, the overhead of checking the vtables at every step was dubious at best. Extract a common base class that handles the reading and writing of object properties employed in both value type references and sequences. Task-number: QTBUG-99766 Change-Id: Idf72d9a20a52366e5c2d0dcd4b3a18072c0ccc41 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Optimize QObject method callsUlf Hermann2022-09-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | So far, for each method call we had to allocate a new QObjectMethod as we didn't have any lookup to cache the methods. Introduce a new lookup for that and use it for all QObject methods. Since QObjectMethod contains a pointer to the concrete QObject the method was retrieved from, some more care has to be taken: If we are going to call the method right away, we don't need the object since we always have a thisObject and any further retrieval of the same method will result in a call again. This enables us to cache the method for any instance of the same class. When storing the method elsewhere, though, we need to hold on to the object since you can defer the call or connect a handler to a signal or similar. For such operations we do need the object. We can still optimize a bit by re-using the method cache we build the first time around. Fixes: QTBUG-95628 Change-Id: I5991180c5e0234cdc179c2b78a43dafc9083e525 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Implement virtualHasProperty for QQmValueTypeWrapperFabian Kosmale2022-07-131-0/+1
| | | | | | | | | We do not have to use the generic path, given that we can just query the meta-object for the existence of the property. Task-number: QTBUG-104803 Change-Id: I9c4f7f8752e0cd8cfd63189538d6ca42523b3587 Reviewed-by: Ulf Hermann <ulf.hermann@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>
* V4: Write back value type references after function callsUlf Hermann2021-05-051-0/+40
| | | | | | | | | | | | If we call a function on a value type reference we have to assume that the value has changed. Therefore, we need to write back, just like we do when writing a property on the reference. Fixes: QTBUG-91783 Pick-to: 6.1 5.15 Change-Id: I6d2e957997d64e40e42eb5210350b6592a92ee26 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Redesign the AOT lookupsUlf Hermann2021-04-301-0/+2
| | | | | | | | | | | | | | | 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>
* Optimize ExecutionEngine::metaTypeToJS()Ulf Hermann2021-03-131-1/+2
| | | | | | | | | | | | | | | | We almost never need to construct a QVariant to do this. Constructing a QVariant is excessively expensive if you have something simple like an integer. This also fixes the unexpected "unwrapping" of variants when we pass them through QJSValue. [ChangeLog][QtQml][Important Behavior Changes] If you create a QJSValue from a nested QVariant (that is, a QVariant containing another QVariant), then, when retrieving its contents again, the outer variant is not unwrapped anymore. Rather, you get exactly the value you've passed in. Change-Id: I8c16eed4f13e8cfdeced0756eef593b3b8e84dd1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use QMetaType instead of metatype-id, take 2Fabian Kosmale2020-12-031-2/+3
| | | | | | | | | This time, the ValueTypeFactory gets converted. As a consequence, many callers get touched again. Task-number: QTBUG-88766 Change-Id: I3a8b7d5cfeb7fac85daf1702febba205971d4256 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Remove the property cache from QQmlValueTypeWrapperLars Knoll2020-12-021-10/+13
| | | | | | | | | | | Instead operate directly on the meta object. We could maybe have an optimization, where we have a global map from id to QQmlPropertyData for each value type. Task-number: QTBUG-88765 Change-Id: I259a06ba116a536b56380c2636737c6c016665d9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Refactor QQmlValueTypeWrapper and assert on some null pointersUlf Hermann2019-09-101-7/+30
| | | | | Change-Id: I8314f2a675211fba08b71e74eacc38076c82b1ed Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Enable lookups in QMLSimon Hausmann2019-03-191-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | The main feature that needs to be implemented in order to enable lookups in QML files is to respect that the QObject wrapper has its own storage layer (meta-object properties). Lookups need to be able to index those when the base is a QObject. This is done by caching the property data and guarding the validity by comparing property cache pointers. The same lookup logic is also implemented for value type wrappers. OVerall there's more that can be done with lookups in meta-objects, for constant properties for example. For "global" lookups we have a safeguard in place that generates a LoadName instruction for property access that should end up in the qml context wrapper. So no changes are needed here at first, but the lookup in the QML context can be optimized in the future. The way of storing the property cache in the lookup itself trades ugliness on destruction against the creation of less internal classes. Another option would be to store the property cache in the internal class and let QObjectWrapper always transition via the property cache. Task-number: QTBUG-69898 Change-Id: I9c378c071acc6d7d4a34a2a76616f9594119d515 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Make Object::getOwnProperty() constLars Knoll2018-09-231-1/+1
| | | | | | | | Object::getOwnProperty never modifies the object, so make it a const member function. Change-Id: I175bb45d61a66a1d9f577c087129562d44d62e17 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Fix ownKey iteration over Proxy objectsLars Knoll2018-09-091-2/+1
| | | | | Change-Id: I045a4844c06df9232cc8b04485ab0a39bb990e3f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Implement ObjectIterator using the new iteration mechanismLars Knoll2018-08-021-1/+0
| | | | | | | And with that get rid of the old advanceIterator methods. Change-Id: I969fa89d25df8992a4b08c8c081b91c92ffdfddd Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Introduce a new mechanism to iterate over object propertiesLars Knoll2018-08-021-0/+1
| | | | | | | | | | | | | | | | | The old advanceIterator schema was extremely ugly and in addition not flexible enough to support the requirements for Proxy.ownKeys and some of the methods in Object Implemented a new scheme through a OwnPropertyKeys method in the Object VTable that creates and returns an iterator object. Ported QJSValueIterator and for-in to use the new mechanism. There's still many places where we use the old ObjectIterator (that relies on advanceIterator). Those will be ported in subsequent commits. Change-Id: I091a9bea9ff6b2b63630cc336814700757a718be Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Prefix vtable methods with virtualLars Knoll2018-07-031-5/+5
| | | | | | | | | Turns out that the overloading of vtable methods and regular ones is problematic in some cases. So let's rather make it explicit which methods are part of the vtable, and which aren't. Change-Id: Ifee32a26104d30f3c82bca8b5a9cdea2d4f4f526 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Replace Identifier by PropertyKeyLars Knoll2018-07-021-3/+3
| | | | | | | | Change all uses of Identifier to use the new PropertyKey class and get rid of Identifier. Change-Id: Ib7e83b06a3c923235e145b6e083fe980dc240452 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify the get and getIndexed vtable functions of QV4::ObjectLars Knoll2018-07-021-1/+1
| | | | | | | | This finalizes the refactoring of Object's vtable API. Also added the receiver argument to the method as required by the ES7 spec. Change-Id: I36f9989211c47458788fe9f7e929862bcfe7b845 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify put and putIndexedLars Knoll2018-07-021-1/+1
| | | | | | | | | | Pass an Identifier through those virtual methods to unify the string and integer based versions. Also add the receiver that's required in ES7 Change-Id: I4e7f01b4c97cc80bcb3c485f6343f28213dc9e6b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Implement a virtual interface for getOwnPropertyLars Knoll2018-06-251-1/+1
| | | | | | | | | | | | This is required to support Proxy properly, and at the same time fixes a couple of test failures. The new interface also replaces the old query and queryIndexed virtual interfaces, as those where doing a subset of what getOwnProperty does. Change-Id: I750e366b475ce971d6d9edf35fa17b7a2b07f771 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Change Objects vtable methods to take a StringOrSymbolLars Knoll2018-05-021-3/+3
| | | | | | | This is needed for symbol support. Change-Id: I83db21f232168710d18999fd97d912016e86d630 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Convert more builtin functions to use the new calling conventionLars Knoll2018-01-121-1/+1
| | | | | | | | Convert most of the methods used QML objects to the new calling convention. Converted IndexedBuiltinFunction to do the same. Change-Id: I41b26042c2f56f24988485b06e8ccd214e2573c0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Remove Scope::result and convert calling convention for builtinsLars Knoll2017-08-081-1/+1
| | | | | | | | Allow for faster calling of builtins, and completely avoid scope creation in many cases. Change-Id: I0f1681e19e9908db10def85a74e134a87fc2e44c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Don't use the ISel's anymoreLars Knoll2017-06-221-0/+1
| | | | | | | | Move the code that generates the CompilationUnit over to Codegen, and don't use the ISel's at all anymore when compiling JS/QML. Change-Id: Iba89082c386c3d3fd58ac25a4651c5d39178cc5c Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Object: Allow put and putIndexed to return success or failureRobin Burchell2017-02-091-1/+1
| | | | | | | | | Some parts of the ES6 (and even ES5!) spec specifically require handling of a property write failure. This will be introduced in followup changes, as it's going to be rather more involved than this. Change-Id: Ie482493fcf4780df0e23619650a856421d20bd55 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Convert more builtin functions to the new calling conventionLars Knoll2017-01-251-1/+1
| | | | | Change-Id: I053215261e1186aff25f29e0967219ef667f7678 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/5.8' into devLiang Qi2016-10-181-4/+14
|\ | | | | | | | | | | | | | | | | | | Conflicts: src/qml/jsruntime/qv4variantobject.cpp src/qml/types/qquickworkerscript.cpp src/quick/scenegraph/util/qsgdefaultpainternode_p.h tools/qmljs/qmljs.cpp Change-Id: I876242714ec8c046238d8fd673a5ace2455b2b59
| * QML: Make Heap::Object and all subclasses trivialErik Verbruggen2016-10-061-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | GCC6 might dead-store-eliminate out our secret write to Base::mmdata, because it expects all memory content to be "undefined" before constructor calls. Clang might take the same approach if the constructor of Heap::Object is removed. By making these structs trivial, it also makes them memcpy-able. Change-Id: I055b2ad28311b997fbe059849ebda4d5894eaa9b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Qml, Imports: mark some methods as constAnton Kudryavtsev2016-10-131-1/+1
|/ | | | | | | These methods do not modify objects. Change-Id: I67b1a10cfd0b32688500fca3265a96f53afd1b57 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Fix visibility of properties in value typesSimon Hausmann2016-05-151-0/+1
| | | | | | | | | | | | It should be possible to enumerate the properties of value types (gadgets), in order for things like JSON.stringify(Qt.point(10, 20)) to return something sensible. Task-number: QTBUG-43382 Task-number: QTBUG-34878 Change-Id: I3a2c09151ebe97fd97760dfbbf5a4f58e022bc94 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
* Updated license headersJani Heikkinen2016-01-191-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: Ic36f1a0a1436fe6ac6eeca8c2375a79857e9cb12 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Remove dead fwd-dclFrank Meerkoetter2015-12-151-1/+0
| | | | | Change-Id: Ifd9fe32b80cd1ebc8dc9fda7c252ecdaae42cb37 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Set the correct prototype at construction timeLars Knoll2015-09-251-0/+1
| | | | | | | Slightly speeds up construction of value type wrappers Change-Id: Ia50e9bcdb07475ed15b5aac908714d25631a0de8 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Move remaining objects to new constructor syntaxLars Knoll2015-09-221-1/+1
| | | | | | | Also disable the old way of constructing objects. Change-Id: Ib4e69087cd563ae1481da116d6caf97876239798 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Get rid of qv4value_inl_p.h and replace it by qv4typedvalue_p.hLars Knoll2015-04-241-1/+1
| | | | | | | | This is a cleaner separation and further reduces include dependencies in the definitions of our basic data structured. Change-Id: I18aa86cdea0c0dfbc16075d4d617af97e638811e Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.5' into devLiang Qi2015-04-221-4/+6
|\ | | | | | | | | | | | | | | | | Conflicts: src/qml/qml/qqmlbinding.cpp src/qml/jsruntime/qv4arraybuffer.cpp src/qml/jsruntime/qv4functionobject.cpp Change-Id: Ic752e9dfd69b282093651c9234c110a49762f06d
| * Speed up copying of value types in bindingsSimon Hausmann2015-04-161-0/+1
| | | | | | | | | | | | | | | | | | When a binding results in a value type reference and the destination property is of the same time, then we can avoid a heap allocation and just allocate the value type memory on the stack, construct, copy and destruct. Change-Id: If71ef82b0ced85c1b962c5e44147d6c07edd1440 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
| * Speed up value type binding creationSimon Hausmann2015-04-161-4/+5
| | | | | | | | | | | | | | | | | | | | | | * Avoid calling QMetaType::construct/destruct(typeId, ...) as that requires repeated lookups in the type registry. Instead cache the constructor/destructor/etc. function addresses in the QQmlValueType singletons as QMetaType * Allocate memory for the gadget pointer lazily, to accommodate the common case of a value type binding by property reference. Change-Id: I98a3ac73453b8f80027c06401b4f29a9707949d2 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Further cleanupsLars Knoll2015-04-161-1/+1
|/ | | | | | | | | The get and getIndexed vtable methods should take a const Managed pointer. Start cleaning up the asFoo() methods in Value and Managed by removing asArrayObject() and asErrorObject(). Change-Id: Ibd49bf20773ef84c15785b7ac37a7bc9fd4745d5 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-121-7/+7
| | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9 Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
* Get rid of most uses of ValueRefLars Knoll2015-01-231-1/+1
| | | | | | | | | | | | Instead pass a const Value & into the functions With our new inheritance structure, we can get rid of ValueRef and instead simply pass a pointer to a Value again. Pointers to Values are safe to use again now, as they are now guaranteed to be in a place where the GC knows about them. Change-Id: I44c606fde764db3993b8128fd6fb781d3a298e53 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
* Enable gadget wrapping for custom value typesSimon Hausmann2015-01-021-0/+1
| | | | | | | | | | | | | | | | | | [ChangeLog][QtQml] Custom C++ value types annotated with Q_GADGET are now fully accessible in the QML and QJSEngine JavaScript environment. QJSEngine::toScriptValue can be used for injection and fromScriptValue to extraction. The QML "built-in" gadget wrappers for QPoint and the gui types are not exposed this way, toScriptValue(point) will still return an opaque QVariant wrapper. We could expose the core types right away, but then we would be lacking an API to enable use of the Gui types that are registered in QtQuick. It would be better to make the core types in qtbase gadgets and thus enable them without the need for hooks and init functions to be called by the user. Task-number: QTBUG-29769 Change-Id: I8179cd599bdc1209ff61cfdbdda419cb400296bb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Removed usage of QQmlValueType in QQmlValueTypeWrapperSimon Hausmann2014-12-281-2/+7
| | | | | | | | | | | | | | | QQmlValueType doesn't have anything really necessary :). Some code it has, but that was only called from the wrapper, so it was moved there. This also reduces one level of memory allocation for the wrapper. In theory the allocation for the JavaScript wrapper could be changed to be the size of the wrapper _plus_ the size needed for the gadget. However in anticipation of wanting to be able to move objects, we can't do that as we can't memmove() gadgets around - they might contain pointers to memory areas within. Change-Id: Icb5a6f5513e3b2c87f6639f6f7b1fb572af08137 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Reduce dependencies on QQmlValueType being a QObjectSimon Hausmann2014-12-231-0/+1
| | | | | | | | Don't rely on caching the property cache in the QQmlData of the value type, instead we can cache is in the engine and store it in our object data. Change-Id: I5f31313c066cd7918caf33e3fabdf5aac71f1adb Reviewed-by: Lars Knoll <lars.knoll@digia.com>