From 2f6459ff25a59e913b5695dcd8919ead8d58947c Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 18 Jan 2010 14:56:22 +0100 Subject: 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 --- src/script/bridge/qscriptqobject.cpp | 3 ++- tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp | 11 ++++++++++- 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(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); { -- cgit v0.12