Commit Graph

226 Commits

Author SHA1 Message Date
Joni Poikelin 7a518d8541 Fix crash when instantiating new QObject object through QMetaObject
Task-number: QTBUG-55691
Change-Id: I3472299e6a963a485be082c9522f1b48fb6c34c3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-09-03 13:01:29 +00:00
Erik Verbruggen 86f81f48c6 QML: In QV4::QObjectWrapper, use QQmlPropertyData to read values
Change-Id: I3abd38788958eed48c04df18b915716d9a72b3aa
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-26 07:34:17 +00:00
Erik Verbruggen 86a55cdb8c QML: Make all fields in QQmlPropertyRawData private
And add accessors. This makes it easier later on to change the storage
of the fields.

Change-Id: I21163668ac83a7d52f398981baf3c27ef161c177
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-10 14:21:15 +00:00
Erik Verbruggen 107a52b8a7 QML: Split off value type information from property data
Change-Id: I2ae2fb0f18af9b866cc9482fd4f42d9d4269f8cb
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-09 08:06:16 +00:00
Christian Kandeler 3e5152be41 QJSValue: Adapt to introduction of QMetaType::Nullptr
[ChangeLog][QtQml][Important Behavior Changes] A JS null value converted
to a QVariant now has type QMetaType::Nullptr rather than
QMetaType::VoidStar.

Change-Id: I91a64e444ada0f1884fe807f9973348ba1a878ff
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-08 12:45:38 +00:00
Erik Verbruggen edb1c204c3 QML: Change the property data flags into a bit field
This will make it easier in follow-up patches to add or remove flags. It
also shrinks the flags, because each type doesn't need its own bit (as
those are mutually exclusive).

Change-Id: I5ba6de5f330eb20c82aa16b4467ed6c952725979
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-05 07:51:51 +00:00
Erik Verbruggen 1534dd6d97 QML: Introduce QQmlPropertyIndex
This helps in making it clear when an index is a plain old number and
when it consists of an encoded value type index.

Change-Id: Ic50d95caf244ed0ee2d62bdba53910a371cfee04
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-04 12:11:05 +00:00
Erik Verbruggen ac326046e1 QML: Fix property notifier registration for constant properties
Constant properties typically do not have change notification signals,
so do not attempt to listen to those.

Change-Id: I4b3622d014aa2f8b3794a63f78ada9806c53966b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-19 12:32:48 +00:00
Erik Verbruggen 0d7dd44d78 QML: Clarify a parameter's usage in QQmlPropertyCache
Give the template type a fitting name, use a parameter name that is
slightly more descriptive than "dummy", and pass it around by pointer
like we do in other places.

Change-Id: Ie7051a6053fc8d2f9c3ea92ee3ce18e57dc5e62a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-06 09:31:08 +00:00
Erik Verbruggen 3dfd47362f QML: Specialize bindings based on target property type.
When we can determine the type of a target property during type
compilation, we can skip a whole bunch of code that deals with
converting the result of a binding to the correct (target) type.

This removes 65 instructions on x86 for such typed bindings.

Change-Id: Id2c7c57b9ae6dfbeb921121beae9630604ca1d17
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-06-27 06:20:23 +00:00
Erik Verbruggen 702c4247d7 V4: Pass scope around as parameters inside the runtime.
The implementation of many (or all) runtime functions consist of first
creating a QV4::Scope, which saves and restores the JS stack pointer.
It also prevents tail-calls because of that restoring behavior. In many
cases it suffices to do that at the entry-point of the runtime.

The return value of a JS function call is now also stored in the scope.
Previously, all return values were stored in a ScopedValue, got loaded
on return, and immediately stored in another ScopedValue in the caller.
This resulted in a lot of stores, where now there is only one store
needed, and no extra ScopedValue for every function.

Change-Id: I13d80fc0ce72c5702ef1536d41d12f710c5914fa
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-06-22 11:07:05 +00:00
Corentin Jabot 8c8ec31b7a Add QJSEngine::newQMetaObject
QJSEngine::newQMetaObject let us expose QMetaObject to the QJSEngine,
allowing to construct QObjects instance from javascript.

Additionally, enums values are exposed as property of the QMetaObject
wrapper.

(The engine takes ownership of the created objects)

Change-Id: I5428d4b7061cceacfa89f51e703dce3379b2c329
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-06-05 15:25:40 +00:00
Liang Qi 8ae479a8ea Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/jsruntime/qv4engine_p.h
	src/qml/jsruntime/qv4runtime_p.h
	src/qml/qml/qqmldelayedcallqueue.cpp
	src/qml/qml/qqmlvaluetypewrapper.cpp
	src/qml/qml/qqmlvmemetaobject.cpp
	src/qml/qml/v8/qv8engine_p.h
	tests/auto/quick/qquicktext/tst_qquicktext.cpp

