Allow accessing engine exceptions from ScriptManager

This commit is contained in:
Dale Glass 2023-03-05 13:45:48 +01:00 committed by ksuprynowicz
parent de02da5fda
commit bb74c2ecc9
2 changed files with 17 additions and 1 deletions

View file

@ -228,6 +228,10 @@ QString ScriptManager::logException(const ScriptValue& exception) {
return message; return message;
} }
std::shared_ptr<ScriptException> ScriptManager::getUncaughtException() const {
return _engine->uncaughtException();
}
ScriptManagerPointer scriptManagerFactory(ScriptManager::Context context, ScriptManagerPointer scriptManagerFactory(ScriptManager::Context context,
const QString& scriptContents, const QString& scriptContents,
const QString& fileNameString) { const QString& fileNameString) {
@ -303,6 +307,9 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con
}); });
#endif #endif
// Forward exceptions from the scripting engine
connect(_engine.get(), &ScriptEngine::exception, this, &ScriptManager::unhandledException);
if (_type == Type::ENTITY_CLIENT || _type == Type::ENTITY_SERVER) { if (_type == Type::ENTITY_CLIENT || _type == Type::ENTITY_SERVER) {
QObject::connect(this, &ScriptManager::update, this, [this]() { QObject::connect(this, &ScriptManager::update, this, [this]() {
// process pending entity script content // process pending entity script content
@ -902,7 +909,8 @@ void ScriptManager::run() {
qCWarning(scriptengine) << "Engine has uncaught exception, stopping"; qCWarning(scriptengine) << "Engine has uncaught exception, stopping";
stop(); stop();
_engine->clearExceptions(); // V8TODO: Is clearing needed here?
//_engine->clearExceptions();
} }
} }
#ifdef _WIN32 #ifdef _WIN32

View file

@ -1172,6 +1172,14 @@ public:
*/ */
Q_INVOKABLE QString getExternalPath(ExternalResource::Bucket bucket, const QString& path); Q_INVOKABLE QString getExternalPath(ExternalResource::Bucket bucket, const QString& path);
/**
* @brief Get the uncaught exception from the underlying script engine
*
* @return std::shared_ptr<ScriptException> Exception
*/
std::shared_ptr<ScriptException> getUncaughtException() const;
public slots: public slots:
/** /**