LibWeb: Move Web prototypes and constructors to new Intrinsics object

This Intrinsics object hangs off of a new HostDefined struct that takes
the place of EnvironmentSettingsObject as the true [[HostDefined]] slot
on JS::Realm objects created by LibWeb.

This gets the intrinsics off of the GlobalObject, Window, similar to the
previous refactor of LibJS to move the intrinsics into the Realm's
[[Intrinics]] internal slot.

A side effect of this change is that we cannot fully initialize a Window
object until the [[HostDefined]] slot has been installed into the realm,
which happens with the creation of the WindowEnvironmentSettingsObject.

As such, any Window usage that has not been funned through a WindowESO
will not have any cached Web prototyped or constructors, and will not
have Window APIs available to javascript code. Currently this seems
limited to usage of Window in the CSS parser, but a subsequent commit
will clean those up to take Realm as well. However, this commit compiles
so let's cut it off here :^).
This commit is contained in:
Andrew Kaster 2022-09-24 15:39:23 -06:00 committed by Linus Groh
parent 01c2cffcca
commit c61a4f35dc
Notes: sideshowbarker 2024-07-17 06:28:43 +09:00
22 changed files with 240 additions and 60 deletions

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/HostDefined.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
#include <LibWeb/HTML/Window.h>
@ -36,7 +38,7 @@ void WindowEnvironmentSettingsObject::setup(AK::URL const& creation_url, Nonnull
// 3. Let settings object be a new environment settings object whose algorithms are defined as follows:
// NOTE: See the functions defined for this class.
auto settings_object = adopt_own(*new WindowEnvironmentSettingsObject(window, move(execution_context)));
auto* settings_object = realm->heap().allocate<WindowEnvironmentSettingsObject>(*realm, window, move(execution_context));
// 4. If reservedEnvironment is non-null, then:
if (reserved_environment.has_value()) {
@ -68,7 +70,14 @@ void WindowEnvironmentSettingsObject::setup(AK::URL const& creation_url, Nonnull
settings_object->top_level_origin = top_level_origin;
// 7. Set realm's [[HostDefined]] field to settings object.
realm->set_host_defined(move(settings_object));
// Non-Standard: We store the ESO next to the web intrinsics in a custom HostDefined object
auto* intrinsics = realm->heap().allocate<Bindings::Intrinsics>(*realm, *realm);
auto host_defined = make<Bindings::HostDefined>(*settings_object, *intrinsics);
realm->set_host_defined(move(host_defined));
// Non-Standard: We cannot fully initialize window object until *after* the we set up
// the realm's [[HostDefined]] internal slot as the internal slot contains the web platform intrinsics
window.initialize_web_interfaces({});
}
// https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:responsible-document