mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 15:30:38 +02:00
Capture exceptions that happen in signals in ScriptEngine, add test
This commit is contained in:
parent
6a189d33af
commit
f2e5f13f1d
4 changed files with 45 additions and 9 deletions
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -64,6 +64,7 @@ private slots:
|
|||
void testRaiseException();
|
||||
void testRaiseExceptionAndCatch();
|
||||
void testSignal();
|
||||
void testSignalWithException();
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue