From 5e0aef012a90598b88b547b1b73785f59ef135c1 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 3 Jun 2009 15:44:20 +0200 Subject: 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. --- src/script/qscriptengine.cpp | 2 +- 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); -- cgit v0.12