summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-01-18 13:56:22 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-01-18 14:06:47 (GMT)
commit2f6459ff25a59e913b5695dcd8919ead8d58947c (patch)
tree0706b81b7ab9a5de17cf932001fe3bd031faf3dd
parent5346edef00dd8f541f16217e0960fd6bb4ea0981 (diff)
downloadQt-2f6459ff25a59e913b5695dcd8919ead8d58947c.zip
Qt-2f6459ff25a59e913b5695dcd8919ead8d58947c.tar.gz
Qt-2f6459ff25a59e913b5695dcd8919ead8d58947c.tar.bz2
don't assert when calling QtScript-wrapped method of deleted QObject
Make it behave the same as the old (4.5) back-end. Reviewed-by: Jedrzej Nowacki
-rw-r--r--src/script/bridge/qscriptqobject.cpp3
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp11
2 files changed, 12 insertions, 2 deletions
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index fb0dddb..3f4f6bb 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -978,7 +978,8 @@ JSC::JSValue QtFunction::execute(JSC::ExecState *exec, JSC::JSValue thisValue,
QScriptObjectDelegate *delegate = scriptObject->delegate();
Q_ASSERT(delegate && (delegate->type() == QScriptObjectDelegate::QtObject));
QObject *qobj = static_cast<QScript::QObjectDelegate*>(delegate)->value();
- Q_ASSERT_X(qobj != 0, "QtFunction::call", "handle the case when QObject has been deleted");
+ if (!qobj)
+ return JSC::throwError(exec, JSC::GeneralError, QString::fromLatin1("cannot call function of deleted QObject"));
QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
const QMetaObject *meta = qobj->metaObject();
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index 3415163..de9d37e 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -2913,7 +2913,8 @@ void tst_QScriptExtQObject::objectDeleted()
v.setProperty("intProperty", QScriptValue(&eng, 123));
QCOMPARE(qobj->intProperty(), 123);
qobj->resetQtFunctionInvoked();
- v.property("myInvokable").call(v);
+ QScriptValue invokable = v.property("myInvokable");
+ invokable.call(v);
QCOMPARE(qobj->qtFunctionInvoked(), 0);
// now delete the object
@@ -2951,6 +2952,14 @@ void tst_QScriptExtQObject::objectDeleted()
QCOMPARE(ret.toString(), QLatin1String("Error: cannot access member `myInvokableWithIntArg' of deleted QObject"));
}
+ // Meta-method wrappers are still valid, but throw error when called
+ QVERIFY(invokable.isFunction());
+ {
+ QScriptValue ret = invokable.call(v);
+ QVERIFY(ret.isError());
+ QCOMPARE(ret.toString(), QString::fromLatin1("Error: cannot call function of deleted QObject"));
+ }
+
// access from script
eng.globalObject().setProperty("o", v);
{