mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57: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:
parent
2801ddfa76
commit
eca0873245
2 changed files with 8 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<DOM::MutationObserver> mutation_observers;
|
||||
|
||||
OwnPtr<JS::ExecutionContext> root_execution_context;
|
||||
};
|
||||
|
||||
struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue