From c898ee90cf2bb64794a583871687e0b08f49ee4b Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 17 Nov 2024 21:33:58 -0700 Subject: [PATCH] js: Don't destroy the JS VM on shutdown This avoids a crash in the fully static distribution build, due to static init order fiasco. --- Utilities/js.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Utilities/js.cpp b/Utilities/js.cpp index af3c49ffac7..3564e871407 100644 --- a/Utilities/js.cpp +++ b/Utilities/js.cpp @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -30,7 +31,10 @@ #include #include -RefPtr g_vm; +// FIXME: https://github.com/LadybirdBrowser/ladybird/issues/2412 +// We should be able to destroy the VM on process exit. +NeverDestroyed> g_vm_storage; +JS::VM* g_vm; Vector g_repl_statements; GC::Root g_last_value = GC::make_root(JS::js_undefined()); @@ -555,7 +559,8 @@ ErrorOr 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 = TRY(JS::VM::create()); + g_vm_storage.get() = TRY(JS::VM::create()); + g_vm = g_vm_storage->ptr(); g_vm->set_dynamic_imports_allowed(true); if (!disable_debug_printing) {