Rethrow exceptions from the top level of a module

This commit is contained in:
phosit
2025-01-15 21:11:53 +01:00
committed by phosit
parent ce01bdddf6
commit d26d9b9b2b
4 changed files with 65 additions and 7 deletions
+12 -1
View File
@@ -21,6 +21,7 @@
#include "lib/file/vfs/vfs_path.h"
#include "scriptinterface/ScriptTypes.h"
#include <exception>
#include <unordered_map>
#include <variant>
@@ -49,10 +50,15 @@ public:
struct Evaluating
{
JS::PersistentRootedObject fulfill;
JS::PersistentRootedObject reject;
};
struct Fulfilled {};
struct Rejected
{
std::exception_ptr error;
};
struct Invalid {};
using Status = std::variant<Evaluating, Fulfilled, Invalid>;
using Status = std::variant<Evaluating, Fulfilled, Rejected, Invalid>;
explicit Future(const ScriptRequest& rq, ModuleLoader& loader, const VfsPath& modulePath);
Future() = default;
@@ -64,6 +70,11 @@ public:
[[nodiscard]] bool IsDone() const noexcept;
/**
* Throws if the evaluation of the module failed.
*/
void Get();
private:
// It's save to not require a `JS::HandleValue` here.
void SetReservedSlot(JS::Value privateValue) noexcept;