Change-Id: I3f0608c7beb88088cbbef4d0db59920f56deaea9
2016-05-24 14:00:39 +02:00
Erik Verbruggen 41a426d781 V4: create a fast-path for QObjectWrapper::wrap
The typical case is that there's already a QQmlData for a QObject, so
fast-path this, and fall back to the general case if there is none (or
it is deleted, etc.)

Change-Id: I00c890e5fe7abdd743c4e99316a7ce93eb3db9df
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-20 11:15:00 +00:00
Liang Qi ae745746a6 Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/jsapi/qjsengine.cpp
	src/qml/qml/qqmlengine_p.h
	src/quick/items/qquickanchors.cpp
	src/quick/items/qquickanimatedimage_p_p.h
	src/quick/items/qquickitem_p.h
	tests/auto/qml/qqmlecmascript/testtypes.h
	tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
	tests/benchmarks/qml/creation/tst_creation.cpp

Change-Id: I65861e32f16e8a04c7090a90231627e1ebf6ba6f
2016-05-13 08:28:27 +02:00
Frank Meerkoetter 4be62189a1 Scrape off some more allocations by using the QStringBuilder
Change-Id: I25cbbcad086afb15694f69bdc52bd4ddce4b3a18
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-09 13:21:31 +00:00
Liang Qi da374438be Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/quick/items/qquickimagebase.cpp
	src/imports/layouts/plugin.cpp

Change-Id: I5f48474df4034a1347ec74795c85d369a55b6b21
2016-04-27 08:47:35 +02:00
Michael Bruning 0b7c11e7c2 Also match QJSValue conversion types in MatchScore.
This had the effect that overloaded methods were always mapped to the
wrong slot.

[ChangeLog][QtQml][Important Behavior Changes] When matching the method signature
of a invokable method to the slot in the metaobject, the matching function now
assigns the best match to a QJSValue if the parameter actually is a QJSValue. This
corrects the previous behavior, where QJSValue and int were given the same match score
even though QJSValue would have been the best match.

Task-number: QTBUG-51746
Change-Id: I906e7b006ee5af92ea760ed1625e5047aef123bf
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-04-20 13:38:31 +00:00
Simon Hausmann 8ca22ca7eb Fix invocations of methods taking a QByteArray
Since commit 3b7e2a69f7 when calling a slot that
takes a QByteArray with a parameter that is not a QByteArray, we would end up
passing an empty QByteArray. This is a regression as previously we supported
the conversion code path, i.e. when passing a QString it would be converted to
utf-8, through QVariant's conversion code path. This code path needs to be
re-activated by removing this "shortcut". The shortcut is not necessary as the
execution engine's toVariant() function also knows how to apply the conversion.

Change-Id: I0600d195c94fa4e1e0b7ab807f045f0da42f595b
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
2016-04-12 11:52:49 +00:00
Andy Nichols 60da655dff Merge remote-tracking branch 'origin/5.7' into dev
Change-Id: I57b06e2e98beb010a56dd0593d93e078ecf76eea
2016-04-05 12:11:13 +02:00
Erik Verbruggen bac1268ab0 QQuick: remove property index from the accessor functions.
This parameter was not used.

Change-Id: I1e8c0994cad37fc24105e354a80a4fb0131d58ee
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-03-31 09:01:55 +00:00
Michael Brasser 6cc908e25b Add Qt.callLater() function.
Calling the new Qt.callLater() multiple times in quick succession with the same
JS function as argument will result in a single call to that function, thus
eliminating redundant unnecessary calls.

Based on previous patches by Mathias Malmqvist <mathias.malmqvist@nokia.com>
and Chris Adams <chris.adams@jollamobile.com>

Change-Id: Ie71b60d4d48fa73d3deae723775cf36662d199ae
Task-number: QTBUG-22400
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-03-08 16:45:39 +00:00
Nobuaki Sukegawa 3b7e2a69f7 Convert QByteArray in C++ type to ArrayBuffer in QML and vice-versa
Change-Id: Ie4e29a443a17826a3ce4d1e1912bd35dc497ac78
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-03-05 08:26:29 +00:00
Liang Qi 4e7f570f92 Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/quick/items/qquickitem.cpp
	tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
	tests/auto/quick/qquicklistview/tst_qquicklistview.cpp

Change-Id: I3cf47faa2fe567d62fffd985aeecbefe5811cc42
2016-02-19 12:59:04 +01:00
Simon Hausmann d444d21a51 Fix crash in Installer Framework when used with Qt 5.6
IFW uses QQmlV4Function in a QJSEngine environment, so there is no QML context.
Up to commit cc98678f40 that would work. Let's
fall back to the root context as scope if we don't have a qml context.

