1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 16:57:36 +00:00

LibJS: Propagate errors from VM creation

This commit is contained in:
Timothy Flynn 2023-03-17 10:44:47 -04:00 committed by Linus Groh
parent eb5aae24f4
commit 13dfadba79
13 changed files with 15 additions and 15 deletions

View file

@ -88,7 +88,7 @@ void CalculatorProvider::query(DeprecatedString const& query, Function<void(Vect
if (!query.starts_with('='))
return;
auto vm = JS::VM::create();
auto vm = JS::VM::create().release_value_but_fixme_should_propagate_errors();
auto interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm);
auto source_code = query.substring(1);

View file

@ -20,7 +20,7 @@ namespace Spreadsheet {
Workbook::Workbook(Vector<NonnullRefPtr<Sheet>>&& sheets, GUI::Window& parent_window)
: m_sheets(move(sheets))
, m_vm(JS::VM::create())
, m_vm(JS::VM::create().release_value_but_fixme_should_propagate_errors())
, m_interpreter(JS::Interpreter::create<JS::GlobalObject>(m_vm))
, m_interpreter_scope(*m_interpreter)
, m_main_execution_context(m_vm->heap())

View file

@ -34,16 +34,16 @@
namespace JS {
NonnullRefPtr<VM> VM::create(OwnPtr<CustomData> custom_data)
ErrorOr<NonnullRefPtr<VM>> VM::create(OwnPtr<CustomData> custom_data)
{
ErrorMessages error_messages {};
error_messages[to_underlying(ErrorMessage::OutOfMemory)] = String::from_utf8(ErrorType::OutOfMemory.message()).release_value_but_fixme_should_propagate_errors();
error_messages[to_underlying(ErrorMessage::OutOfMemory)] = TRY(String::from_utf8(ErrorType::OutOfMemory.message()));
auto vm = adopt_ref(*new VM(move(custom_data), move(error_messages)));
WellKnownSymbols well_known_symbols {
#define __JS_ENUMERATE(SymbolName, snake_name) \
Symbol::create(*vm, "Symbol." #SymbolName##_string.release_value_but_fixme_should_propagate_errors(), false),
Symbol::create(*vm, TRY("Symbol." #SymbolName##_string), false),
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
#undef __JS_ENUMERATE
};

View file

@ -38,7 +38,7 @@ public:
virtual void spin_event_loop_until(Function<bool()> goal_condition) = 0;
};
static NonnullRefPtr<VM> create(OwnPtr<CustomData> = {});
static ErrorOr<NonnullRefPtr<VM>> create(OwnPtr<CustomData> = {});
~VM() = default;
Heap& heap() { return m_heap; }

View file

@ -189,7 +189,7 @@ int main(int argc, char** argv)
g_main_hook();
if (!g_vm) {
g_vm = JS::VM::create();
g_vm = MUST(JS::VM::create());
g_vm->enable_default_host_import_module_dynamically_hook();
}

View file

@ -56,7 +56,7 @@ JS::VM& main_thread_vm()
{
static RefPtr<JS::VM> vm;
if (!vm) {
vm = JS::VM::create(make<WebEngineCustomData>());
vm = JS::VM::create(make<WebEngineCustomData>()).release_value_but_fixme_should_propagate_errors();
// NOTE: We intentionally leak the main thread JavaScript VM.
// This avoids doing an exhaustive garbage collection on process exit.

View file

@ -23,7 +23,7 @@ Worker::Worker(String const& script_url, WorkerOptions const options, DOM::Docum
, m_options(options)
, m_document(&document)
, m_custom_data()
, m_worker_vm(JS::VM::create(adopt_own(m_custom_data)))
, m_worker_vm(JS::VM::create(adopt_own(m_custom_data)).release_value_but_fixme_should_propagate_errors())
, m_interpreter(JS::Interpreter::create<JS::GlobalObject>(m_worker_vm))
, m_interpreter_scope(*m_interpreter)
, m_implicit_port(MessagePort::create(document.realm()).release_value_but_fixme_should_propagate_errors())

View file

@ -621,7 +621,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
s_history_path = TRY(String::formatted("{}/.js-history", Core::StandardPaths::home_directory()));
g_vm = JS::VM::create();
g_vm = TRY(JS::VM::create());
g_vm->enable_default_host_import_module_dynamically_hook();
// NOTE: These will print out both warnings when using something like Promise.reject().catch(...) -