diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-03-16 16:57:49 +0100 |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-03-16 16:57:49 +0100 |
commit | d10667052db5dc2f4d1c7a7c161b040e9747897e (patch) | |
tree | 9239a131e77416ef1508021af9e4653117865237 /tests | |
parent | 4574b41dfb56652e806afd1dd64cc8b300284570 (diff) | |
download | qt4-tools-d10667052db5dc2f4d1c7a7c161b040e9747897e.tar.gz |
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')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 8658240504..d9beb459ef 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() |