Change-Id: Ib240746a95a0d16d61620f97abc31e4c74f36723
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-02-02 13:08:51 +00:00
Jani Heikkinen 45bd04ba73 Updated license headers
From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/

Updated license headers to use new LGPL header instead of LGPL21 one
(in those files which will be under LGPL v3)

Change-Id: Ic36f1a0a1436fe6ac6eeca8c2375a79857e9cb12
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-19 14:53:18 +00:00
Liang Qi 6c090cd8d0 Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
	src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.h
	tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
	tests/auto/quick/qquicktextedit/qquicktextedit.pro
	tests/auto/quick/qquicktextinput/qquicktextinput.pro

Change-Id: I95d2c20a8619e5b8fa361c941a16dd8dce3e04e7
2016-01-10 20:45:46 +01:00
J-P Nurmi 9c4621217f Revert "Fix QtSharedPointer::ExternalRefCountData object leaks"
This reverts commit 839d2d3e23, which has
been causing crashes in qtquickcontrols2 auto tests and making it nearly
impossible to integrate anything over the past few days.

Change-Id: I570b286a067aae5e3c2d8c56ad601e1a6cb58c20
Task-number: QTBUG-50134
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-12-23 18:19:57 +00:00
Liang Qi 9f38956fc9 Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
	tests/auto/quick/qquicklistview/tst_qquicklistview.cpp

Change-Id: I9588a3e2c7d590e031dd4c66905a79f0d74d3ac8
2015-12-18 19:17:30 +01:00
Jian Liang 839d2d3e23 Fix QtSharedPointer::ExternalRefCountData object leaks
Call destroyObject() for every QV4::Heap::QObectWrapper object in heap in
QV4::MemoryManager::sweep() to make sure the QPointer object contained in
QV4::Heap::QObjectWrapper is properly destructed.
We also keep track of QObjectWrapper in QV4::Heap::ModelObject to make
sure we destory them in QV4::MemoryManager::sweep()

Change-Id: I3b3e96cfc300c2e21ab691762879ac2970afa90c
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-12-18 15:52:43 +00:00
Liang Qi f9ef039ad9 Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
	src/qml/debugger/qqmldebug.cpp

Change-Id: I93de5a81b18cdece475870cf7cfba1b9baef2304
2015-09-25 20:56:51 +02:00
Lars Knoll 52fb4685e9 Cleanups
Change-Id: I68b5253eafc0f3786e4aa671b388a8f4c78c9ed7
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:40:07 +00:00
Lars Knoll 6565e78610 Reduce memory consumption of signal handlers
Move the connect/disconnect methods for signal handlers into
their prototype, so that we don't need to define them per instance
anymore.

Change-Id: Iac1e6d1dd7bce86730dbb6c51e2c3f79713641f7
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:40:03 +00:00
Lars Knoll f4ccd46569 Smaller cleanups
Change-Id: I68f7ea476cb00a571908b7ec0a036f8517b091d5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:39:52 +00:00
Lars Knoll 13edffa303 Move remaining objects to new constructor syntax
Also disable the old way of constructing objects.

Change-Id: Ib4e69087cd563ae1481da116d6caf97876239798
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:13 +00:00
Lars Knoll 2a8de9d8d8 Convert FunctionObjects to new allocation syntax
Change-Id: I269c20abdc7f9eb0d71a2d2d485d622b65405762
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:09 +00:00
Lars Knoll fb52dab6b4 Further cleanups
Reduce usage of ScopedContext.

Change-Id: I84a6a7478065de3398fd0b21596ca1308e78ceb3
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 19:12:40 +00:00
Ulf Hermann 6e295437ca Decode signal signatures as UTF-8 rather than Latin1
QML source code is supposed to be in UTF-8, including signal
specifications.

Change-Id: Ic2d0aef579addabf39b3910393a77989130bc11a
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 10:20:43 +00:00
Lars Knoll 830376c962 Rename currentExecutionContext to currentContext
Now that the other method is gone, let's use
the shorter currentContext

Change-Id: I2a6fb3b77f83a1ffdf314ad29081e303d17030ed
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:26 +00:00
Lars Knoll 0e6195a85c Cleanup usage of ExecutionEngine::currentContext
Change-Id: Ic79d6da162375928ec25871cd0341daeab6483d2
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:22 +00:00
Lars Knoll cc98678f40 Use the QmlContext as the scope for QQmlV4Function calls
This further reduces our dependency on the QQmlContextWrapper
and reduces storage requirements in the QObjectMethod.

