mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +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:
parent
4ae2390554
commit
0fe923e355
2 changed files with 24 additions and 3 deletions
|
@ -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>
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* 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,
|
// NOTE: We push a dummy execution context onto the JS execution context stack,
|
||||||
// just to make sure that it's never empty.
|
// just to make sure that it's never empty.
|
||||||
auto& custom_data = *verify_cast<WebEngineCustomData>(vm->custom_data());
|
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);
|
vm->push_execution_context(*custom_data.root_execution_context);
|
||||||
}
|
}
|
||||||
return *vm;
|
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
|
// https://dom.spec.whatwg.org/#queue-a-mutation-observer-compound-microtask
|
||||||
void queue_mutation_observer_microtask(DOM::Document& document)
|
void queue_mutation_observer_microtask(DOM::Document& document)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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>
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibJS/Runtime/JobCallback.h>
|
#include <LibJS/Runtime/JobCallback.h>
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
|
#include <LibWeb/Bindings/WindowObject.h>
|
||||||
#include <LibWeb/DOM/MutationObserver.h>
|
#include <LibWeb/DOM/MutationObserver.h>
|
||||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||||
|
|
||||||
|
@ -31,6 +32,10 @@ struct WebEngineCustomData final : public JS::VM::CustomData {
|
||||||
NonnullRefPtrVector<DOM::MutationObserver> mutation_observers;
|
NonnullRefPtrVector<DOM::MutationObserver> mutation_observers;
|
||||||
|
|
||||||
OwnPtr<JS::ExecutionContext> root_execution_context;
|
OwnPtr<JS::ExecutionContext> root_execution_context;
|
||||||
|
|
||||||
|
// This object is used as the global object for GC-allocated objects that don't
|
||||||
|
// belong to a web-facing global object.
|
||||||
|
JS::Handle<Bindings::WindowObject> internal_window_object;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData {
|
struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData {
|
||||||
|
@ -48,6 +53,7 @@ struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData
|
||||||
|
|
||||||
HTML::ClassicScript* active_script();
|
HTML::ClassicScript* active_script();
|
||||||
JS::VM& main_thread_vm();
|
JS::VM& main_thread_vm();
|
||||||
|
Bindings::WindowObject& main_thread_internal_window_object();
|
||||||
void queue_mutation_observer_microtask(DOM::Document&);
|
void queue_mutation_observer_microtask(DOM::Document&);
|
||||||
NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM&, Function<JS::GlobalObject*(JS::Realm&)> create_global_object, Function<JS::GlobalObject*(JS::Realm&)> create_global_this_value);
|
NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM&, Function<JS::GlobalObject*(JS::Realm&)> create_global_object, Function<JS::GlobalObject*(JS::Realm&)> create_global_this_value);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue