LibJS: Propagate errors from VM creation
This commit is contained in:
parent
eb5aae24f4
commit
13dfadba79
Notes:
sideshowbarker
2024-07-17 07:16:27 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/13dfadba79 Pull-request: https://github.com/SerenityOS/serenity/pull/17892 Reviewed-by: https://github.com/linusg
13 changed files with 15 additions and 15 deletions
|
@ -15,7 +15,7 @@
|
|||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
{
|
||||
auto js = StringView(static_cast<unsigned char const*>(data), size);
|
||||
auto vm = JS::VM::create();
|
||||
auto vm = MUST(JS::VM::create());
|
||||
auto interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm);
|
||||
auto parse_result = JS::Script::parse(js, interpreter->realm());
|
||||
if (!parse_result.is_error())
|
||||
|
|
|
@ -190,7 +190,7 @@ int main(int, char**)
|
|||
reprl_input = (char*)mmap(0, REPRL_MAX_DATA_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, REPRL_DRFD, 0);
|
||||
VERIFY(reprl_input != MAP_FAILED);
|
||||
|
||||
auto vm = JS::VM::create();
|
||||
auto vm = MUST(JS::VM::create());
|
||||
auto interpreter = JS::Interpreter::create<TestRunnerGlobalObject>(*vm);
|
||||
|
||||
while (true) {
|
||||
|
|
|
@ -359,7 +359,7 @@ extern "C" int initialize_repl(char const* time_zone)
|
|||
if (time_zone)
|
||||
setenv("TZ", time_zone, 1);
|
||||
|
||||
g_vm = JS::VM::create();
|
||||
g_vm = MUST(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(...) -
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <LibTest/TestCase.h>
|
||||
|
||||
#define SETUP_AND_PARSE(source) \
|
||||
auto vm = JS::VM::create(); \
|
||||
auto vm = MUST(JS::VM::create()); \
|
||||
auto ast_interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm); \
|
||||
\
|
||||
auto script_or_error = JS::Script::parse(source##sv, ast_interpreter->realm()); \
|
||||
|
|
|
@ -232,7 +232,7 @@ static Result<void, TestError> run_test(StringView source, StringView filepath,
|
|||
return {};
|
||||
}
|
||||
|
||||
auto vm = JS::VM::create();
|
||||
auto vm = MUST(JS::VM::create());
|
||||
vm->enable_default_host_import_module_dynamically_hook();
|
||||
auto ast_interpreter = JS::Interpreter::create<JS::Test262::GlobalObject>(*vm);
|
||||
auto& realm = ast_interpreter->realm();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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(...) -
|
||||
|
|
Loading…
Add table
Reference in a new issue