summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmldeclarativedata_p.h2
-rw-r--r--src/declarative/qml/qmlobjectscriptclass.cpp11
-rw-r--r--tests/auto/declarative/qmlecmascript/data/objectsCompareAsEqual.qml15
-rw-r--r--tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp21
4 files changed, 48 insertions, 1 deletions
diff --git a/src/declarative/qml/qmldeclarativedata_p.h b/src/declarative/qml/qmldeclarativedata_p.h
index b4c87b8..f6ecc3d 100644
--- a/src/declarative/qml/qmldeclarativedata_p.h
+++ b/src/declarative/qml/qmldeclarativedata_p.h
@@ -54,6 +54,7 @@
//
#include <private/qobject_p.h>
+#include <QtScript/qscriptvalue.h>
QT_BEGIN_NAMESPACE
@@ -86,6 +87,7 @@ public:
QHash<int, QObject *> *attachedProperties;
+ QScriptValue scriptValue;
QmlPropertyCache *propertyCache;
static QmlDeclarativeData *get(const QObject *object, bool create = false) {
diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp
index 2d5991c..330eddd 100644
--- a/src/declarative/qml/qmlobjectscriptclass.cpp
+++ b/src/declarative/qml/qmlobjectscriptclass.cpp
@@ -80,7 +80,16 @@ QScriptValue QmlObjectScriptClass::newQObject(QObject *object)
{
QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
- return newObject(scriptEngine, this, new ObjectData(object));
+ QmlDeclarativeData *ddata = QmlDeclarativeData::get(object, true);
+
+ if (!ddata->scriptValue.isValid()) {
+ ddata->scriptValue = newObject(scriptEngine, this, new ObjectData(object));
+ return ddata->scriptValue;
+ } else if (ddata->scriptValue.engine() == QmlEnginePrivate::getScriptEngine(engine)) {
+ return ddata->scriptValue;
+ } else {
+ return newObject(scriptEngine, this, new ObjectData(object));
+ }
}
QObject *QmlObjectScriptClass::toQObject(const QScriptValue &value) const
diff --git a/tests/auto/declarative/qmlecmascript/data/objectsCompareAsEqual.qml b/tests/auto/declarative/qmlecmascript/data/objectsCompareAsEqual.qml
new file mode 100644
index 0000000..2526576
--- /dev/null
+++ b/tests/auto/declarative/qmlecmascript/data/objectsCompareAsEqual.qml
@@ -0,0 +1,15 @@
+import Qt 4.6
+
+Item {
+ id: Root
+
+ property var item: Child
+ Item { id: Child }
+
+ property bool test1: Child == Child
+ property bool test2: Child.parent == Root
+ property bool test3: Root != Child
+ property bool test4: item == Child
+ property bool test5: item != Root
+}
+
diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
index 65f7021..15bfe24 100644
--- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
+++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
@@ -53,6 +53,7 @@ private slots:
void nonExistantAttachedObject();
void scope();
void signalParameterTypes();
+ void objectsCompareAsEqual();
private:
QmlEngine engine;
@@ -543,6 +544,10 @@ void tst_qmlecmascript::scope()
QCOMPARE(object->property("test8").toInt(), 2);
}
+/*
+Tests that "any" type passes through a synthesized signal parameter. This
+is essentially a test of QmlMetaType::copy()
+*/
void tst_qmlecmascript::signalParameterTypes()
{
QmlComponent component(&engine, TEST_FILE("signalParameterTypes.qml"));
@@ -558,6 +563,22 @@ void tst_qmlecmascript::signalParameterTypes()
}
/*
+Test that two JS objects for the same QObject compare as equal.
+*/
+void tst_qmlecmascript::objectsCompareAsEqual()
+{
+ QmlComponent component(&engine, TEST_FILE("objectsCompareAsEqual.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test1").toBool(), true);
+ QCOMPARE(object->property("test2").toBool(), true);
+ QCOMPARE(object->property("test3").toBool(), true);
+ QCOMPARE(object->property("test4").toBool(), true);
+ QCOMPARE(object->property("test5").toBool(), true);
+}
+
+/*
Confirm bindings and alias properties can coexist.
Tests for a regression where the binding would not reevaluate.