summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-10-22 11:26:28 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-10-22 11:44:21 (GMT)
commit9dec5247be84ae4606d5d9baf5b99612c5feba8d (patch)
treee8eafa402f5104c959dab69d95018c259f8e1fd7
parentc74240bf4ab182f13b18271831fd6deebfe573f6 (diff)
downloadQt-9dec5247be84ae4606d5d9baf5b99612c5feba8d.zip
Qt-9dec5247be84ae4606d5d9baf5b99612c5feba8d.tar.gz
Qt-9dec5247be84ae4606d5d9baf5b99612c5feba8d.tar.bz2
QtScript: Compatibility with 4.5
We must register the same type as they were registered in Qt 4.5 Reported on qt4-preview-feedback mailing list. Reviewed-by: Kent Hansen
-rw-r--r--src/script/api/qscriptengine.cpp4
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp24
2 files changed, 28 insertions, 0 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 360036a..c3c8caf 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -797,6 +797,10 @@ QScriptEnginePrivate::QScriptEnginePrivate()
registeredScriptStrings(0), inEval(false)
{
qMetaTypeId<QScriptValue>();
+ qMetaTypeId<QList<int> >();
+#ifndef QT_NO_QOBJECT
+ qMetaTypeId<QObjectList>();
+#endif
JSC::initializeThreading(); // ### hmmm
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index 320a429..44adf7e 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -317,6 +317,11 @@ public:
Q_INVOKABLE QObject* myInvokableReturningMyQObjectAsQObject()
{ m_qtFunctionInvoked = 57; return this; }
+ Q_INVOKABLE QObjectList findObjects() const
+ { return findChildren<QObject *>(); }
+ Q_INVOKABLE QList<int> myInvokableNumbers() const
+ { return QList<int>() << 1 << 2 << 3; }
+
void emitMySignal()
{ emit mySignal(); }
void emitMySignalWithIntArg(int arg)
@@ -493,6 +498,7 @@ protected slots:
}
private slots:
+ void registeredTypes();
void getSetStaticProperty();
void getSetDynamicProperty();
void getSetChildren();
@@ -543,6 +549,24 @@ void tst_QScriptExtQObject::cleanup()
delete m_myObject;
}
+// this test has to be first and test that some types are automatically registered
+void tst_QScriptExtQObject::registeredTypes()
+{
+ QScriptEngine e;
+ QObject *t = new MyQObject;
+ QObject *c = new QObject(t);
+ c->setObjectName ("child1");
+
+ e.globalObject().setProperty("MyTest", e.newQObject(t));
+
+ QScriptValue v1 = e.evaluate("MyTest.findObjects()[0].objectName;");
+ QCOMPARE(v1.toString(), c->objectName());
+
+ QScriptValue v2 = e.evaluate("MyTest.myInvokableNumbers()");
+ QCOMPARE(qscriptvalue_cast<QList<int> >(v2), (QList<int>() << 1 << 2 << 3));
+}
+
+
static QScriptValue getSetProperty(QScriptContext *ctx, QScriptEngine *)
{
if (ctx->argumentCount() != 0)