diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-06-03 13:44:20 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-06-03 13:52:24 (GMT) |
commit | 5e0aef012a90598b88b547b1b73785f59ef135c1 (patch) | |
tree | 98d4e3b40a0209ffd0aff6192b0627206c39c34d | |
parent | c890793e7a58e1d75d1f88f5e2c88162eddcca44 (diff) | |
download | Qt-5e0aef012a90598b88b547b1b73785f59ef135c1.zip Qt-5e0aef012a90598b88b547b1b73785f59ef135c1.tar.gz Qt-5e0aef012a90598b88b547b1b73785f59ef135c1.tar.bz2 |
fix silly typo
Yeesh.
The function worked for the common case of the argument being a plain
script object (obviously, otherwise this would have been discovered
sooner), but it would never pick the less expensive path when replacing
the QObject pointer of an existing proxy. And if you passed in a
QVariant proxy (now who would ever do something like that...?),
it would assert.
-rw-r--r-- | src/script/qscriptengine.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 14 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/script/qscriptengine.cpp b/src/script/qscriptengine.cpp index d8908ed..97021fc 100644 --- a/src/script/qscriptengine.cpp +++ b/src/script/qscriptengine.cpp @@ -587,7 +587,7 @@ QScriptValue QScriptEngine::newQObject(const QScriptValue &scriptObject, QScriptValuePrivate *p = QScriptValuePrivate::get(scriptObject); if (!p || !p->value.isObject()) return newQObject(qtObject, ownership, options); - if (p->value.isVariant()) { + if (p->value.isQObject()) { QScript::ExtQObject::Instance *data; data = d->qobjectConstructor->get(p->value); Q_ASSERT(data != 0); diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 5339fb4..fe60cd0 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -636,9 +636,21 @@ void tst_QScriptEngine::newQObject() QScriptValue val = ret.property("objectName"); QVERIFY(val.isString()); } + // "promote" variant object to QObject + { + QScriptValue obj = eng.newVariant(123); + QVERIFY(obj.isVariant()); + QScriptValue originalProto = obj.prototype(); + QScriptValue ret = eng.newQObject(obj, this); + QVERIFY(ret.isQObject()); + QVERIFY(ret.strictlyEquals(obj)); + QVERIFY(obj.isQObject()); + QCOMPARE(ret.toQObject(), (QObject *)this); + QVERIFY(ret.prototype().strictlyEquals(originalProto)); + } // replace QObject* of existing object { - QScriptValue object = eng.newQObject(this); + QScriptValue object = eng.newVariant(123); QScriptValue originalProto = object.prototype(); QObject otherQObject; QScriptValue ret = eng.newQObject(object, &otherQObject); |