mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 09:20:48 +02:00
Capture exceptions that happen in signals in ScriptEngine, add test
This commit is contained in:
parent
1e1b96765f
commit
6ac2596293
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(const v8::TryCatch &tryCatch, const QString& info = QString());
|
||||||
void setUncaughtException(std::shared_ptr<ScriptException> exception);
|
void setUncaughtException(std::shared_ptr<ScriptException> exception);
|
||||||
|
|
||||||
|
friend class ScriptSignalV8Proxy;
|
||||||
|
|
||||||
std::shared_ptr<ScriptException> _uncaughtException;
|
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: \""
|
qCDebug(scriptengine) << "Signal proxy " << fullName() << " connection call failed: \""
|
||||||
<< _engine->formatErrorMessageFromTryCatch(tryCatch)
|
<< _engine->formatErrorMessageFromTryCatch(tryCatch)
|
||||||
<< "\nThis provided: " << conn.thisValue.get()->IsObject();
|
<< "\nThis provided: " << conn.thisValue.get()->IsObject();
|
||||||
|
|
||||||
|
_engine->setUncaughtException(tryCatch, "Error in signal proxy");
|
||||||
}
|
}
|
||||||
//_engine->popContext();
|
//_engine->popContext();
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,6 +271,37 @@ void ScriptEngineTests::testSignal() {
|
||||||
QVERIFY(printed.length() >= 10);
|
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() {
|
void ScriptEngineTests::scriptTest() {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -64,6 +64,7 @@ private slots:
|
||||||
void testRaiseException();
|
void testRaiseException();
|
||||||
void testRaiseExceptionAndCatch();
|
void testRaiseExceptionAndCatch();
|
||||||
void testSignal();
|
void testSignal();
|
||||||
|
void testSignalWithException();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue