Commit Graph

50 Commits

Author SHA1 Message Date
Roberto Raggi d00fbd043e Don't rewrite the body of function expressions
That is, don't look inside function expressions when rewriting
bindings as closures.

Task-number: QTBUG-25901
Change-Id: Ia4b99d3c58c4482e9505cf2461bd14942a9a00ca
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
2012-05-25 11:32:45 +02:00
Aaron Kennedy d2e557c2c2 Lazily create QMetaObjects
For internal QML built types, creating a metaobject each time is
just wasteful.  Additionally, as the property caches were always
created from the intermediate QMetaObject, it was difficult to pass
information directly from the compiler to the property cache.

Change-Id: I769526b0edaaf16a86883f3065b75618b94e4077
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-05-24 12:52:43 +02:00
Andrew den Exter 4709f30b26 Enable binding to properties of type QJSValue.
This allows javascript objects of all types to be bound to properties
declared in c++.  Compared to a QVariant the primary benefit this offers
is a type which functions and objects with functions can be bound to.

Change-Id: Idb3313e7ff1d616ab12d44f616083c8296201f3a
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
2012-05-24 05:52:32 +02:00
Matthew Vogt e574e9adca Remove default parenting in Qt.createComponent()
Remove the default parent applied to component instances created by
Qt.createComponent().  This allows these objects to be managed by usual
JS reference management, and thus to be appropriately garbage
collected.

Task-number: QTBUG-24841
Change-Id: I29efbb9d8f5a2ef4c74415399fa3024e6590004b
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-05-24 00:23:43 +02:00
Matthew Vogt a96705e349 Allow the existence of a VME metaobject to be asserted
Test for the existence of a VME metaobject.  Otherwise, assertion of
a static cast result is not meaningful.

Change-Id: Ic9e9c38e5dce65c41d20e405c33e179334c37b00
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-05-21 00:17:37 +02:00
Chris Adams ea13e0cf3f Ensure that we don't attempt to dispose handle twice
If a weak ref callback causes disposal of a v8object associated with
a qobject, the later qqmldata::destroyed() handler could cause a
double dispose, due to 753d9f4be5.

Change-Id: I07c1c8e2e7b444a7e873da26bc4d0c19bcfe57b5
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
2012-05-16 05:53:49 +02:00
Chris Adams e1c26307c2 Revert "Allow function assignment to cause binding for non-var props"
This reverts commit 92b1f9981d.

Conflicts:

	src/qml/qml/v8/qv8qobjectwrapper.cpp

Also remove XPASS tests from qjsonbinding

Change-Id: Ibc9da28d5f0bdffbf62e7e20f12bb55ff36ae271
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
2012-05-15 09:16:41 +02:00
Aaron Kennedy 5570040771 Permit signals to be emitted in a different thread
The QQmlNotifier approach to connecting to signals did not
support the cross-thread signal/slot model used elsewhere in
Qt.  This change allows one specific case of that - emitting
a signal in a different thread than the one the QObject
lives - to work.

Task-number: QTBUG-25647
Change-Id: Ia8fdaf4c7d7e2ccd7ff7657bb1d8e26277eb60aa
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
2012-05-11 17:23:20 +02:00
Chris Adams 029e510256 Fix edge case in signal emission semantics
Signal emission triggered by property changes during an onDestruction
handler was previously not well tested.  This commit adds several
unit tests to ensure correct behaviour in that situation.

Those unit tests showed a problem in signal emission related to when
children objects are cleaned up.  This commit also ensures that if
such children own their own context, their onDestruction handlers
are called prior to marking the child as deleted.

Change-Id: Ibf84ae56ba1134e5d6402b742aee1bdc0e5e4e15
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
2012-05-09 00:56:16 +02:00
Michael Brasser c4fab1011b Remove QQmlData::objectNameChanged callback.
The objectName property now has a proper NOTIFY signal. Also
remove the objectName accessor, as it is no longer required.

Task-number: QTBUG-23526
Change-Id: Ib18ba7335bf62a2fe2a9e489cb4c0f1fb142d74c
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-05-09 00:56:16 +02:00
Thiago Macieira 44f9412bf7 Change uses of {to,from}Ascii to {to,from}Latin1
This operation should be a no-op anyway, since at this point in time,
the fromAscii and toAscii functions simply call their fromLatin1 and
toLatin1 counterparts.

Task-number: QTBUG-21872
Change-Id: I03084595ddc425a988374b8352fd23e9504ffba6
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
2012-05-04 10:36:17 +02:00
Matthew Vogt 186abc1e08 Ensure binding target has not been deleted
Prevent the evaluation of bindings if the target has been deleted.
Also, mark an item as queued for deletion at the beginning of the
destructor call chain, so that bindings triggered by the operation
of the destructor itself are not evaluated (after the context is
destructed, if necessary).

Task-number: QTBUG-25516
Change-Id: I587ef7923eb749eb7980156ad73822c1fb7c1ff3
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-05-04 05:51:29 +02:00
Matthew Vogt c31026c9ca Emit Component.onDestruction before context is invalidated
When a component no longer has any live references, emit the
destruction signal immediately so that handlers are run before the
associated V8 resources are invalidated.  Also, when the root
context of the engine is destroyed, emit the destruction signal
before destroying any resources needed to process the resulting
binding invocations.

Change-Id: I722dd6e4b60c499b533fc45e33b61e95bca6187f
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-05-04 03:41:33 +02:00
Kent Hansen b9ccb579c4 Remove QJS exception API
This API has been deprecated for a while. It's legacy stuff from
QtScript.

Until someone proves that QJSValue::isError() isn't sufficient to
handle JavaScript exceptions, we won't provide any additional API
for that.

Also removed QJSValuePrivate::lessThan(), which was using the
exception mechanism, but the function itself wasn't used anymore
(another remnant from the QtScript days).

Change-Id: I3dffc6a7835874153f90d25ae2a72c93ea6db39a
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
2012-05-03 09:52:41 +02:00
Charles Yin 78f1d26792 Prevent object being delete by GC before object is fully created
Add a new flag inCreation to QQmlData. Set it to true when a top-level object begins creation,
and back to false when initial creation is finished and the object has been marked indestructible.
In the GC callback function, if inCreation is true, skip the GC and make a weak reference for next GC loop.

Change-Id: I4ec82864c52f6be0c3e6ef892474dd77d835e152
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-05-01 03:25:01 +02:00
Jędrzej Nowacki b765e3a84b Avoid calling gc in QQmlEngine destructor.
GC may be expensive. GC call in QQmlEngine doesn't have much sense
because V8 will destroy all objects living in a current context.
The only problem is that V8 may decide to not invoke weak callbacks
which may cause a memory leak. To avoid that we track all QObjects that
have JavaScript ownership set and we delete them explicitly.

The change reduce time of destroying QQmlEngine by 75%, which is really
visible in qquicklistmodel test.

Change-Id: I2a3668fd23630669114baee8c241a7ecc4100e33
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-04-27 10:38:58 +02:00
Kent Hansen c0f07d5707 Specialize for QJson types in the QObject meta-call binding
Avoid falling back to QVariant conversion; make the overload handling
consistent.

Also make the MaxSizeOf template helper class actually compute the
correct size needed for the argument storage.

Change-Id: I04afb378bd89743d542973cc3bb0ceb729b400d9
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
2012-04-26 10:30:57 +02:00
Matthew Vogt 5dac3d9f84 Verify that QML can reliably receive datetime info from C++
Since a JavaScript Date object does not contain any information about
the timezone in which it is specified, a C++ module that exports
datetime information to QML must also provide the relevant timezone
data so that clients can correctly interpret the datetime value.

Provide an example of exporting datetime information to QML, verifying
that the data can be correctly interpreted in JS.

Task-number: QTBUG-25262
Change-Id: I732797da225861470e6b034f2e3d89a43df36cf7
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
2012-04-24 00:33:25 +02:00
Matthew Vogt a8e017fbc2 Record current status of date conversion from QML
Ensure that the qqmlecmascript test is not broken by changes in the
time zone of the test environment.

This test documents the existing situation with convertibility
of date information between QML and JS.

Task-number: QTBUG-25262
Change-Id: I42716e0b34ef26daa391fdb4aebc1f31340fcea0
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
2012-04-24 00:33:00 +02:00
Lars Knoll a896d4b39e Merge remote-tracking branch 'origin/master' into api_changes
Conflicts:
	src/qml/debugger/qqmlprofilerservice_p.h
	src/qml/qml/qqmlboundsignal.cpp
	src/qml/qml/v4/qv4bindings.cpp
	src/quick/items/qquickshadereffect.cpp
	src/quick/particles/qquickcustomparticle.cpp
	src/quick/qtquick2.cpp

