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

LibWeb: Add an "internal" JS realm & window object

These will be used to host JS objects that don't belong in one of the
web-facing global objects.
This commit is contained in:
Andreas Kling 2022-08-07 12:03:41 +02:00
parent 4ae2390554
commit 0fe923e355
2 changed files with 24 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -307,12 +307,27 @@ JS::VM& main_thread_vm()
// 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());
custom_data.root_execution_context = MUST(JS::Realm::initialize_host_defined_realm(
*vm, [&](JS::Realm& realm) -> JS::GlobalObject* {
auto internal_window = HTML::Window::create();
custom_data.internal_window_object = JS::make_handle(vm->heap().allocate<Bindings::WindowObject>(realm, realm, internal_window));
return custom_data.internal_window_object.cell(); },
[](JS::Realm&) -> JS::GlobalObject* {
return nullptr;
}));
vm->push_execution_context(*custom_data.root_execution_context);
}
return *vm;
}
Bindings::WindowObject& main_thread_internal_window_object()
{
auto& vm = main_thread_vm();
auto& custom_data = verify_cast<WebEngineCustomData>(*vm.custom_data());
return *custom_data.internal_window_object;
}
// https://dom.spec.whatwg.org/#queue-a-mutation-observer-compound-microtask
void queue_mutation_observer_microtask(DOM::Document& document)
{