1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:17:35 +00:00

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.
This commit is contained in:
Andreas Kling 2022-08-04 20:16:40 +02:00
parent 2801ddfa76
commit eca0873245
2 changed files with 8 additions and 0 deletions

View file

@ -286,6 +286,12 @@ JS::VM& main_thread_vm()
vm->host_resolve_imported_module = [&](JS::ScriptOrModule, JS::ModuleRequest const&) -> JS::ThrowCompletionOr<NonnullRefPtr<JS::Module>> {
return vm->throw_completion<JS::InternalError>(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<WebEngineCustomData>(vm->custom_data());
custom_data.root_execution_context = make<JS::ExecutionContext>(vm->heap());
vm->push_execution_context(*custom_data.root_execution_context);
}
return *vm;
}