From eca08732450d9fa2eccea7c4103a54d8e449d447 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 4 Aug 2022 20:16:40 +0200 Subject: [PATCH] LibWeb: Always put a dummy execution context on the main thread VM stack A lot of code assumes that there's a current execution context. By setting up a dummy context right after creating the main thread VM, we ensure that such code can always run. --- Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp | 6 ++++++ Userland/Libraries/LibWeb/Bindings/MainThreadVM.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index e8432f0d5e..57cbd7501e 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -286,6 +286,12 @@ JS::VM& main_thread_vm() vm->host_resolve_imported_module = [&](JS::ScriptOrModule, JS::ModuleRequest const&) -> JS::ThrowCompletionOr> { return vm->throw_completion(vm->current_realm()->global_object(), JS::ErrorType::NotImplemented, "Modules in the browser"); }; + + // NOTE: We push a dummy execution context onto the JS execution context stack, + // just to make sure that it's never empty. + auto& custom_data = *verify_cast(vm->custom_data()); + custom_data.root_execution_context = make(vm->heap()); + vm->push_execution_context(*custom_data.root_execution_context); } return *vm; } diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.h b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.h index a085543d6e..686ce3ccb1 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.h +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.h @@ -29,6 +29,8 @@ struct WebEngineCustomData final : public JS::VM::CustomData { // https://dom.spec.whatwg.org/#mutation-observer-list // FIXME: This should be a set. NonnullRefPtrVector mutation_observers; + + OwnPtr root_execution_context; }; struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData {