aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4engine.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* QJSValue: convert more aggressively to QVariantFabian Kosmale2023-12-191-16/+32
| | | | | | | | | | | | | | | | | | | | | | | Normally, we don't want to convert aggressively between JS objects and QVariant, as that is prone to losing information. However, QJSValue::toVariant is documented to attempt lossy conversions. Restore the behavior of Qt < 6.5.3 for it. This is done by replacing the boolean indicating we should wrap JS objects into QJSValue with an enum instead. That enum introduces a third state ("Aggressive"), which is only used for QJSValue::toVariant. All other users of QJSEngine::toVariant behave as before (post 6.5.3). Function objects are still not converted, as we know that this would be a futile attempt, and more importantly, to keep the behavior that existed before Qt 6.5.3. Amends 43077556550c6b17226a7d393ec844b605c9c678 which introduced the regression and afe96c4d633146df477012975824b8ab65034239 which fixed the issue only partially. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-119963 Change-Id: I07d9901437812579ac5b873a4dff4de60c8f617e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QML: Add missing metaType-s to ExecutionEngine::metaTypeFromJSDmitrii Akshintsev2023-10-091-0/+6
| | | | | | | | | | | | | After debugging QTBUG-117384 it was found out that ExecutionEnginge is failing to convert Long and ULong types to a meta-type, because they were missing from the switch statement. Fixes: QTBUG-117384 Change-Id: Idcd7325e783df45d27323cb9d9d8372ddde25c3e Pick-to: 6.5 6.6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtQml: Correctly convert to QQmlListProperty<QObject>Ulf Hermann2023-10-071-0/+7
| | | | | | | | | If we have a QQmlListWrapper, we can extract its property. Fixes: QTBUG-117829 Pick-to: 6.6 6.5 6.2 Change-Id: I46ae8db1aabf7c1b617a22f371ce4f060cf4bb38 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qv4mm: Document and extend allocManaged overload setFabian Kosmale2023-10-061-1/+1
| | | | | | | | | Add some helper overloads to centralize the sizeof computation. Add a doc note about the various variants of allocManaged, including a note why we even need the size parameter. Change-Id: I4e0c485217e87c339a7433c306cb05d6614d30e1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Silence warnings about converting holes in sparse arraysUlf Hermann2023-09-251-3/+3
| | | | | | | | | | | | | | Holes in sparse arrays are undefined when read via get(). QV4::Sequence does not have holes, by design. Therefore, when converting, we fill the holes with default-constructed values. This is on purpose and should not cause warnings. Furthermore, since QVariant::convert() always produces the given type, we don't need to re-initialize the variant afterwards. Change-Id: I46a675dfb71ae9f66858c97a580ec133aabef10e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QML: Allow conversion from JS Array to QByteArrayUlf Hermann2023-08-081-3/+15
| | | | | | | | | | | | Since QByteArray is sequentially iterable and we allow any sequentially iterable type to be constructed from a JS array, we also need to allow this. Pick-to: 6.6 6.5 Fixes: QTBUG-115733 Change-Id: I6ffd5eaad0e587ea1cafbe0c1b0179202f3f28cf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QML: Do convert objects with prototypes to QVariantMapUlf Hermann2023-07-271-18/+25
| | | | | | | | | | | | | | | | While we shouldn't convert to QVariantMap if only QVariant is requested, we should convert if QVariantMap is explicitly requested. QVariant can hold QJSValue which is a better fit for objects with properties. QVariantMap cannot hold QJSValue. A best effort conversion is still better than an empty map. Amends commit 47678c682f168eb6d5020383ea75fe1700e8c4f6. Pick-to: 6.6 6.5 Fixes: QTBUG-115523 Change-Id: Iaa96809ee411dc0db95311c641c4e3f1f51a6026 Reviewed-by: Amanda Hamblin-Trué <amanda.hamblin-true@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Un-specialcase QStringList and QVariantList conversionUlf Hermann2023-06-301-131/+92
| | | | | | | | | | | | | | | | | | 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>
* QtQml: Further refine value type creation methodsUlf Hermann2023-06-231-5/+5
| | | | | | | | | The methods that populate a default-constructed value type should be called "populateValueType" and they don't have to unconditionally destroy the old value. Change-Id: Icbc0b4bccf00bb9d0f6c838239ac23a1ec9367aa Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Use QQmlType as container for composite types (inline or not)Ulf Hermann2023-06-221-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This gives us a unified interface to all kinds of QML types at run time and reduces the effort of finding corresponding type attributes. QQmlType is much larger than CompositeMetaTypeIds. Most composite types, however, are initially referenced by URL, and we call typeForUrl anyway. typeForUrl already creates a mostly functional QQmlType; we only need to add the dynamic metatypes. The same type can be retrieved later and associated with the actual CU using the compositeTypes hash. That way, we don't need any extra type. We do, however, incur the cost of creating the QMetaTypePrivate instances when first referencing a type. This could be optimized, like many things in this area, by using thread safe lazy initialization. Now some QQmlTypes implicitly depend on the CUs they were created for. This creates problems if the CUs are removed but the types still persist. Such a situation can arise if you create and delete engines. In order to avoid it, we: 1. Make the compositeTypes hold a strong reference to the CUs 2. When unlinking, avoid dropping the property caches (as those are used to hold the metaobjects) Now, however we got a cyclic reference between the CU and its QQmlType(s). To resolve this, we clear the QQmlTypes on unlinking. Finally, to avoid deletion recursion when clearing the last CUs on destruction of the QQmlMetaTypeData, we move the compilation units out of the way first. All of this still doesn't work if multiple CUs hold the same QQmlType, since compositeTypes can only hold one CU per type and that may be the one that gets removed first. Therefore, we cannot allow such a situation to happen and have to create a new QQmlType if it arises. It can only arise if you have multiple engines loading the same QML components, which should be fairly rare. For inline components, we apply a similar trick: You can either find an inline component by Url, and receive any type that matches, no matter what CU it belongs to. Or you can request an inline component type that belongs to a specific CU. It turns out we don't have to store the containing type of an IC at all. Also, we slightly change the naming of internal components' "class names" since we want to use the inline components' element names for them. Change-Id: I0ef89bd4b0a02cc927aed2525e72f6bff56df626 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QML: Allow conversion of symbols to QVariantUlf Hermann2023-06-201-10/+22
| | | | | | | | | | | We produce their descriptiveString or simply a QVariant containing a QJSValue, depending on whether we're supposed to convert objects without equivalent C++ type or not. Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-113854 Change-Id: I22b6038c936d860fdd8aa227f9dfe704e3265a77 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Try QML conversion before metatype conversionUlf Hermann2023-06-151-4/+20
| | | | | | | | | | and guard against null gadgetPtr. This is what we get for uninitialized value type properties. Pick-to: 6.5 6.5.2 6.6 Fixes: QTBUG-114494 Change-Id: I86ad23abcc4fec219017d1aad6b7add1c9a9af5d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow creating constructible value types from variant objectsUlf Hermann2023-06-151-0/+2
| | | | | | | | | VariantObject as source for value type constructions should work the same way as other types. Pick-to: 6.5 6.6 Change-Id: I35770adf0486b404673ee00800fb1d3e429a23cf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Construct value types by properties from any object-likesUlf Hermann2023-06-081-1/+1
| | | | | | | | | | | | | | | Since we allow any object to be used for property-by-property construction when encoded as QJSValue, we should do the same when it's encoded as QVariant. This allows us to use typed modelData in delegates. The modelData's type only has to be a structured value. Any matching data from the model will then be inserted. Fixes: QTBUG-113752 Pick-to: 6.5 6.6 Change-Id: I200e9acac3c6c302c9dedf8e7e1ccd6c9fdf5eb6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow coercing variant objects to their own typeUlf Hermann2023-06-081-33/+49
| | | | | | | | | This allows passing unregistered value types through QML. Pick-to: 6.5 6.6 Task-number: QTBUG-114340 Change-Id: I6fa5adadf2d406d2d5f3a83fb922e9d547e7ead9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Allow coercion to signed char in metaTypeFromJSUlf Hermann2023-06-051-0/+3
| | | | | | | | | So far we rely on QVariant::convert() and that only works in some places and is expensive. Pick-to: 6.5 6.6 Change-Id: Ia6be7807c3d245148fcd4f4bed2ebc9e35ad52ff Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Encode "missing" line number as negated address of stack frameUlf Hermann2023-05-091-3/+3
| | | | | | | | | | | | | | | This way we can identify which entry in a stack frame to amend when processing an exception in generated code. However, negative line numbers are also used to signal the position of "Ret" instructions. Since you cannot throw an exception from a "Ret" instruction, those cannot collide, but we cannot qAbs() the line number anymore when saving it in the stack trace. We have to qAbs() it in all the places where it's read. Pick-to: 6.5 Fixes: QTBUG-112946 Change-Id: I24dc4008fb7eab38e4d24e70211c22e46f1b72a7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow conversion from QV4::Sequence to different iterableUlf Hermann2023-05-091-11/+21
| | | | | | | Pick-to: 6.5 Fixes: QTBUG-112291 Change-Id: Idd47ea8daf9c54759af6c1feba68bd52d1163615 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Don't try to convert objects with prototypes to QVariantUlf Hermann2023-05-091-4/+4
| | | | | | | | | This is likely to lose some properties. Pick-to: 6.5 Fixes: QTBUG-106266 Change-Id: Ib5a2567d61635a5cf7b3abee7cfef0c073d59e63 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow some more backing types for enumsFabian Kosmale2023-04-121-3/+2
| | | | | | | | | 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>
* Avoid duplicate value type creationUlf Hermann2023-02-241-5/+5
| | | | | | | | | | | We can actually produce an uninitialized but pre-allocated QVariant using QVariant::Private. Using the new in-place construction support in QMetaObject, we can minimize the amount of copying necessary for value types. Fixes: QTBUG-108789 Change-Id: I6b748794a6adbf6558e1e3086eab80fcfb3154a0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix coercion of undefined to float and doubleUlf Hermann2023-02-211-0/+6
| | | | | | | | | | | | | | | | It should result in NaN, not in 0. The typedArray() test exposes that ExecutionEngine::toVariant() also gets this wrong. Fix that, too. [ChangeLog][QtQml][Important Behavior Changes] Converting a JavaScript value to a double or float, for example by inserting it into a typed array, now assumes JavaScript type coercion semantics. In particular, converting a value that is not actually a number now results in NaN where it previously sometimes resulted in 0. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-111179 Change-Id: If24444ae9014c8972761c565a6920f06699e485c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove superfluous Q_DECLARE_METATYPEFabian Kosmale2023-02-081-2/+0
| | | | | | | | | It breaks unity builds, and declaring metatypes outside of the actual class that uses them is generally a bad idea. Pick-to: 6.5 Change-Id: I0106667f6075aabc2fa3c9e5271d21b64f41e4c1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Treat long and ulong like other numbersUlf Hermann2023-02-071-0/+4
| | | | | | | | | | | | They should either be the same size as int/uint or the same size as longlong/ulonglong, but for some reason we get them as separate types. Pick-to: 6.5 Fixes: QTBUG-110767 Change-Id: I4c5826cfe6108e6f9722e6b3443bde13b2141b04 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* V4: Unify type conversions for date and time valuesUlf Hermann2023-01-171-22/+16
| | | | | | | | | | We should always use the same conversion to string and we shouldn't duplicate the code for the date conversion. Task-number: QTBUG-109380 Change-Id: I1b1959c8e9b5957ddcf287d252b8143511237565 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Allow extraction of V4 values from QJSPrimitiveValueUlf Hermann2023-01-161-0/+16
| | | | | | | | | | Since we can produce QJSPrimitiveValue in metaTypeFromJS, we should also handle the other direction. Fixes: QTBUG-109867 Pick-to: 6.5 Change-Id: I2c7598d19eba3e78d071ca3eceb32deda4d0ead8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Fix write back of Date valuesUlf Hermann2023-01-171-13/+29
| | | | | | | | | | A JavaScript Date object can be backed by QDate, QTime or QDateTime. Allow those to be written back. Pick-to: 6.5 Fixes: QTBUG-28981 Change-Id: Ic46b5c4daf75453f03e99470933cf179820e63ef Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QtQml: Allow more fine grained control of the disk cacheUlf Hermann2023-01-021-4/+45
| | | | | | | | | You can now enable and disable the AOT-compiled code and the loading and saving of .qmlc files separately. Fixes: QTBUG-101358 Change-Id: I1305c4f2f75d8cff544a127e956589d1ed1aeb52 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix wrapping of numbers in QJSPrimitiveValueUlf Hermann2022-12-151-0/+18
| | | | | | | | | | | | | | | | | | We need to explicitly cast to double if we are wrapping a number type that's not natively accepted by the ctors. As a side effect, correctly run conversions from generic QVariant to QJSPrimitiveValue through the engine now. For that we need another clause in metaTypeFromJS(). Since we are calling methods that return list types in the test, we need to add another clause that converts JS arrays to list types. Otherwise we cannot run that test in interpreted mode. Pick-to: 6.5 6.2 6.4 6.4.2 Task-number: QTBUG-109111 Change-Id: I87f7aafd24371d2c1ffe85569e1f2cd3a1979742 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Route Qt::TimeSpec usage via QTimeZoneEdward Welbourne2022-12-111-1/+3
| | | | | | | | QTimeZone now packages Qt::TimeSpec details, unifying QDateTime APIs. Task-number: QTBUG-108199 Change-Id: I4a6bfaa213ec6db2fb357d20c7cd59e8c58ad103 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Add an accurate stack bounds checkerUlf Hermann2022-12-091-26/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* QML: Faithfully convert undefined and null to stringUlf Hermann2022-11-151-2/+4
| | | | | | | | | | | | | | | | | | If you do that in JS you get "undefined" and "null", respectively. Our C++-based conversion methods should do the same. The documentation for QJSValue also suggests that QJSValue::toFoo() should behave like qjsvalue_cast<Foo>(x). So far QJSValue::toString() produced "undefined" and "null" while qjsvalue_cast<String>(x) produced an empty string. [ChangeLog][QtQml][Important Behavior Changes] qjsvalue_cast<QString>(x) now returns "undefined" for undefined JS values, and "null" for null JS values. This is in line with what QJSValue::toString() does, and also what JavaScript itself would produce when stringifying such values. Previously, qjsvalue_cast would return an empty string for both, undefined and null JS values. Change-Id: Ib93f4157f092ed769dca946541ffbcfbd7317d4c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Drop unused includes from qv4engine.cppUlf Hermann2022-11-031-10/+0
| | | | | Change-Id: I9123a93e57a0288235fcbb6c521cbbbc875e2407 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Recursively write back value types and sequencesUlf Hermann2022-10-191-8/+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>
* QV4::Scope: Forbid calling alloc with qint64Fabian Kosmale2022-10-131-2/+2
| | | | | | | | | | | | | | | | | | | | | Calling alloc with a qint64 parameter is a good indicator that we got that value from Object::getLength. In that case, the value needs to be sanitized with safeForAllocLength. As a consequence, we notice that method_stringify did indeed use alloc in an usasafe way; this is now fixed. In a few other places, variables had to be changed from unsigned to signed int (as the conversion is now ambiguous). An even stricter check would be to only accepd a value of (not yet existing) "sanitized_size_t" type. However, that requires more effort, at it would each and every call-site, and is thus left as an exercise for later. Pick-to: 6.4 6.2 5.15 Fixes: QTBUG-107619 Change-Id: I3bba9be1e0aea72e11ccb6c168219b4591eb8f5b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QV4: Avoid memory corruption in Reflect.applyFabian Kosmale2022-10-131-0/+19
| | | | | | | | | | This extracts the check from Function.prototype.apply into a shared function, and uses it in Reflect.apply, which has the same issue. Pick-to: 6.4 6.2 5.15 Task-number: QTBUG-107619 Change-Id: I899464c86554f9bbb5270a95bbe3fe27531e9a27 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-071-6/+6
| | | | | | | | | | | | | | | | | | | | 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-11/+6
| | | | | | | | | 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>
* V4: Drop extra QVariant parameter from fromData()Ulf Hermann2022-10-071-11/+7
| | | | | | | | The data needs to be copied anyway if we are going to store it in ScarceResourceObject. We can just as well copy it from the void pointer. Change-Id: Ic106221138b1236a6ddea20cfdb468c6fbe3e1c3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Optimize more type conversionsUlf Hermann2022-10-061-0/+2
| | | | | | | | | | | | When loading from value type properties we left quite a few trivial conversions on the table and went via QVariant instead. Add them. It would be nice to unify the various places where we switch over the trivial types, but I don't see an easy way to do so right now. Change-Id: I9dcb29ce147a2f282e7ea6903a7af8a4b3038af6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Allow more options for creating value types from JS objectsUlf Hermann2022-09-241-13/+30
| | | | | | | | | | | | | | | | | | | | We allow value types to be created 1. by calling Q_INVOKABLE constructors 2. by setting their values from properties of a JS object Both have to be opted into by setting a class info. If opted into, these options override the existing methods. When a a type can be created by setting its properties, that implies you can also initialize it using an invokable constructor. However, when given a JS object, the properties method is used. We keep this internal and undocumented for now. As the last try (the create(QJSValue) methods and QJSValue ctors) was not that stellar, let's first wait a bit and see if we're getting it right this time around. Fixes: QTBUG-106480 Change-Id: I767230924afcba032d501846cc3263dad57b7bf0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* V4: Make ExecutionEngine::toVariant() staticUlf Hermann2022-09-201-27/+36
| | | | | | | | | 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>
* QtQml: Remove unused includes in qml, first partSemih Yavuz2022-09-141-1/+0
| | | | | | | | | | | | | | | 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: Debugger, Compiler, JsApi, JsRuntime, Memory, Parser Task-number: QTBUG-106473 Change-Id: I01d996a2a2ba31cbbc5f60f5454c8f850298f528 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Drop unused value type provider functionsUlf Hermann2022-09-131-1/+1
| | | | | | | | | The only thing we still need is createValueType(). That is by itself debatable, and it can be static. Change-Id: Id092f547415c600b7d1db01f78661c287e7f4979 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow limited extensions to globalsUlf Hermann2022-09-071-1/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can allow a, overriding data members of globals, such as Error.name b, adding members that don't clash with any internals c, any manipulation of toString(), toLocaleString(), valueOf(), and constructor To that effect, add a "Locked" flag to our internal classes. If that is set, disallow changing prototypes and when defining a property, check if it shadows any non-configurable property. Furthermore, make all non-primitive properties that are not meant to be overridden non-configurable and non-writable. constructor, toString(), toLocaleString() and valueOf() are exempt because they are explicitly meant to be overridden by users. Therefore, we let that happen and refrain from optimizing them or triggering their implicit invocation in optimized code. [ChangeLog][QtQml][Important Behavior Changes] The JavaScript global objects are not frozen anymore in a QML engine. Instead, they are selectively locked. You can extend the objects with new members as long as you don't shadow any existing methods, and you can change or override data members. This also means that most methods of Object.prototype, which was previously exempt from the freezing, cannot be changed anymore. You can, however, change or override constructor, toString(), toLocaleString() and valueOf() on any prototype. Those are clearly meant to be overridden by user code. Fixes: QTBUG-101298 Task-number: QTBUG-84341 Change-Id: Id77db971f76c8f48b18e7a93607da5f947ecfc3e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Allow const and non-const QObjectWrappers to coexistUlf Hermann2022-09-071-10/+4
| | | | | | | | | | | | | 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>
* V4: Account for the guard pages when allocating stack spaceUlf Hermann2022-09-071-4/+7
| | | | | | | | | | | | | | | Previously we've assumed the whole allocation can be used, even though the first and the last page are actually not usable. This makes a difference when the size of the guard pages grows, such as on macOS, which these days has 16k pages. Add the extra guard page size to the amount of memory to be allocated in order to fix the calculation. Pick-to: 6.4 6.3 6.2 5.15 Fixes: QTBUG-93188 Change-Id: I0ebece94449da3127e9a78a19d8a22722ad8d698 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Make modules imported with registerModule() available in QMLUlf Hermann2022-09-021-24/+31
| | | | | | | | | So far, you could only use them from pure JavaScript programs. Also, fix re-exporting parts of native modules. Fixes: QTBUG-105901 Change-Id: I170017083284e6457b1aa0c6e606fd26227edae3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Do not update proto usage before engine is fully initializedUlf Hermann2022-08-301-0/+4
| | | | | | | | | Updating the prototype usage is very expensive. We only need to do it once there are lookups. Before the engine is fully initialized there are no lookups. Change-Id: Ic919a1f8955718d417e7747ea72e009d443c42fd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* JSON: Properly handle bad objects in JSON.stringify()Ulf Hermann2022-08-071-0/+3
| | | | | | | | | | | | | | | | | | For objects with circular structures we generate a proper error message and fail earlier. For objects with excessive recursion we throw a range error rather than crashing. This behavior is modeled after node's behavior in such circumstances. We use the existing stack overflow detection to determine when to throw the range error. Testing shows that on windows the limit was insufficient. Lower it. Pick-to: 6.2 6.3 6.4 Fixes: QTBUG-92192 Change-Id: I25dd302f65f359111e42492df3c71549c4ed7157 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>