Commit Graph

146 Commits

Author SHA1 Message Date
Ulf Hermann c4addf7d0e Pass QMetaType by value rather than by ID in more places
This saves us some ping-pong between the IDs and the QMetaTypes, and
avoids possible ambiguities if multiple metatypes are registered for the
same C++ type.

Change-Id: I81cec94a9cd05d69927dc884f65574f0ab2ddc22
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-09 14:47:13 +02:00
Fabian Kosmale d009c0088b QV4::Engine::toVariant: Use metatype instead of metatype id
This way, we can avoid the costly id to metatype lookup in case where we
actually need the full metatype.

Task-number: QTBUG-88766
Change-Id: Ibe29b323007f00d2f8d1807fb9b64f9a8f87e807
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-25 21:25:28 +01:00
Ulf Hermann eb2386a042 Optimize ExecutionEngine::metaTypeToJS()
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>
2021-03-13 10:08:48 +01:00
Ulf Hermann f0908255c9 QtQml: Integrate sequences with registration macros
You get to write QML_SEQUENTIAL_CONTAINER(value_type) now, and
qmltyperegistrar will generate a sensible registration call from that.
A registration might look like this:

struct MyStringListForeign
{
    Q_GADGET
    QML_ANONYMOUS
    QML_SEQUENTIAL_CONTAINER(QString)
    QML_FOREIGN(MyStringList)
    QML_ADDED_IN_VERSION(3, 1)
};

It's unfortunate that we need to use a metaobject to transfer all of
this information, but there is no other sensible way.

Transform the containers defined in qv4sequenceobject.cpp to use the new
style, and move them out of the builtins, into QtQml. Recognize that
only one of them was ever tested, and add tests for the rest.

Task-number: QTBUG-82443
Change-Id: I3a30f9e27266bb575eea26c5daf5dad1ec461cc5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-11 11:37:49 +01:00
Ulf Hermann d621027bab V4: Rewrite qv4sequenceobject based on QMetaSequence
This avoids the template explosion and makes the mechanism extendable.
You can now register additional anonymous sequential containers.

Fixes: QTBUG-71574
Task-number: QTBUG-82443
Change-Id: I5b9ed9af1533a3b7df8fc5bb37bbb73b8304e592
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 13:21:09 +02:00
Ulf Hermann 47313e5181 Rename QQmlQPointer to QV4QPointer
You can wrap QObject pointers in plain JavaScript.

Change-Id: I246a72a7d5d7b2562e722bf9eafc7880b772a806
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-21 12:03:30 +02:00
Ulf Hermann e60ac3f16a Rename QQmlSequence to QV4Sequence
This feature is available without QML, in pure JavaScript.

Change-Id: Iec8a52ed10ed3eeaec24d3955c8c132bf2bd9677
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-21 12:02:36 +02:00
Volker Hilsheimer 49c97ed1bd Fix build after QStringList change in qtbase
Change-Id: I258bcd59e7e97e025fa9ff77594bd8fdba0c34dd
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2020-09-15 13:32:47 +02:00
Fabian Kosmale f31a2dc6fc Check in even more places for exceptions
Amends commit 4c5ed04e64

Task-number: QTBUG-83384
Pick-to: 5.15 5.12
Change-Id: I0918c27dfa73dff83cbf0f58b41ce8620dff8a0a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2020-04-21 20:10:59 +02:00
Qt Forward Merge Bot 499c6ed78d Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I3058a6b9347d7ca2a0c04a58cb030ae5c47de415
2020-01-15 12:18:57 +01:00
Qt Forward Merge Bot 8a22c92b55 Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
	src/imports/folderlistmodel/plugin.cpp
	src/imports/layouts/plugin.cpp
	src/imports/localstorage/plugin.cpp
	src/imports/models/plugin.cpp
	src/imports/particles/plugin.cpp
	src/imports/qtqml/plugin.cpp
	src/imports/qtquick2/plugin.cpp
	src/imports/shapes/plugin.cpp
	src/imports/statemachine/plugin.cpp
	src/imports/testlib/main.cpp
	src/imports/wavefrontmesh/plugin.cpp
	src/imports/window/plugin.cpp
	src/imports/workerscript/plugin.cpp
	src/qml/jsruntime/qv4sequenceobject.cpp
	src/qml/qml/qqmlengine.cpp
	src/qmlmodels/qqmlmodelsmodule.cpp
	src/qmlmodels/qqmlmodelsmodule_p.h
	src/qmlworkerscript/qqmlworkerscriptmodule.cpp
	src/qmlworkerscript/qqmlworkerscriptmodule_p.h
	src/quick/items/qquickitemsmodule.cpp

Change-Id: I5f1fbc3d00e8f583d2c89afc5389de84d68633a7
2020-01-14 11:24:11 +01:00
Ulf Hermann e5ddcab385 SequenceObject: Better message when trying to write readonly container
Before it would only output "Type Error".

Change-Id: Ibd3a85f327c3ce8c58295c7e900c516b77c85a2b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-01-09 15:24:48 +00:00
Ulf Hermann d9fe0f3667 qv4sequenceobject.cpp: Add "here be dragons" comment
No one should remove this at() before Qt6.

Task-number: QTBUG-80535
Change-Id: I464c6f675dc68ad9762fcb594bb4d6ba6bdaf316
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-12-11 12:36:38 +01:00
Ulf Hermann fb54af6638 qv4sequenceobject.cpp: Use operator[] rather than at()
at() does a range check on the argument. There is no reason to do this
here, and for std::vector this can trigger an exception with interesting
compiler bugs attached to it.

Task-number: QTBUG-80535
Change-Id: I186262de89074a93e68cacec4fba31cc8b8108c8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-12-09 10:46:24 +01:00
Lars Knoll 893100fba3 Fix build after QList->QVector changes in qtbase
Change-Id: I1575c247de26ba08fba349bf879ed3e017530975
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-10-31 10:44:44 +01:00
Tasuku Suzuki 89c9418621 Fix build without features.itemmodel
Change-Id: Ia4304644a2a365c359eed31c55c2ca9d7d42f10c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-07-08 18:42:26 +09:00
Lars Knoll 009a125d07 Fix ownKey iteration over Proxy objects
Change-Id: I045a4844c06df9232cc8b04485ab0a39bb990e3f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-09-09 15:52:02 +00:00
Lars Knoll a88f01364e Implement ObjectIterator using the new iteration mechanism
And with that get rid of the old advanceIterator methods.

Change-Id: I969fa89d25df8992a4b08c8c081b91c92ffdfddd
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-08-02 20:25:55 +00:00
Lars Knoll 0754f55287 Introduce a new mechanism to iterate over object properties
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>
2018-08-02 20:25:41 +00:00
Lars Knoll 61440411a9 Prefix vtable methods with virtual
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>
2018-07-03 08:08:35 +00:00
Lars Knoll 86f88521fb Replace Identifier by PropertyKey
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>
2018-07-02 19:29:40 +00:00
Lars Knoll db695c5b1d Unify the get and getIndexed vtable functions of QV4::Object
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>
2018-07-02 19:29:29 +00:00
Lars Knoll 98263a0137 Unify put and putIndexed
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>
2018-07-02 19:29:25 +00:00
Lars Knoll 53adb5bbc6 Unify deleteProperty and deleteIndexedProperty vtable methods
Change-Id: I25245818c6ff2104642594476cb9684bac824f29
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-06-26 10:03:46 +00:00
Simon Hausmann d258c904a6 Throw type errors when attempting to mutate read-only sequence properties
Calling for example Qt.application.arguments.push("...") should throw an
exception.

Task-number: QTBUG-67774
Change-Id: Ifd5cd3357dde510cca77b9b32c9f55f8f72837ff
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-02 15:46:26 +00:00
Lars Knoll 278b144a35 Disambiguate different allocation functions in the memory manager
Some compilers (in this case MingW 5.3) don't manage to properly
disambiguate the template overloads, and try to instantiate the
wrong template function.

Solve this by renaming the one of the template functions.

Change-Id: I3574e617fe96c4bd52920a0127a1dfe39cc3d302
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:58:48 +00:00
Shawn Rutledge 499ec43937 use nullptr consistently (clang-tidy)
From now on we prefer nullptr instead of 0 to clarify cases where
we are assigning or testing a pointer rather than a numeric zero.

Also, replaced cases where 0 was passed as Qt::KeyboardModifiers
with Qt::NoModifier (clang-tidy replaced them with nullptr, which
waas wrong, so it was just as well to make the tests more readable
rather than to revert those lines).

Change-Id: I4735d35e4d9f42db5216862ce091429eadc6e65d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-02-26 07:13:18 +00:00
Lars Knoll 4e1512baf6 Convert more builtin functions to use the new calling convention
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>
2018-01-12 07:04:27 +00:00
Lars Knoll e72306a6f2 Further cleanup JSCallData
Avoid allocations on the JS stack if possible

Change-Id: I344cd6dceb6264314f9d22c94db22b22d1d24d14
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:48 +00:00
Lars Knoll bc5ff76e5a Simplify JSCallData construction
Change-Id: Ic53532edae9a209aa7125af6f00a9d993d74f1a3
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:44 +00:00
Lars Knoll a59d9a7eac Get rid of JSCallData::call()
Change-Id: I6b99e9a7102b3dcb6a7699f54b6456eba6248699
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:37 +00:00
Lars Knoll c6c79644dc Rename JSCall to JSCallData
As, this is going to change in a simple stack based structure
to keep pointers to the data to pass to calls.