Change-Id: I2c12d0a8818d81d45139f482caac8510ad8dfddc
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-20 20:01:18 +00:00
Ulf Hermann eb30e3d7ee Merge remote-tracking branch 'origin/5.5' into 5.6
Conflicts:
	src/qml/debugger/qv4debugservice.cpp
	src/qml/jsruntime/qv4value_inl_p.h
	src/qml/jsruntime/qv4value_p.h
	src/qml/memory/qv4mm.cpp
	src/qml/memory/qv4mm_p.h
	src/qml/qml/qqmlnotifier_p.h
	src/qml/qml/qqmlproperty.cpp
	src/quick/items/qquickflickable.cpp
	src/quick/items/qquicktextedit.cpp
	tests/auto/quick/qquickwindow/BLACKLIST

The extra changes in qqmlbinding.cpp are ported from changes to
qqmlproperty.cpp that occurred in parallel with writeBinding() being
moved to qqmlbinding.cpp.

Change-Id: I16d1920abf448c29a01822256f52153651a56356
2015-08-18 10:29:47 +02:00
Sérgio Martins b557201079 qml: Avoid heap allocations due to QString::fromLatin1()
By using QStringLiteral when the argument is a literal.

Change-Id: Ib25042d10f3d9d0aca81af74cde0107aba4f9432
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2015-08-13 16:11:48 +00:00
Lars Knoll c1667cd727 destruct qobject wrappers before sweeping the GC heap
The wrappers emit a destroyed signal, and it's important
that the GC heap is in a well defined state when these signals
are emitted.

Change-Id: I423c4241b1e2fd3de727277d26bbe64f08862193
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-10 07:24:36 +00:00
Lars Knoll b288956817 Use the QmlContext to access properties of the scope object
Add some runtime methods to access properties of the scope
object directly (using the QmlContext), and generate proper
code to call those.

Change-Id: I0b29357c9a3b9ad53ba568ec6cb763e8ecb10f21
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-10 01:21:57 +00:00
Thiago Macieira 60007e4a9d Use the new macros for disabling warnings in qtdeclarative
Change-Id: I476da50ba23598c7ca98651477fb701f74053b82
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
2015-07-28 23:59:04 +00:00
Erik Verbruggen 92836d052e Remove type punning from QV4::Value.
The union in QV4::Value is used to do type punning. In C++, this is
compiler-defined behavior. For example, Clang and GCC will try to detect
it and try to do the proper thing. However, it can play havoc with Alias
Analysis, and it is not guaranteed that some Undefined Behavior (or
Compiler depenedent behavior) might occur.

The really problematic part is the struct inside the union: depending on
the calling convention and the register size, it results in some
exciting code. For example, the AMD64 ABI specifies that a struct of two
values of INTEGER class can be passed in separate registers when doing a
function call. Now, if the AA in the compiler looses track of the fact
that the tag overlaps with the double, you might get:

    ecx := someTag
    ... conditional jumps
double_case:
    rdx := xorredDoubleValue
    callq someWhere

If the someWhere function checks for the tag first, mayhem ensues: the
double value in rdx does not overwrite the tag that is passed in ecx.

Changing the code to do reinterpret_cast<>s might also give problems
on 32bit architectures, because there is a double, whose size is not the
same as the size of the tag, which could confuse AA.

So, to fix this, the following is changed:
- only have a quint64 field in the QV4::Value, which has the added
  benefit that it's very clear for the compiler that it's a POD
- as memcpy is the only approved way to ensure bit-by-bit "conversion"
  between types (esp. FP<->non-FP types), change all conversions to use
  memcpy. Use bitops (shift/and/or) for anything else.
- only use accessor functions for non-quint64 values

As any modern compiler has memcpy as an intrinsic, the call will be
replaced with one or a few move instructions. The accessor functions
also get inlined, the bitops get optimized, so in all cases the compiler
can generate the most compact code possible.

This patch obsoletes f558bc4858 (which had
the exact aliassing problem of the double and the tag as described
above).

Change-Id: I60a39d8564be5ce6106403a56a8de90943217006
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
2015-07-24 11:44:05 +00:00
Lars Knoll 5f162e17ed Cleanup retrieval of scope and context objects
Change-Id: I9c6174181f950bc4f829727dc6acdfe82fa4e894
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-18 18:24:34 +00:00
Lars Knoll bc045ae542 Cleanup signature of get/setProperty in the object wrapper
Change-Id: I3612a8fe952656da2239e4baf0b460bef46e3f62
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-18 18:24:26 +00:00
Lars Knoll 1d76a5d3ea Simplify property capturing code
No need to inherit from a base class defined in QQmlEnginePrivate.
The capture handling can be a simple value based class without
virtual methods that is allocated on the stack.

Change-Id: Ib0ddf4afcaf154b3f953d8c9322f5bec196d7abf
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-18 14:41:13 +00:00