mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
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:
parent
084cceab5c
commit
8263a9863f
Notes:
github-actions[bot]
2025-04-25 14:45:48 +00:00
Author: https://github.com/shannonbooth
Commit: 8263a9863f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4453
12 changed files with 13 additions and 15 deletions
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<VM>> VM::create(OwnPtr<Agent> agent)
|
NonnullRefPtr<VM> VM::create(OwnPtr<Agent> agent)
|
||||||
{
|
{
|
||||||
ErrorMessages error_messages {};
|
ErrorMessages error_messages {};
|
||||||
error_messages[to_underlying(ErrorMessage::OutOfMemory)] = ErrorType::OutOfMemory.message();
|
error_messages[to_underlying(ErrorMessage::OutOfMemory)] = ErrorType::OutOfMemory.message();
|
||||||
|
|
|
@ -47,7 +47,7 @@ enum class EvalMode {
|
||||||
|
|
||||||
class VM : public RefCounted<VM> {
|
class VM : public RefCounted<VM> {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullRefPtr<VM>> create(OwnPtr<Agent> = {});
|
static NonnullRefPtr<VM> create(OwnPtr<Agent> = {});
|
||||||
~VM();
|
~VM();
|
||||||
|
|
||||||
GC::Heap& heap() { return m_heap; }
|
GC::Heap& heap() { return m_heap; }
|
||||||
|
|
|
@ -183,7 +183,7 @@ int main(int argc, char** argv)
|
||||||
g_main_hook();
|
g_main_hook();
|
||||||
|
|
||||||
if (!g_vm) {
|
if (!g_vm) {
|
||||||
g_vm = MUST(JS::VM::create());
|
g_vm = JS::VM::create();
|
||||||
g_vm->set_dynamic_imports_allowed(true);
|
g_vm->set_dynamic_imports_allowed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
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());
|
auto& agent = as<HTML::Agent>(*s_main_thread_vm->agent());
|
||||||
agent.event_loop = s_main_thread_vm->heap().allocate<HTML::EventLoop>(type);
|
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) {
|
s_main_thread_vm->host_unrecognized_date_string = [](StringView date) {
|
||||||
dbgln("Unable to parse date string: \"{}\"", date);
|
dbgln("Unable to parse date string: \"{}\"", date);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::VM& main_thread_vm()
|
JS::VM& main_thread_vm()
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData
|
||||||
|
|
||||||
HTML::Script* active_script();
|
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();
|
JS::VM& main_thread_vm();
|
||||||
|
|
||||||
void queue_mutation_observer_microtask(DOM::Document const&);
|
void queue_mutation_observer_microtask(DOM::Document const&);
|
||||||
|
|
|
@ -17,7 +17,7 @@ struct Globals {
|
||||||
Globals::Globals()
|
Globals::Globals()
|
||||||
{
|
{
|
||||||
Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||||
// FIXME: https://github.com/SerenityOS/serenity/issues/17899
|
// FIXME: https://github.com/SerenityOS/serenity/issues/17899
|
||||||
if (!Utf8View(js).validate())
|
if (!Utf8View(js).validate())
|
||||||
return 0;
|
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 root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
|
||||||
auto& realm = *root_execution_context->realm;
|
auto& realm = *root_execution_context->realm;
|
||||||
auto parse_result = JS::Script::parse(js, realm);
|
auto parse_result = JS::Script::parse(js, realm);
|
||||||
|
|
|
@ -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);
|
reprl_input = (char*)mmap(0, REPRL_MAX_DATA_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, REPRL_DRFD, 0);
|
||||||
VERIFY(reprl_input != MAP_FAILED);
|
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 root_execution_context = JS::create_simple_execution_context<TestRunnerGlobalObject>(*vm);
|
||||||
auto& realm = *root_execution_context->realm;
|
auto& realm = *root_execution_context->realm;
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(is_layout_test_mode, &font_provider));
|
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)
|
if (collect_garbage_on_every_allocation)
|
||||||
Web::Bindings::main_thread_vm().heap().set_should_collect_on_every_allocation(true);
|
Web::Bindings::main_thread_vm().heap().set_should_collect_on_every_allocation(true);
|
||||||
|
|
|
@ -68,7 +68,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(false));
|
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));
|
TRY(initialize_resource_loader(Web::Bindings::main_thread_vm().heap(), request_server_socket));
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ static ErrorOr<void, TestError> run_test(StringView source, StringView filepath,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto vm = MUST(JS::VM::create());
|
auto vm = JS::VM::create();
|
||||||
vm->set_dynamic_imports_allowed(true);
|
vm->set_dynamic_imports_allowed(true);
|
||||||
|
|
||||||
GC::Ptr<JS::Realm> realm;
|
GC::Ptr<JS::Realm> realm;
|
||||||
|
|
|
@ -558,7 +558,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
AK::set_debug_enabled(!disable_debug_printing);
|
AK::set_debug_enabled(!disable_debug_printing);
|
||||||
s_history_path = TRY(String::formatted("{}/.js-history", Core::StandardPaths::home_directory()));
|
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 = g_vm_storage->ptr();
|
||||||
g_vm->set_dynamic_imports_allowed(true);
|
g_vm->set_dynamic_imports_allowed(true);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue