LibJS+LibWeb: Do not return error from VM::create

This never returns an error to propogate, also allowing ErrorOr
to be removed from creating the main thread VM.
This commit is contained in:
Shannon Booth 2025-04-24 15:46:51 +12:00 committed by Andreas Kling
commit 8263a9863f
Notes: github-actions[bot] 2025-04-25 14:45:48 +00:00
12 changed files with 13 additions and 15 deletions

View file

@ -37,7 +37,7 @@
namespace JS {
ErrorOr<NonnullRefPtr<VM>> VM::create(OwnPtr<Agent> agent)
NonnullRefPtr<VM> VM::create(OwnPtr<Agent> agent)
{
ErrorMessages error_messages {};
error_messages[to_underlying(ErrorMessage::OutOfMemory)] = ErrorType::OutOfMemory.message();

View file

@ -47,7 +47,7 @@ enum class EvalMode {
class VM : public RefCounted<VM> {
public:
static ErrorOr<NonnullRefPtr<VM>> create(OwnPtr<Agent> = {});
static NonnullRefPtr<VM> create(OwnPtr<Agent> = {});
~VM();
GC::Heap& heap() { return m_heap; }

View file

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

View file

@ -72,11 +72,11 @@ HTML::Script* active_script()
});
}
ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
void initialize_main_thread_vm(HTML::EventLoop::Type type)
{
VERIFY(!s_main_thread_vm);
s_main_thread_vm = TRY(JS::VM::create(make<HTML::SimilarOriginWindowAgent>()));
s_main_thread_vm = JS::VM::create(make<HTML::SimilarOriginWindowAgent>());
auto& agent = as<HTML::Agent>(*s_main_thread_vm->agent());
agent.event_loop = s_main_thread_vm->heap().allocate<HTML::EventLoop>(type);
@ -645,8 +645,6 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
s_main_thread_vm->host_unrecognized_date_string = [](StringView date) {
dbgln("Unable to parse date string: \"{}\"", date);
};
return {};
}
JS::VM& main_thread_vm()

View file

@ -32,7 +32,7 @@ struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData
HTML::Script* active_script();
ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type);
void initialize_main_thread_vm(HTML::EventLoop::Type);
JS::VM& main_thread_vm();
void queue_mutation_observer_microtask(DOM::Document const&);

View file

@ -17,7 +17,7 @@ struct Globals {
Globals::Globals()
{
Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);
MUST(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window));
Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window);
}
}

View file

@ -19,7 +19,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
// FIXME: https://github.com/SerenityOS/serenity/issues/17899
if (!Utf8View(js).validate())
return 0;
auto vm = MUST(JS::VM::create());
auto vm = JS::VM::create();
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
auto& realm = *root_execution_context->realm;
auto parse_result = JS::Script::parse(js, realm);

View file

@ -194,7 +194,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 = MUST(JS::VM::create());
auto vm = JS::VM::create();
auto root_execution_context = JS::create_simple_execution_context<TestRunnerGlobalObject>(*vm);
auto& realm = *root_execution_context->realm;

View file

@ -191,7 +191,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(is_layout_test_mode, &font_provider));
TRY(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window));
Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window);
if (collect_garbage_on_every_allocation)
Web::Bindings::main_thread_vm().heap().set_should_collect_on_every_allocation(true);

View file

@ -68,7 +68,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(false));
TRY(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Worker));
Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Worker);
TRY(initialize_resource_loader(Web::Bindings::main_thread_vm().heap(), request_server_socket));

View file

@ -210,7 +210,7 @@ static ErrorOr<void, TestError> run_test(StringView source, StringView filepath,
return {};
}
auto vm = MUST(JS::VM::create());
auto vm = JS::VM::create();
vm->set_dynamic_imports_allowed(true);
GC::Ptr<JS::Realm> realm;

View file

@ -558,7 +558,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
AK::set_debug_enabled(!disable_debug_printing);
s_history_path = TRY(String::formatted("{}/.js-history", Core::StandardPaths::home_directory()));
g_vm_storage.get() = TRY(JS::VM::create());
g_vm_storage.get() = JS::VM::create();
g_vm = g_vm_storage->ptr();
g_vm->set_dynamic_imports_allowed(true);