aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4qobjectwrapper.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* QML: When marking a QObjectWrapper, also mark its const counterpartUlf Hermann2023-07-261-3/+31
| | | | | | | | | | | | Otherwise the const wrapper will be swept while the object should still be alive (and vice versa). Amends commit d3b3fef5a878d7fd53de6a9f9fff196a273930e3. Pick-to: 6.6 6.5 Fixes: QTBUG-114596 Change-Id: Ib4d8e9f805a229a471ca72f5ff357e3a4c9999a5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Unify treatment of wrappers when dealing with QObjectMethodUlf Hermann2023-07-121-88/+91
| | | | | | | | | | | | | | A method can belong to a QObjectWrapper, a QQmlValueTypeWrapper, or a QQmlTypeWrapper. store only one wrapper pointer and allow for all variants. Furthermore, keep a reference to the wrapper so that it doesn't get garbage collected. We still need it to retrieve the metaobject, even if we're calling the method on a different instance. Pick-to: 6.2 6.5 6.6 Fixes: QTBUG-115115 Change-Id: I1759fb687918ff79829fef776e0a93d29373b30f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Fix validation when calling methods with different 'this'Ulf Hermann2023-07-071-1/+5
| | | | | | | | | | | We were checking the wrong method offsets and we didn't check for destroy() and toString(). Amends commit 3fd3a2a9d06505d549cc4a7c18819a17c6622dfd. Pick-to: 6.5 6.6 Change-Id: I8ebeb927a7827cc1fd3394fb3ab589c35d31ab70 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Check result when constructing object from metaobjectUlf Hermann2023-07-061-3/+5
| | | | | | | | | | | If you pass insufficient arguments to call the ctor, the resulting object is null and cannot be used. Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-114910 Change-Id: Ib184684b6a7665bcdc1a3fe8f8a2401a33a8ac1c Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Un-specialcase QStringList and QVariantList conversionUlf Hermann2023-06-301-6/+6
| | | | | | | | | | | | | | | | | | Those are just regular sequences these days. They can be written back. Drop some now-dead code and deduplicate the value type conversion code in the process. We should try the (more common) value type conversion before the sequence conversion, but after all the "simple" conversions. [ChangeLog][QtQml][Important Behavior Changes] Converting a QVariantList to a QJSValue via, for example QJSEngine::toScriptValue() does not produce a JavaScript array anymore, but rather a better suited sequence object that behaves almost like a JavaScript array. The only difference is that its QJSValue::isArray() will return false now. Fixes: QTBUG-113690 Change-Id: Ib176c34d59c45a6b5cff68d029c4b1b87d7aa192 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Better encapsulate QmlListWrapperUlf Hermann2023-06-261-1/+1
| | | | | Change-Id: I00a298f8b5d0473b89c6385e46983ef776a4531b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* ResolveOverloaded: change qCInfo to qCDebugOlaf Mandel2023-06-231-17/+17
| | | | | | | | | | | Change the message type for the messages on category qt.qml.overloadresolution from Info to Debug: the messages are intended for debugging purposes, so an Info message type is "too loud". Fixes: QTBUG-114643 Pick-to: 6.6 Change-Id: I3d33ea05de24eb98aa736e7c74016a53aa9a00b4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Rename qmlobject_can_castUlf Hermann2023-06-221-2/+2
| | | | | | | | We want a version that only casts using the first C++ metaobject, and another one that takes the full QML type hierarchy into account. Change-Id: Ie23cf774f7837955de63d5ccb6c7cead1d1948f2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Fix overload resolution for QObject* typesUlf Hermann2023-06-091-2/+31
| | | | | | | | | Amazingly, QObject pointers were not supported at all so far. Pick-to: 6.5 6.6 Change-Id: I61b28705d3bebf9602bdeee05aadcb085f39b184 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Call value type ctors with derived types of formal parameterUlf Hermann2023-06-081-14/+30
| | | | | | | | | | | | If you pass an argument of a derived type to a ctor that's declared to accept the base type, this will generally work, even if no QMetaType conversion is explicitly declared. Pick-to: 6.5 6.6 Task-number: QTBUG-113752 Change-Id: I0364c2d6b2a1b0f6c067b5a4fd5c000e483afca6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QML: Re-add QMetaType::convert() attempt for argument conversionUlf Hermann2023-06-081-1/+5
| | | | | | | | | | | There are people who depend on QMetaType to convert their types. This is not nice, but removing it breaks compatibility. Pick-to: 6.5 6.6 Fixes: QTBUG-114340 Change-Id: I0a7f54b8fd0f77b71e7e56f65ef7d6f91c876237 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QObjectWrapper: Use metaTypeFromJS for call argumentsUlf Hermann2023-06-051-29/+2
| | | | | | | | | | | We want the precise type there, not some approximation that happens to be a QVariant. This exposes that we had a few conversions that were possible with QVariant::convert() but not with our builtin type coercion. Pick-to: 6.5 6.6 Change-Id: I44c57a22bad8268de3d4398721e1c63b18009dfc Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Fix typo in warning messageUlf Hermann2023-06-051-1/+1
| | | | | | | Pick-to: 6.5 6.6 Task-number: QTBUG-114086 Change-Id: Iacaaf3ed0696c78664c62398931a13ffbc9f3211 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QML: Maintain invariant between QObjectMethod membersUlf Hermann2023-05-111-3/+19
| | | | | | | | | | | | | | | If the methodCount is 0, the methods have to be nullptr. Otherwise they have to point to the actual method(s). This is important for the method resolution to work correctly. In particular when cloning a method we have to check for 0. Amends commit 17bd07cbc5b6cf54716e991765ab3088a710d7b3. Pick-to: 6.5 Fixes: QTBUG-113484 Change-Id: Ic31d6e391c1d74a162820232f242a19379f5e4df Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Properly support lists as method argumentsUlf Hermann2023-05-091-0/+5
| | | | | | | | | | | a, Teach QV4::QObjectWrapper how to convert QQmlListProperty to QObjectList. b, Parse the isList attribute from qmltypes. c, Resolve lists when resolving QQmlJSScope. Change-Id: I70c6d40507de990b45a87eb7d8c7bba279d550e8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Don't crash when monitoring binding removalUlf Hermann2023-05-051-7/+19
| | | | | | | | There are more bindings kinds around. Fixes: QTBUG-113353 Change-Id: If545f56bd61c238431883be3eb013841d96b18bb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow some more backing types for enumsFabian Kosmale2023-04-121-1/+1
| | | | | | | | | Task-number: QTBUG-112180 Done-with: Fabian Kosmale <fabian.kosmale@qt.io> Change-Id: I48a2a696d3424ab1d8b9e693a92361a978ad70e9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Support more integer typesUlf Hermann2023-03-301-1/+1
| | | | | | | | | | | This adds support for 8- and 16-bit signed and unsigned integer types. The test exposes that the engine fails to correctly convert out of range values when assigning to a 32-bit int property. Fix that as drive-by. Fixes: QTBUG-101634 Change-Id: I0a4177f49ffc062a1f444e30424e94c1f293e70c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QML: Add a pragma for value type behaviorUlf Hermann2023-01-201-8/+18
| | | | | | | | | | | Unfortunately value types behave differently when compiled to C++. Document the difference and introduce a pragma to make them behave one way or the other. Pick-to: 6.5 Fixes: QTBUG-109221 Change-Id: Ib2685153c0b4ae209bafbea7a01229377fdb47dd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QObjectWrapper: fix QT_ASCII_CAST_WARNINGMarc Mutz2023-01-031-1/+4
| | | | | | | | | | | | | | | | | The two arguments to QLatin1StringView::arg() are const char* and QByteArray, both of which are considered "ASCII" for the purposes of QT_ASCII_CAST_WARNING. Fix by wrap them in QLatin1StringView (their contents are actually ASCII (class and method names)). Amends 3fd3a2a9d06505d549cc4a7c18819a17c6622dfd. As a drive-by, use the _L1 UDL for the format string. Pick-to: 6.5 Change-Id: I7f83133f52b6f4ec53a2bfcbca58d91afa9e2ff2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QObjectWrapper: Fix calling attached methods on different objectsUlf Hermann2023-01-021-35/+137
| | | | | | | | | | | | | You can generally store a method in a value and call it on a different object. However, since we've ignored the thisObject basically forever, we cannot just accept it right away. Add an opt-in mechanism via a pragma that allows you to pass (implicitly via context or explicitly via call()) specific thisObjects to QObject methods. Fixes: QTBUG-109585 Pick-to: 6.5 Change-Id: I4c81b8ecf6317af55104ac9ebb62d98862ff24e7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Add an accurate stack bounds checkerUlf Hermann2022-12-091-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This re-introduces a stack bounds checker. The previous stack bounds checker was removed in commit 74f75a3a120b07bbfe6904512b338db8850874e4 because the cost of determining the stack base was deemed too high. Indeed, determining the stack base on linux using the pthread functions costs about 200.000 instructions and the cost grows with the number of concurrently running threads. However, by reading /proc/self/maps directly we can trim this to about 125k instructions. Furthermore, with the new implementation we only need to do this once per engine. Calling JavaScript functions of the same engine from different threads is not supported. So we don't have to consider the case of checking the bounds of a different thread than the one the engine was created in. Furthermore, we get a more accurate number now, which means we don't have to re-check when we get near the boundary. Also, change QV4::markChildQObjectsRecursively() to use an actual QQueue instead of being recursive. This avoids the stack from overflowing when the stack is already almost full, and was leading to crashes in the stackOverflow tests. Make the stack smaller for the the tst_qquickloader::stackOverflow{,2} tests to run faster in the CI (and avoid the timeout). Task-number: QTBUG-106875 Fixes: QTBUG-108182 Change-Id: Ia5d13caa7d072526ff2a3e1713ec7781afc154a9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qv4qobjectwrapper: return false on failed argument conversionSami Shalayel2022-12-021-1/+1
| | | | | | | | | | | | | | | | It was possible to call c++-methods (either invokable or as slot) with wrong arguments, which caused a crash. The reason was that CallMethod(...) converted something to a QObject without checking if it was an actual QObject. The wrongly typed argument would end up reinterpret_cast'ed into another type for the call, which leads to segmentation fault when accessing the argument in the function. Added a test where an int tried to be reinterpret-cast'ed into a QFont. Pick-to: 6.4 6.2 Fixes: QTBUG-108994 Change-Id: I8c45c9124411ad3fd100faed0b03390843f7d034 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlMetaObjectWrapper: A metaobject is not equal to a non-metaobjectUlf Hermann2022-12-021-8/+4
| | | | | | | | In particular, the Qt object's prototype is not equal to anything. Change-Id: I208d0bd914b0890e842775d273f2d3b5c63c1d36 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QJSEngine: Optimize conversion from QObject* to QStringUlf Hermann2022-11-221-29/+36
| | | | | | | | | | | | | | | This is commonly done for logging. With this in place we can have the code generator use coerceType() for such constructs. [ChangeLog][QML][Important Behavior Changes] You can implement custom toString() methods for your QML objects in JavaScript or in C++. Those methods don't actually have to return a string. Previously, whatever return value the method generated was forwarded as-is. Now it is coerced to a string. Change-Id: I4a9721a6948be0c24a36b31d453a74bd747db729 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Port to new Q_UNREACHABLE_RETURN()Marc Mutz2022-10-201-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator to convert sequences of Q_UNREACHABLE() + return into Q_UNREACHABLE_RETURN(), newly added to qtbase. const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule(stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)); a.k.a qt-use-unreachable-return. subStmt() and nextStmt() are non-standard matchers. There was one false positive, suppressed it with NOLINTNEXTLINE. It's not really a false positiive, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. Change-Id: I3855b2dc8523db1ea860f72ad9818738162495c6 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Recursively write back value types and sequencesUlf Hermann2022-10-191-41/+86
| | | | | | | | | | | | | | | | | 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>
* Port from container::count() and length() to size() - V5Marc Mutz2022-10-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); except that on() was replaced with a matcher that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Change-Id: I58e1b41b91c34d2e860dbb5847b3752edbfc6fc9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* V4: Refactor QQmlValueType{Wrapper|Reference} and QV4::SequenceUlf Hermann2022-10-131-24/+8
| | | | | | | | | | | | | 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>
* QObjectWrapper: Assert on m_multiplyWrappedQObjects where appropriateUlf Hermann2022-10-111-1/+3
| | | | | | | | | If we have a const wrapper we always have m_multiplyWrappedQObjects. The static analyzer cannot see it, though. Coverity-Id: 401044 Change-Id: Id97597185ec1aef5cfa640029d9afa133a7219d9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-071-5/+5
| | | | | | | | | | | | | | | | | | | | 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>
* QML: Drop the "succeeded" out parameters from SequencePrototypeUlf Hermann2022-10-071-3/+2
| | | | | | | | | The success of the operation is visible from the return value in all cases. Change-Id: I93177785f76b8078ddd8eeb7d77143993fe80739 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Optimize QObject method callsUlf Hermann2022-09-201-56/+197
| | | | | | | | | | | | | | | | | | | | | | 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>
* V4: Make ExecutionEngine::toVariant() staticUlf Hermann2022-09-201-6/+6
| | | | | | | | | Wherever we need an engine in there, we also have a managed value to get it from. This relieves us from the requirement to drag an engine around wherever we want to call toVariant(). Change-Id: Ib95d02b5fbf5eaa494214e337c9b700e97e5e0df Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Allow const and non-const QObjectWrappers to coexistUlf Hermann2022-09-071-43/+43
| | | | | | | | | | | | | 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>
* Engine: Fix handling of attached objects in function callsFabian Kosmale2022-09-021-4/+6
| | | | | | | | | | | | | | | | When we use an attached object as an argument to a function call, we need to properly extract it from the QmlTypeWrapper. Before this change, we simpley left the argument pointer as null, which lead to subsequent crashes when it got dereferenced. Moreover, treat passing namespaces to functions expecting a QObject as a TypeError, by returning false from CallArgument::fromValue (used to crash for the same reason as with the attached object case). Pick-to: 6.2 6.3 6.4 Fixes: QTBUG-106119 Change-Id: Ifa6a32e20a29935aff1f265eb0edd3e35ea1c11b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* V4: Mark InternalClass parents when running GCUlf Hermann2022-08-031-1/+1
| | | | | | | | | | | | | | | | We need to preserve them as they notify us about protoId related changes. In order to avoid wasting heap space in case many properties are added and removed from the same object, we put a mechanism in place to rebuild the InternalClass hierarchy if many redundant transitions are detected. Amends commit 69d76d59cec0dcff4c52eef24e779fbef14beeca. Pick-to: 5.15 6.2 6.3 6.4 Fixes: QTBUG-91687 Task-number: QTBUG-58559 Change-Id: I3238931b5919ed2b98059e0b7f928334284ce7bf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix array-like methods on V4 sequencesUlf Hermann2022-07-191-1/+1
| | | | | | | | | | | | | We need to properly convert value type lists on assignment and we need to add the "length" property to the own properties. Furthermore, the V4 sequence methods were confused about integer type ranges. We teach them about qsizetype, properly range check everything, and drop the artificial limitation to INT_MAX. Pick-to: 6.4 Task-number: QTBUG-82443 Change-Id: Ie5af1130c9e78e412c171e6fa26a28a6a7a5d498 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* ResolveOverloaded: add debug output for resolutionFabian Kosmale2022-07-121-5/+35
| | | | | | | | This is helpful to understand why exactly a certain method overload has been chosen. Change-Id: Ia6895d628cd25589a2bb8144544d0f827c5fb730 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML engine: Let string match QUrl during overload resolutionFabian Kosmale2022-07-121-0/+2
| | | | | | | | | | | | | | | If an overload set contains a function with a QUrl parameter, and we pass in a string, that would have resulted in the worst-possible score of 10 for that function. Given that URLs are often provided as strings in QML for convenience (instead of using e.g. Qt.url), that is arguably a bad idea. Starting from this commit, they'll get a score of 6: QJsonValue still wins (to minimize the risk of breaking existing overload sets), but we no longer claim that there is no match at all for such a parameter. Change-Id: Ic0faa0029c9d5f14aff143cbd7fd4859d9ac2b2a 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>
* Allow retrieval of sequences from QJSValueUlf Hermann2022-06-021-5/+4
| | | | | | | | | | | | | | As we can store sequence types in QJSValue, we should be able to retrieve them, too. Move the declaration of the QV4::Sequence struct into a header to make it less of a hassle to identify sequences. Change-Id: I3e45bfe193c669107f90cd6c502765c0c9f60fb0 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Replace synthetic AOT functions with property-to-property bindingsUlf Hermann2022-05-241-1/+1
| | | | | | | | | Those should be more efficient and make your feet attract fewer projectiles. Fixes: QTBUG-103588 Change-Id: I8b25b9edb1edf5e112dbcba5bba898646d29ae2b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Generalize QQmlAbstractBinding::isValueTypeProxy()Ulf Hermann2022-04-251-1/+1
| | | | | | | | | Instead of a bool we can just return an enum of the actual kind. This way all the checks become more readable. Furthermore, we can eliminate a dynamic_cast without sacrificing readability. Change-Id: I8a38687f9b796cd47196a6ab0385624c737e4435 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Respect invokable toString() methodsUlf Hermann2022-03-281-11/+22
| | | | | | | | | | | | | | | We should not invoke the base toString() method if there is an override in a more specific type. This involves lowering the priority of generic JS lookups when resolving scope properties, in favor of context and scope lookup. [ChangeLog][QtQml] You can now override the JavaScript toString() method by providing a Q_INVOKABLE method of the same name in your QObject-based C++ classes. Fixes: QTBUG-87697 Change-Id: I6190111f4c28e54ce76c391c69c4a921e290e612 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Make most QQmlPropertyData constUlf Hermann2022-03-141-11/+13
| | | | | | | You really should not mess with that after creating the property cache. Change-Id: I070200772475bb67f539dbbd85a298020b14ca79 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use const QQmlPropertyCache wherever possibleUlf Hermann2022-03-141-4/+5
| | | | | | | | 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>
* V4: Avoid repeated lookup of h->object() in QObjectWrapperUlf Hermann2022-02-051-5/+5
| | | | | | Change-Id: I200be7a6257a39a117a2bca09c7aca6594d40ee2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* V4: Do not call dtor of an object we continue to useUlf Hermann2022-02-031-3/+2
| | | | | | | | | | | | | | | | | | After destroyObject(), the QObjectWrapper is still alive. We might use its heap object again. Furthermore, the Heap::QObjectWrapper dtor does not actually do anything defined. What we want to do here is clear the QObject pointer because we've just gotten rid of the QObject. There is a method for that: Heap::QObjectWrapper::destroy(). Finally, the internalClass must never ever be nullptr. Assert on that rather than checking it. Pick-to: 5.15 6.2 6.3 Task-number: QTBUG-100431 Change-Id: I794a295c182b2ed4ba80673f58d6143c861b7391 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow named lists of value typesUlf Hermann2022-01-281-16/+17
| | | | | | | | | | | | | | | | | | | | | | | | 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>