Change-Id: Ia9c6517035ae912fa75e77473a452bd3383def56
2012-04-11 16:05:03 +02:00
Aaron Kennedy 8b0831f0b0 Do not execute overwritten bindings
During the construction of an object, internal bindings can be
overwritten by the initialization of objects with outer scope.

Task-number: QTBUG-23138
Change-Id: I46a187d9cdc41f4dd96d068f39788a2255b8888d
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-04-04 13:29:19 +02:00
Aaron Kennedy 7aa4c4164e Don't crash if calling a method on a QObject that has been gc()'d
As we don't actually delete an object immediately when it is collected,
it is possible to get into a situation where a method is called on an
object after the collector has marked it to be destroyed.  This fixes
a crash in this case.

Change-Id: I131d4c5d7ed788a91aa52f6af2e5c089d9bf5e08
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-04-03 16:22:04 +02:00
Michael Brasser 817c0741d1 Allow objects created in QML with incubateObject to be destroyed.
Change-Id: I8a0678ea8dff6f4a40ac367395a99dd025f7f08a
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-04-03 07:50:17 +02:00
Aaron Kennedy 833336fa96 Loosen shared binding tests
Previously we blocked all function calls, but only because we were trying
to prevent "eval" calls from appearing in shared bindings.  Instead this
test allows function calls as long as the identifier "eval" doesn't
appear.

This also exposed a crash with v8 bindings that is also fixed.

Change-Id: I22eefd290c7b82d9c01b2cd2907a46e560ae4db9
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-03-30 12:55:23 +02:00
Kent Hansen 24fb8dc27e Merge master into api_changes
Conflicts:
	src/qml/debugger/qqmlenginedebugservice.cpp
	src/qml/debugger/qqmlprofilerservice_p.h
	src/qml/qml/qqmlboundsignal.cpp
	src/qml/qml/qqmlpropertycache.cpp
	src/quick/util/qquickimageprovider.cpp

Change-Id: I0609aa5ed54c7769f1e2773a96a7cd43a69f133c
2012-03-27 16:56:14 +02:00
Chris Adams d3bcce569f Add templated module api registration function
This commit adds a templated module api registration function which
allows clients to provide type information at registration time.
We use this typeinformation in V4 if available, in order to allow
module APIs to be used in v4 bindings.

This commit also clarifies the ownership semantics of QObject module
apis, and updates some documentation references which were missed
during the rename of Declarative to Qml.

Task-number: QTBUG-24894
Change-Id: Iebb61ca8d8eacbb15218549eab715e22f52a1474
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-03-26 04:55:30 +02:00
Michael Brasser d120c3c383 Support registered QFlags in QML methods and signal handlers.
Change-Id: I2a71122303dcf7af4f07c3ffb73456bcdce62a74
Reviewed-by: Martin Jones <martin.jones@nokia.com>
2012-03-26 02:55:20 +02:00
Kent Hansen 0655209fda Merge master into api_changes
Conflicts:
	src/qml/qml/qqmlboundsignal.cpp
	src/qml/qml/qqmlpropertycache.cpp

Change-Id: I5193a193fa301c0b518291645bf626a5fa07118f
2012-03-23 14:31:47 +01:00
Michael Brasser 91f9f123eb Prevent the root object from being garbage collected.
Passing the root object as a return value from a C++ function could
cause the indestructible flag to be set to false.

Change-Id: Ib70c666f0d0ffbb48bca1996c2517fbccafa5dc1
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-03-23 08:04:08 +01:00
Chris Adams 4c9d326230 Allow literal enum to int property assignments
Previously, enum to int property assignments were considered bindings.
This commit adds support for assigning enum values to int properties
as enums.

Note that to use an enum in QML, it must have been declared with
Q_ENUMS or otherwise registered as a metatype.  Enum values from the
global Qt object are also usable.

Task-number: QTBUG-23403
Change-Id: I50db6cae54a24400ea472bde43619d547e4ceb78
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-03-21 05:18:35 +01:00
Andrew den Exter b2722ab31e Fix consistency of parsing ISO 8601 date strings.
Use the UTC timespec for strings with no time zone qualifier as V8 does
so we don't get different QDateTime in bindings depending on whether
the string was bound directly, or parsed by constructing a new JS
Date object.

Task-number: QTBUG-24895
Change-Id: I8f74dae418aaeeaf06df33fe58ab4e3e3fea791b
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-03-21 04:05:38 +01:00
Matthew Vogt 610df5cdf8 Allow parent to be specified for Qt.createComponent
Add an optional parameter to the Qt.createComponent function which
allows the caller to specify the object that will become the parent
for the created component.

If the parent is not specified by the caller, it becomes the QML
engine; this behavior will change in the near future to allow
these component objects to be collected when no longer referenced.

Task-number: QTBUG-24840
Change-Id: I2742133fe8ab8cbc80d8012a9d9b9fc2e4596fca
Reviewed-by: Martin Jones <martin.jones@nokia.com>
2012-03-20 02:58:26 +01:00
Matthew Vogt c5cd60a96d Ensure JS files imported inside modules work correctly
When a module exports functionality provided by a script, ensure
that imported script modules inside that script resolve correctly.

Task-number: QTBUG-24596
Change-Id: I3885dcc56946423f0d7cf00afdcdfaa0cb11967a
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
2012-03-19 23:20:30 +01:00
Kent Hansen 4821058f10 Merge master into api_changes
Conflicts:
	src/qml/debugger/qqmlenginedebugservice.cpp
	src/qml/qml/v8/qv8qobjectwrapper.cpp
	src/quick/util/qquickimageprovider.cpp
	tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

Change-Id: Ie78ba2fabd32f4812bcae9dbdd66ed289dc11dcb
2012-03-19 12:37:03 +01:00
Miikka Heikkinen 21e228afa7 Windows: Fix file URL issues in declarative autotests
Fixed by using testFileUrl() shared utility function where appropriate
instead of testFile() or various other ways file URLs were being
incorrectly used.

Task-number: QTBUG-24779
Change-Id: I48cbd297d419238f42ea45132344b7e5a487b6f1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
2012-03-15 11:25:36 +01:00
Chris Adams 25793276e5 Fix crash caused by dereferencing collected v8 data
If a var property of a QObject is read after the v8 data associated
with the qobject has been deleted but prior to the DeferredDelete
event being processed, the varProperties array will be null and
a crash will occur.

This patch ensures that we check for this condition in both the
access and set codepaths for var properties, and also ensures
that an object which has previously been queued for deletion cannot
be referenced in JS.

Finally, it adds a unit test to ensure that we don't regress.

Task-number: QTBUG-24748
Change-Id: Idde384ca01e18f4dcf9e376e9379f2c5eb410e14
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-03-15 02:44:40 +01:00
Aaron Kennedy 5ae8caba10 Remove binding dependency on QQmlExpression
This is the first step to creating much lighter weight bindings that
are tuned for the specific scenario in which they're used.

Change-Id: Ib985dcff25679b711b5c634bbc891aa7902bf405
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-03-15 01:33:24 +01:00
Chris Adams b06108350b Ensure that dynamic property storing QObject ptr notifies on delete
Previously, when a QObject ptr was stored in a dynamic variant
property, the value of the property could change (to a zero ptr)
if the QObject was deleted without a notify signal being emitted
by the QDeclarativeVMEMetaObject which stores the property.

This commit ensures that such a notify signal is emitted correctly.

Task-number: QTBUG-23451
Change-Id: I5689abd984b177737f8d5f18950838b73ebde328
Reviewed-by: Martin Jones <martin.jones@nokia.com>
2012-03-15 00:22:45 +01:00
Kent Hansen a27fd584df Let V8 throw the exception when QML property lookup fails
Only V8 knows whether a failed property lookup should actually cause
a ReferenceError to be thrown. When evaluating a "typeof" expression,
for example, a ReferenceError should not be thrown even if the
expression involves global variables that don't exist, according to
the ECMA-262 specification.

QML should try to match the standard JavaScript behavior. This is
achieved by simply returning an empty value handle (to signify the
absence of the property), and leaving it to V8 to throw an exception
as appropriate.

Task-number: QTBUG-21864
Task-number: QTBUG-24448
Change-Id: I9945adcab98fc3b801371163367473d6af0ab31a
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
2012-03-14 19:49:35 +01:00
Kent Hansen f91dba1274 Use the same ReferenceError message wording as V8
Instead of "Can't find variable: foo", use "foo is not defined".

This is in preparation of letting V8 throw the exception when a
property lookup fails on the QML scope object (needed for
QTBUG-24448).

Change-Id: I3c747482a8ef138dad9a85530a4f6b5c4c818a03
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
2012-03-14 16:45:30 +01:00
Michael Brasser 665f860d9a Support module api objects in v4.
Change-Id: I72911a2c8e0a8613e53861da7b38312e51bf57da
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
2012-03-14 01:12:35 +01:00
Jędrzej Nowacki 83f11e3374 Crash fix after QMetaType change.
QMetaType::UnknownType was added so we can distinguish between "void"
and an unregistered type.

Change-Id: If8cee21b3f84bf129343dc457d10ab31a9bfc8b8
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
2012-03-13 12:58:48 +01:00
Matthew Vogt 1f52c54301 Merge branch 'master' of git://gitorious.org/qt/qtdeclarative into api_changes
Change-Id: I578b1e2f1bb374da6194e6ba04a0fd459b2632fe
2012-03-12 08:35:40 +10:00
João Abecasis 3c94c7eb7e Don't grow container when desired size is known
QList<Type>::reserve() is used upfront to allocate necessary memory in a one
go. This tells us straight away whether allocation is possible at all and
reduces re-allocations and consequent memory copies.

This also has the side effect that no spare memory is allocated, also allowing
up to (and including) INT_MAX elements to actually be stored in the underlying
QList, as long as enough memory is available to satisfy the allocation request
and subsequent fill.

The qqmlecmascript::sequenceConversionIndexes was changed to not attempt
INT_MAX allocations as, given enough memory and virtual address space, that
might succeed but take a really long time.

Change-Id: I4b0c965e9c23be78874343a70d7c155933c80903
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
2012-03-09 21:26:40 +01:00
Lars Knoll 616bbd1988 Merge remote-tracking branch 'origin/master' into api_changes
Change-Id: I121cb9c9316b5e47476dcb982bc28b6f3f358f78
2012-03-07 22:01:11 +01:00
Kent Hansen aed15e7762 Make sure QML type "real" always maps to C++ type "double"
The type "real" was documented to be a single-precision float, but
that's incorrect. It's always been double.

However, signal parameters of type "real" would be mapped to the C++
type "qreal", which can be either float or double depending on the
platform.

Since JavaScript floating point numbers have double precision, QML
should use the same, to avoid potential loss of precision.

With this change, "real" behaves the same as the QML "double" type
(which already guaranteed double precision). Even though it's
redundant, "double" is kept to preserve compatibility.

Added tests for the "double" type to the QML meta-object autotest,
and a test for the "real" type that ensures there's no loss of
precision.

Change-Id: I1a77f1fd45082ff670684a935e17d1a46ea75d84
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
2012-03-07 12:10:27 +01:00
Chris Adams 92b1f9981d Allow function assignment to cause binding for non-var props
This patch maintains the old function-assignment behaviour for non-var
properties, and will be reverted soon.

Change-Id: I523e464501106616c51ff7478f7eb7171c1ca350
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
2012-03-05 10:06:48 +01:00
Chris Adams b6e78b3836 Improve support for var properties
This commit changes the semantics of function assignment in QML.
Previously, function assignment was interpreted as binding assignment.
Now, function assignment is interpreted as function assignment, and
therefore fails for all property types other than "var" properties.

To support imperative binding assignment, a new function was added to
the Qt object: Qt.binding(function) which takes a single function
parameter and returns a function object which will be interpreted as
an assignable binding expression by the QML engine.

Finally, this commit also slightly changes the semantics of var
properties in that the "special" JavaScript values of null and
undefined may be assigned to var properties, rather than being
interpreted as reset requests.

Task-number: QTBUG-21842
Change-Id: Iee99a878b9badf0fb76e983da7ebfa493f55ceb5
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
2012-03-05 09:01:47 +01:00
Matthew Vogt 0284817d6c Merge master <-> api_changes
Change-Id: Iad2f07b989b25349fd2d4fff010e24dcd5a1688f
2012-03-05 11:39:54 +10:00
Matthew Vogt b855240b78 Rename QDeclarative symbols to QQuick and QQml
Symbols beginning with QDeclarative are already exported
by the quick1 module.

Users can apply the bin/rename-qtdeclarative-symbols.sh
script to modify client code using the previous names of the
renamed symbols.

Task-number: QTBUG-23737
Change-Id: Ifaa482663767634931e8711a8e9bf6e404859e66
Reviewed-by: Martin Jones <martin.jones@nokia.com>
2012-02-24 04:51:31 +01:00