Capture exceptions that happen in signals in ScriptEngine, add test

This commit is contained in:
Dale Glass 2023-03-06 20:13:16 +01:00 committed by ksuprynowicz
parent 6a189d33af
commit f2e5f13f1d
4 changed files with 45 additions and 9 deletions

View file

@ -225,6 +225,8 @@ protected:
void setUncaughtException(const v8::TryCatch &tryCatch, const QString& info = QString());
void setUncaughtException(std::shared_ptr<ScriptException> exception);
friend class ScriptSignalV8Proxy;
std::shared_ptr<ScriptException> _uncaughtException;

View file

@ -1474,6 +1474,8 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
qCDebug(scriptengine) << "Signal proxy " << fullName() << " connection call failed: \""
<< _engine->formatErrorMessageFromTryCatch(tryCatch)
<< "\nThis provided: " << conn.thisValue.get()->IsObject();
_engine->setUncaughtException(tryCatch, "Error in signal proxy");
}
//_engine->popContext();
}

View file

@ -271,6 +271,37 @@ void ScriptEngineTests::testSignal() {
QVERIFY(printed.length() >= 10);
}
void ScriptEngineTests::testSignalWithException() {
QString script =
"var count = 0;"
"Script.update.connect(function(deltaTime) {"
" count++;"
" print(deltaTime);"
" if (count >= 3) {"
" Script.stop(true);"
" }"
" nonExist();"
"});";
QStringList printed;
int exceptionCount = 0;
auto sm = makeManager(script, "testSignalWithException.js");
connect(sm.get(), &ScriptManager::printedMessage, [&printed](const QString& message, const QString& engineName){
printed.append(message);
});
connect(sm.get(), &ScriptManager::unhandledException, [&exceptionCount](std::shared_ptr<ScriptException> exception){
exceptionCount++;
});
sm->run();
QVERIFY(printed.length() >= 3);
QVERIFY(exceptionCount >= 3);
}
void ScriptEngineTests::scriptTest() {
return;

View file

@ -64,6 +64,7 @@ private slots:
void testRaiseException();
void testRaiseExceptionAndCatch();
void testSignal();
void testSignalWithException();