Change-Id: Ia9aa3f81ee3eeba36affd16aac7b2fe97d59aea9
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:26 +00:00
Erik Verbruggen 042aa2eb0e Change CallData::argc to be a QV4::Value
Instead of mimicking a Value. This makes sure that argc now stays
correct even when anything on Value changes.

Most of the change is mechanical: replace callData->argc by
callData->argc().

Change-Id: I521831ae1ffb3966bad6589c18d7a373e13439d7
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-09-19 09:44:33 +00:00
Lars Knoll 74c8fe8675 Always set the correct FunctionObject when calling JS functions
Renamed ScopedCallData to JSCall, enforced passing a JS
FunctionObject to it, and added call() and callAsConstructor()
methods to it.

Change-Id: I30db65c9765c2896b5909fe2105c0934c6dad861
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-09-02 07:12:17 +00:00
Lars Knoll aa8f956e8d Move ScopedCallData and ScopedStackFrame into a separate file
Change-Id: I9ae42aa7a811aa93fe0950725e9d253a0c5e8dba
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-09-01 12:31:19 +00:00
Lars Knoll 4e0174a88e Move line number information into a side table
Don't emit any Line instructions anymore, and instead store
the info in a side table in the compiled data, where it can
be looked up on demand.

Change-Id: Idcaf3bf4ee4129fd62f9e717bf1277dc6a34fe19
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-08-25 12:05:59 +00:00
Lars Knoll 4acb72bf35 Cleanup naming of Stack frame structures
Change-Id: I0b392040b6726e6d93f237ccccc9f053256ed819
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-08-10 08:20:15 +00:00
Lars Knoll 50e7badd5f Remove Scope::result and convert calling convention for builtins
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>
2017-08-08 18:58:14 +00:00
Lars Knoll 7835060518 Fix frame handling
Fix some regressions introduced by change
1ae1eaf59e0475a2dc9c5e22e53e9be19d0f2feb.

Change-Id: I24c1db78634e3beb1ab090325b60e70f788f92a7
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-08-04 08:59:54 +00:00
Lars Knoll c0f961cd6b Change function signatures for call/construct back
Change those back again to return a value. This will be required
to avoid creation of Scope objects between JS function calls.

Change-Id: I05cb5cf8fd0c13dcefa60d213ccd5983fab57ea3
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-08-04 07:08:19 +00:00
Lars Knoll be70a025c1 Don't store the current line number in the ExecutionContext
Instead modify our StackFrame struct to hold the
QV4::Function and have a linked list of those for
the frames.

Change-Id: I8676e16bc51a5ba6cf25a5b3423576d44e8a926a
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-08-04 07:08:02 +00:00
Ville Voutilainen 4be29bdbd5 Don't wrap std::vector into a QVariant when passing it to a Q_INVOKABLE
Task-number: QTBUG-60386
Change-Id: Idd5a8939a575c254636042b5cb1900d2d8673072
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-04-27 14:31:41 +00:00
Ville Voutilainen c50113aaf4 Add support for std::vector and QVector matching the support for QList
Task-number: QTBUG-60133
Change-Id: I5497dc3c4a1c3922e7147d7a20593c75a0d9d0e9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-04-21 17:15:07 +00:00
Robin Burchell 5f83e6dfe6 Object: Allow put and putIndexed to return success or failure
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>
2017-02-09 14:53:01 +00:00
Lars Knoll 25552c1404 Convert more builtin functions to the new calling convention
Change-Id: I053215261e1186aff25f29e0967219ef667f7678
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:31:28 +00:00
Liang Qi f5da1a9261 Merge remote-tracking branch 'origin/5.7' into 5.8
Conflicts:
	src/quick/items/qquickitemsmodule.cpp
	tests/auto/quick/rendernode/tst_rendernode.cpp

Change-Id: I90582df69feb95a4e4aafb0b9793c23714654f19
2016-10-20 08:28:16 +02:00
Allan Sandfeld Jensen f63ad7c63b Fix gcc6 build
Complete the patch for tautological-compare warnings after it was
merged form 5.6.

Task-number: QTBUG-56266
Change-Id: I39f25f429b90deb8d8830fb15f45ce29a5a4c51c
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
2016-10-16 19:07:00 +00:00
Simon Hausmann 0426400424 Merge remote-tracking branch 'origin/5.6' into 5.8
Change-Id: I175b27337b534c0b8f46a4a792d2c43cde73ffc4
2016-10-13 14:40:30 +02:00
Liang Qi b4cdfc4a12 Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: Ib31008e593442ca5813fb14ae6b02f7ab2577395
2016-10-12 20:49:45 +02:00
Allan Sandfeld Jensen 376077a8e7 Fix developer-build with gcc 6
Locally suppress bogus tautological compare warnings.

Task-number: QTBUG-56266
Change-Id: Ic1b554982a778cdd89c8047483523c44d53bbadd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2016-10-10 04:41:42 +00:00