summaryrefslogtreecommitdiff
path: root/src/qml/jsruntime/qv4object.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Move ScopedStackFrame into qv4stackframe_p.hUlf Hermann2023-05-171-9/+11
| | | | | | | | | | | This is where it belongs. We need to apply some tricks to avoid cyclic includes, but that's better than what we have so far. Also, sort and clean up the includes in the affected files. Change-Id: Ia7a957d06c0ca284045d831417740c3f9920bc92 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Models: Straighten out model and modelData propertiesUlf Hermann2023-03-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | If there is more than one role, just return the whole model item as modelData. This makes sure we can always require modelData. That's a basic precondition for writing delegates that work with any model. The test shows that model and modelData behave quite erratically in the different cases, but much of this cannot be changed anymore. At least they are now both available in all cases. Furthermore, provide modelData as anonymous property of model. This way, if you have a model that can be singular, and a role that will be an empty string if the model is singular, you can just write: SomeDelegate { required property var model someData: model[role] } Task-number: QTBUG-111176 Task-number: QTBUG-110980 Task-number: QTBUG-104752 Change-Id: Ie200be467df2098d817b85b03d2409267722b596 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Recursively write back value types and sequencesUlf Hermann2022-10-191-0/+25
| | | | | | | | | | | | | | | | | 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()Marc Mutz2022-10-071-1/+1
| | | | | | | | | | | | | | | | | | | | 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>
* QtQml: Remove unused includes in qml, final partSemih Yavuz2022-09-141-4/+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: JsRuntime, Qml Fixes: QTBUG-106473 Change-Id: I483da15d42a8e3ce6cd3b654909665fff3075d6b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow limited extensions to globalsUlf Hermann2022-09-071-4/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* V4: Do not update proto usage before engine is fully initializedUlf Hermann2022-08-301-1/+9
| | | | | | | | | 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>
* V4: Mark InternalClass parents when running GCUlf Hermann2022-08-031-12/+47
| | | | | | | | | | | | | | | | 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>
* 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>
* JS: Ensure that array keeps valid after length changes and fix concatFabian Kosmale2021-07-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | This is a partial revert of 6fa617524a6d0a2bc988e2dc70e8d719d1b9c282. The reasoning there was wrong: Due to the ring structure of the array, there might be further (non-undefined) elements at the start of the allocated memory. Those need to be copied to. This patch therefore reverts the change in 6fa617524a6d0a2bc988e2dc70e8d719d1b9c282 which simply set the size, and restores the copying behavior again. The actual fix for the crash in QTBUG-81037 requires a change to how we set the array length: Previously, when the size increased, we only reinitialized the array (as a sparse array) when the new size was greater than a certain threshold. If the new size was smaller than that threshold (but larger than the current alloc value), we would end up with an inconsistent array: It was non-sparse, but had a smaller capacity than size, leading to the memory corruption in concat when the elements that should exist (but did not) were accessed. This patch ensures that we now always resize the alloc buffer if necessary. Task-number: QTBUG-81037 Fixes: QTBUG-90456 Change-Id: Ie193aa3d714121ce6e8203c4b663b9015715e025 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Use QV4::Scope::hasException() where applicableUlf Hermann2021-06-301-3/+3
| | | | | | | It is shorter and encapsulates the exception handling a bit. Change-Id: I8e2dc0eb3b930e222b8cb4852b73d99ca18a0379 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Clean up JSCallData setupUlf Hermann2021-03-171-8/+8
| | | | | | | | | | | | | | | | | We either have pre-populated arguments and thisObject, then we can just use them and keep them const. Or, we want to allocate and populate the arguments and the thisObject. Then, do allocate them in a separate object, and transform that into JSCallData afterwards if necessary. Furthermore, avoid alloc(0) as that just returns the current stack top. Writing to it will clobber other data. Rather, just use nullptr and crash if it's written to. Also, remove the useless operator-> from JSCallData. That one just confuses the reader. Change-Id: I8310911fcfe005b05a07b78fcb3791d991a0c2ce Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port QtDeclarative from QStringRef to QStringViewKarsten Heimrich2020-06-161-1/+1
| | | | | | | | Task-number: QTBUG-84319 Change-Id: I2dcfb8a2db98282c7a1acdad1e6f4f949f26df15 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Re-arrange qv4identifier{_p.h|.cpp}Ulf Hermann2020-04-151-1/+1
| | | | | | | | | | | | QV4::IdentifierHashData doesn't need to be visible to all the clients. Furthermore, it can be completely inline. The public functions of QV4::IdentifierHash need to be out of line, but the private ones can be all inline. This shouldn't make much of a difference as most of the public functions call at least one private function. Finally, the files should be named by the class names. Change-Id: I931f2aa71103e41fdd3dae9cc47d204edece0e12 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Check for exceptions before we use the result of a JS callUlf Hermann2020-01-231-1/+1
| | | | | | | | If the call resulted in an exception the return value is undefined. Task-number: QTBUG-81581 Change-Id: Ibfdd5e1229cf5437f270232d3b1a91308adeec72 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Merge remote-tracking branch 'origin/5.13' into devQt Forward Merge Bot2019-05-161-4/+5
|\ | | | | | | Change-Id: I192cb06f3b92869699cb3e072f2c6c1e8dbb1ef4
| * Do not take a reference of nullptrAllan Sandfeld Jensen2019-05-141-4/+5
| | | | | | | | | | | | | | | | | | | | | | References are not allowed to be null, but we pass a nullptr as receiver in QQmlContextWrapper::resolveQmlContextPropertyLookupGetter. Detected with UBSAN. Change-Id: Iaa7945fb17e4b0e549e541e47589b2f47d32ea4e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Don't use UINT_MAX as invalid array index in PropertyKeyUlf Hermann2019-04-161-11/+7
| | | | | | | | | | | | | | | | | | | | | | Technically UINT_MAX is actually a valid array index, although that is an academic problem right now. However, we do have a method isArrayIndex() and should just use that to determine if a PropertyKey is an array index. Fixes: QTBUG-73893 Change-Id: I302e7894331ed2ab4717f7d8d6cc7d8974dabb4e Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* | Merge remote-tracking branch 'origin/5.13' into HEADUlf Hermann2019-03-221-3/+94
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/qml/compiler/qv4compileddata_p.h src/qml/jit/qv4baselinejit.cpp src/qml/jit/qv4jithelpers.cpp src/qml/jsruntime/qv4lookup.cpp src/qml/jsruntime/qv4runtime.cpp src/qml/jsruntime/qv4runtimeapi_p.h src/qml/jsruntime/qv4vme_moth.cpp src/qml/qml/qqmltypemodule_p.h Change-Id: If28793e9e08418457a11fc2c5832f03cab2fcc76
| * Make object property lookup resolution virtualSimon Hausmann2019-03-151-0/+82
| | | | | | | | | | | | | | | | | | | | This allows sub-classes of Object to have their own lookup resolution and verification logic, instead of squeezing it all into qv4lookup.cpp. The typical fallbacks are still in qv4lookup.cpp though. Task-number: QTBUG-69898 Change-Id: I32a8884982b37e2065090666a7bf05b198f5b7fd Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
| * Don't keep raw pointers to SparseArrayNodeUlf Hermann2019-03-141-3/+5
|/ | | | | | | | | | | | The nodes are owned by the SparseArrayData and will be freed whenever an item is deleted from the array. Therefore, we have to look up the node for each iteration. This is slightly slower, but at least it doesn't crash. Fixes: QTBUG-74188 Change-Id: Id24324a8c83b00b3ad1212cdaabccabd6c8a999f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Ensure our builtin constructors are subclassableLars Knoll2018-11-221-0/+15
| | | | | | | | | Respect the newTarget passed into those constructors and make sure we set up the proto chain correctly. Change-Id: I3d12c7dbef4b33660a6715d73e9fb0f89105167a Fixes: QTBUG-71138 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Speed up instanceof operationsLars Knoll2018-09-271-7/+13
| | | | | | | | | | | Introduce a shortcut if the rhs is a functionobject with the regular function proto as prototype. Add an optimized instanceOf implementation when we already have some checks done, and inline some methods. Change-Id: Iab9b648ae7bbec749b319e883b6ae90a23875454 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Refactor deletion of propertiesLars Knoll2018-09-271-6/+5
| | | | | | | | | | | | | In line with the previous commit, allow entries with a valid PropertyKey, but invalid attributes in the InternalClass. Those entries mark a deleted property. This cleans up/unifies some of the code in the internal class implementation and allows re-using the slot if a deleted property gets added again. Change-Id: I1bada697486e3cafce7689bae87b7f884200dd99 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Get rid of remaining assumptions about setter being next to gettersLars Knoll2018-09-271-47/+41
| | | | | | | | The only place where we now assume that getters and setters are next to each other in the MemberData is in the internal class. Change-Id: I3285f3abb1cbfe051853e808339cd360eb602262 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Differentiate between finding for get and set in InternalClassLars Knoll2018-09-271-13/+11
| | | | | | | | This is required, so we can get rid of the requirement that getter and setter live next to each other in the member data. Change-Id: I2ed57a171628af4dfecd1836d00e958c6bed9d4f Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Refactor InternalClass::find()Lars Knoll2018-09-271-23/+23
| | | | | | | | | Specialize find() into several methods for different purposes. Prepares for further cleanups and being able to split up getter and setter for accessor properties. Change-Id: Id4ec5509ac1a1361e2170bbfc2347b89b520c782 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Make Object::getOwnProperty() constLars Knoll2018-09-231-2/+2
| | | | | | | | Object::getOwnProperty never modifies the object, so make it a const member function. Change-Id: I175bb45d61a66a1d9f577c087129562d44d62e17 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Cleanups in Value/PrimitiveLars Knoll2018-09-171-2/+2
| | | | | | | | | | | | Get rid of Primitive and move the corresponding methods directly into Value. Mark many methods in Value as constexpr and turn Value into a POD type again. Keep Primitive as a pure alias to Value for source compatibility of other modules that might be using it. Change-Id: Icb47458947dd3482c8852e95782123ea4346f5ec Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Some more optimizations to Object::internalPut()Lars Knoll2018-09-161-0/+12
| | | | | Change-Id: Ib1b224ad27428ca37450f269b491cfa9d82e559a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Optimize Object::virtualGet()Lars Knoll2018-09-161-21/+30
| | | | | | | | Optimize virtualGet() for the common case where the proto chain are all regular objects. Change-Id: I51eea9a4b96033be4effc2072fedc5b9b08e8440 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add a shortcut into Object::internalPut() for the common casev5.12.0-alpha1Lars Knoll2018-09-111-1/+43
| | | | | | | | This avoids a lot of the slowdown of the more generic code path. Change-Id: I1a22f55900d3dc829d7733f9d79b8de5d79dc44c Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Fix a small bug in virtualHasPropertyLars Knoll2018-09-091-5/+6
| | | | | | | | | It should call hasProperty() on the proto if the property wasn't found locally, instead of looping and calling getOwnProperty, as this leads to subtly differences with Proxy objects. Change-Id: I088b0522c621999b7991f9194f46eaa9f6e15206 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Include symbols in getOwnPropertyKeysLars Knoll2018-09-091-17/+31
| | | | | | | And fix getOwnPropertySymbols and getOwnPropertyDescriptors. Change-Id: Ie0e4c3d308ffe8a904e9a6ab9242b2cda59d779f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix ownKey iteration over Proxy objectsLars Knoll2018-09-091-1/+2
| | | | | Change-Id: I045a4844c06df9232cc8b04485ab0a39bb990e3f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix spec compliance of Object::virtualGet()Lars Knoll2018-09-081-42/+25
| | | | | Change-Id: I9c07a6b08e9029b893c28e7a945f839c0f0dda8d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix internalPutLars Knoll2018-08-311-75/+30
| | | | | | | Fix spec compliancy of the put() method. Change-Id: Iab4f4040cc7308d0c8d9f2eed239af98b7c2eee2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Implement IsConstructor for Function objectsLars Knoll2018-08-231-12/+4
| | | | | | | | Use the jsConstruct member in the function object for this and set it to a nullptr for methods that are not a constructor. Change-Id: I63d2971b23b2596a8e3b6d2781f0d9ed3208693b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix bugs in ArrayBuffer.prototype.sliceLars Knoll2018-08-231-0/+20
| | | | | Change-Id: I6de8031a04c372a5309a878811da55b93b53da3d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Implement ObjectIterator using the new iteration mechanismLars Knoll2018-08-021-71/+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/+72
| | | | | | | | | | | | | | | | | 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>
* Fix a cornercase for instanceofLars Knoll2018-08-011-1/+3
| | | | | | | | | It's possible to define a getter function for the prototype property of Function objects. Ensure this doesn't mess up things by not taking shortcuts. Change-Id: Id981f3080f5c5c0714a1b7b6de27b4af04e794c8 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Make Array.prototype.concat comply better with the specLars Knoll2018-07-301-0/+27
| | | | | | | | There are still some failures in the test cases, but at least less than before. Change-Id: I5bad4ddb1e9d6fe120e981f806a6d986fd43b64d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Implement support for new.targetLars Knoll2018-07-031-1/+1
| | | | | | | | | Support the new.target meta property in the codegen, and add support for passing the newtarget into the constructor vtable methods and the execution context. Change-Id: I62ea58e5e92d894035a76e35776203e9837c383b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Prefix vtable methods with virtualLars Knoll2018-07-031-19/+19
| | | | | | | | | 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>
* Unify the managed and object vtablesLars Knoll2018-07-031-6/+5
| | | | | | | | | | Allow for nullptr entries in the vtable. To nevertheless get some decent error checking if one of the methods is reimplemented, use a base class for Managed that contains a full set of the vtable entries all being nullptr's. Change-Id: Ibc53973b539f87331e8e465a6c44436a30acbefd Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Clean up the property key API in StringOrSymbolLars Knoll2018-07-021-10/+9
| | | | | | | | | | | | | | Get rid of makeIdentifier(), as toPropertyKey() will take care of it. Rename identifier() to propertyKey() and check that the key is valid. Remove String/StringOrSymbol::asArrayIndex(), we don't need it anymore. Change-Id: I3c490fabc1475c9ea288b49b1638b6fa1bc237b7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Replace Identifier by PropertyKeyLars Knoll2018-07-021-12/+12
| | | | | | | | 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>
* Cleanups in the Identifier APILars Knoll2018-07-021-6/+6
| | | | | | | | | | Rename from/asHeapObject to from/asStringOrSymbol and fix the signature. Add a isStringOrSymbol() method and redefine isValid() to also include array indices. Change-Id: Ic8272bfbe84d15421e2ebe86ddda7fdaa8db4f3e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Unify the get and getIndexed vtable functions of QV4::ObjectLars Knoll2018-07-021-16/+13
| | | | | | | | 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>