mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 16:27:36 +00:00
LibJS+LibWeb: Restore type safety of Realm::set_global_object()
The changes from 8a03b17
to allow any JS::Value aren't a good fit, as
shown by the excessive amount of verify_cast needed :^)
This commit is contained in:
parent
64b29eb459
commit
c8f1651761
10 changed files with 27 additions and 36 deletions
|
@ -367,7 +367,7 @@ void queue_mutation_observer_microtask(DOM::Document& document)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-new-javascript-realm
|
||||
NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM& vm, Function<JS::Value(JS::Realm&)> create_global_object, Function<JS::Value(JS::Realm&)> create_global_this_value)
|
||||
NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM& vm, Function<JS::GlobalObject*(JS::Realm&)> create_global_object, Function<JS::GlobalObject*(JS::Realm&)> create_global_this_value)
|
||||
{
|
||||
// 1. Perform InitializeHostDefinedRealm() with the provided customizations for creating the global object and the global this binding.
|
||||
// 2. Let realm execution context be the running JavaScript execution context.
|
||||
|
|
|
@ -49,6 +49,6 @@ struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData
|
|||
HTML::ClassicScript* active_script();
|
||||
JS::VM& main_thread_vm();
|
||||
void queue_mutation_observer_microtask(DOM::Document&);
|
||||
NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM&, Function<JS::Value(JS::Realm&)> create_global_object, Function<JS::Value(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);
|
||||
|
||||
}
|
||||
|
|
|
@ -168,16 +168,16 @@ NonnullRefPtr<Document> Document::create_and_initialize(Type type, String conten
|
|||
// 5. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
|
||||
auto realm_execution_context = Bindings::create_a_new_javascript_realm(
|
||||
Bindings::main_thread_vm(),
|
||||
[&](JS::Realm& realm) -> JS::Value {
|
||||
[&](JS::Realm& realm) -> JS::GlobalObject* {
|
||||
// - For the global object, create a new Window object.
|
||||
window = HTML::Window::create();
|
||||
auto* global_object = realm.heap().allocate_without_global_object<Bindings::WindowObject>(realm, *window);
|
||||
VERIFY(window->wrapper() == global_object);
|
||||
return global_object;
|
||||
},
|
||||
[](JS::Realm&) -> JS::Value {
|
||||
[](JS::Realm&) -> JS::GlobalObject* {
|
||||
// FIXME: - For the global this binding, use browsingContext's WindowProxy object.
|
||||
return JS::js_undefined();
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
// 6. Let topLevelCreationURL be creationURL.
|
||||
|
|
|
@ -121,16 +121,16 @@ NonnullRefPtr<BrowsingContext> BrowsingContext::create_a_new_browsing_context(Pa
|
|||
// 8. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
|
||||
auto realm_execution_context = Bindings::create_a_new_javascript_realm(
|
||||
Bindings::main_thread_vm(),
|
||||
[&](JS::Realm& realm) -> JS::Value {
|
||||
[&](JS::Realm& realm) -> JS::GlobalObject* {
|
||||
// - For the global object, create a new Window object.
|
||||
window = HTML::Window::create();
|
||||
auto* global_object = realm.heap().allocate_without_global_object<Bindings::WindowObject>(realm, *window);
|
||||
VERIFY(window->wrapper() == global_object);
|
||||
return global_object;
|
||||
},
|
||||
[](JS::Realm&) -> JS::Value {
|
||||
[](JS::Realm&) -> JS::GlobalObject* {
|
||||
// FIXME: - For the global this binding, use browsingContext's WindowProxy object.
|
||||
return JS::js_undefined();
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
// 9. Let topLevelCreationURL be about:blank if embedder is null; otherwise embedder's relevant settings object's top-level creation URL.
|
||||
|
|
|
@ -102,7 +102,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti
|
|||
// 7. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
|
||||
auto realm_execution_context = Bindings::create_a_new_javascript_realm(
|
||||
*m_worker_vm,
|
||||
[&](JS::Realm& realm) -> JS::Value {
|
||||
[&](JS::Realm& realm) -> JS::GlobalObject* {
|
||||
// 7a. For the global object, if is shared is true, create a new SharedWorkerGlobalScope object.
|
||||
// 7b. Otherwise, create a new DedicatedWorkerGlobalScope object.
|
||||
// FIXME: Proper support for both SharedWorkerGlobalScope and DedicatedWorkerGlobalScope
|
||||
|
@ -113,9 +113,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti
|
|||
m_worker_scope = m_worker_vm->heap().allocate_without_global_object<JS::GlobalObject>(realm);
|
||||
return m_worker_scope;
|
||||
},
|
||||
[&](JS::Realm&) -> JS::Value {
|
||||
return JS::js_undefined();
|
||||
});
|
||||
nullptr);
|
||||
m_worker_realm = realm_execution_context->realm;
|
||||
|
||||
m_console = adopt_ref(*new WorkerDebugConsoleClient(m_worker_scope->console()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue