summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-03-16 15:57:49 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-03-16 15:57:49 (GMT)
commitd10667052db5dc2f4d1c7a7c161b040e9747897e (patch)
tree9239a131e77416ef1508021af9e4653117865237 /tests/auto/qscriptengine
parent4574b41dfb56652e806afd1dd64cc8b300284570 (diff)
downloadQt-d10667052db5dc2f4d1c7a7c161b040e9747897e.zip
Qt-d10667052db5dc2f4d1c7a7c161b040e9747897e.tar.gz
Qt-d10667052db5dc2f4d1c7a7c161b040e9747897e.tar.bz2
QtScript: Fix regression when calling newQObject() from native constructor
The thisObject passed to native constructors did not have all the new structure flags, so if it was promoted to a QObject (using the overload of newQObject() that takes an existing script object as first argument), the resulting script object did not receive dynamic property access callbacks.
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 8658240..d9beb45 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -155,6 +155,7 @@ private slots:
void nativeFunctionScopes();
void evaluateProgram();
void collectGarbageAfterConnect();
+ void promoteThisObjectToQObjectInConstructor();
void qRegExpInport_data();
void qRegExpInport();
@@ -4461,6 +4462,25 @@ void tst_QScriptEngine::collectGarbageAfterConnect()
QVERIFY(widget == 0);
}
+static QScriptValue constructQObjectFromThisObject(QScriptContext *ctx, QScriptEngine *eng)
+{
+ Q_ASSERT(ctx->isCalledAsConstructor());
+ return eng->newQObject(ctx->thisObject(), new QObject, QScriptEngine::ScriptOwnership);
+}
+
+void tst_QScriptEngine::promoteThisObjectToQObjectInConstructor()
+{
+ QScriptEngine engine;
+ QScriptValue ctor = engine.newFunction(constructQObjectFromThisObject);
+ engine.globalObject().setProperty("Ctor", ctor);
+ QScriptValue object = engine.evaluate("new Ctor");
+ QVERIFY(!object.isError());
+ QVERIFY(object.isQObject());
+ QVERIFY(object.toQObject() != 0);
+ QVERIFY(object.property("objectName").isString());
+ QVERIFY(object.property("deleteLater").isFunction());
+}
+
static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; }
void tst_QScriptEngine::qRegExpInport_data()