From bb74c2ecc9d4bf19b5db3ade968546e7b462c5ab Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Sun, 5 Mar 2023 13:45:48 +0100 Subject: [PATCH] Allow accessing engine exceptions from ScriptManager --- libraries/script-engine/src/ScriptManager.cpp | 10 +++++++++- libraries/script-engine/src/ScriptManager.h | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libraries/script-engine/src/ScriptManager.cpp b/libraries/script-engine/src/ScriptManager.cpp index 81b0e455fb..a36015e097 100644 --- a/libraries/script-engine/src/ScriptManager.cpp +++ b/libraries/script-engine/src/ScriptManager.cpp @@ -228,6 +228,10 @@ QString ScriptManager::logException(const ScriptValue& exception) { return message; } +std::shared_ptr ScriptManager::getUncaughtException() const { + return _engine->uncaughtException(); +} + ScriptManagerPointer scriptManagerFactory(ScriptManager::Context context, const QString& scriptContents, const QString& fileNameString) { @@ -303,6 +307,9 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con }); #endif + // Forward exceptions from the scripting engine + connect(_engine.get(), &ScriptEngine::exception, this, &ScriptManager::unhandledException); + if (_type == Type::ENTITY_CLIENT || _type == Type::ENTITY_SERVER) { QObject::connect(this, &ScriptManager::update, this, [this]() { // process pending entity script content @@ -902,7 +909,8 @@ void ScriptManager::run() { qCWarning(scriptengine) << "Engine has uncaught exception, stopping"; stop(); - _engine->clearExceptions(); + // V8TODO: Is clearing needed here? + //_engine->clearExceptions(); } } #ifdef _WIN32 diff --git a/libraries/script-engine/src/ScriptManager.h b/libraries/script-engine/src/ScriptManager.h index 514a182d20..9491b1e47b 100644 --- a/libraries/script-engine/src/ScriptManager.h +++ b/libraries/script-engine/src/ScriptManager.h @@ -1172,6 +1172,14 @@ public: */ Q_INVOKABLE QString getExternalPath(ExternalResource::Bucket bucket, const QString& path); + + /** + * @brief Get the uncaught exception from the underlying script engine + * + * @return std::shared_ptr Exception + */ + std::shared_ptr getUncaughtException() const; + public slots: /**