summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/Scripting
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2022-09-24 15:39:23 -0600
committerLinus Groh <mail@linusgroh.de>2022-10-01 21:05:32 +0100
commitc61a4f35dc224818ac4c0e69109ed586d7c8666a (patch)
treeea7abb554882604ced1ef19907489b755dfd92a6 /Userland/Libraries/LibWeb/HTML/Scripting
parent01c2cffccab7f066079eb344ed2ce9aab818c632 (diff)
downloadserenity-c61a4f35dc224818ac4c0e69109ed586d7c8666a.zip
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 :^).
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/Scripting')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp6
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/Environments.h4
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp13
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h16
5 files changed, 29 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp
index b35390f70d..e28b49922d 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp
@@ -286,7 +286,7 @@ EnvironmentSettingsObject& incumbent_settings_object()
}
// 3. Return context's Realm component's settings object.
- return verify_cast<EnvironmentSettingsObject>(*context->realm->host_defined());
+ return Bindings::host_defined_environment_settings_object(*context->realm);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-incumbent-realm
@@ -310,7 +310,7 @@ EnvironmentSettingsObject& current_settings_object()
auto& vm = event_loop.vm();
// Then, the current settings object is the environment settings object of the current Realm Record.
- return verify_cast<EnvironmentSettingsObject>(*vm.current_realm()->host_defined());
+ return Bindings::host_defined_environment_settings_object(*vm.current_realm());
}
// https://html.spec.whatwg.org/multipage/webappapis.html#current-global-object
@@ -334,7 +334,7 @@ JS::Realm& relevant_realm(JS::Object const& object)
EnvironmentSettingsObject& relevant_settings_object(JS::Object const& object)
{
// Then, the relevant settings object for a platform object o is the environment settings object of the relevant Realm for o.
- return verify_cast<EnvironmentSettingsObject>(*relevant_realm(object).host_defined());
+ return Bindings::host_defined_environment_settings_object(relevant_realm(object));
}
EnvironmentSettingsObject& relevant_settings_object(DOM::Node const& node)
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h
index c8fee5dd64..c2f34b1466 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h
@@ -54,7 +54,9 @@ enum class RunScriptDecision {
// https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
struct EnvironmentSettingsObject
: public Environment
- , public JS::Realm::HostDefined {
+ , public JS::Cell {
+ JS_CELL(EnvironmentSettingsObject, JS::Cell);
+
virtual ~EnvironmentSettingsObject() override;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-target-browsing-context
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp
index ad343bc023..94e861c64b 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp
@@ -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
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h
index 48f3196d0e..47c25d9e85 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h
@@ -12,6 +12,8 @@
namespace Web::HTML {
class WindowEnvironmentSettingsObject final : public EnvironmentSettingsObject {
+ JS_CELL(WindowEnvironmentSettingsObject, EnvironmentSettingsObject);
+
public:
static void setup(AK::URL const& creation_url, NonnullOwnPtr<JS::ExecutionContext>, Optional<Environment>, AK::URL top_level_creation_url, Origin top_level_origin);
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h b/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h
index 8631a88cd8..cac5fb546a 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h
@@ -13,23 +13,27 @@
namespace Web::HTML {
class WorkerEnvironmentSettingsObject final
- : public EnvironmentSettingsObject
- , public Weakable<WorkerEnvironmentSettingsObject> {
+ : public EnvironmentSettingsObject {
+ JS_CELL(WindowEnvironmentSettingsObject, EnvironmentSettingsObject);
+
public:
WorkerEnvironmentSettingsObject(NonnullOwnPtr<JS::ExecutionContext> execution_context)
: EnvironmentSettingsObject(move(execution_context))
{
}
- static WeakPtr<WorkerEnvironmentSettingsObject> setup(NonnullOwnPtr<JS::ExecutionContext> execution_context /* FIXME: null or an environment reservedEnvironment, a URL topLevelCreationURL, and an origin topLevelOrigin */)
+ static JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> setup(NonnullOwnPtr<JS::ExecutionContext> execution_context /* FIXME: null or an environment reservedEnvironment, a URL topLevelCreationURL, and an origin topLevelOrigin */)
{
auto* realm = execution_context->realm;
VERIFY(realm);
- auto settings_object = adopt_own(*new WorkerEnvironmentSettingsObject(move(execution_context)));
+ auto settings_object = realm->heap().allocate<WorkerEnvironmentSettingsObject>(*realm, move(execution_context));
settings_object->target_browsing_context = nullptr;
- realm->set_host_defined(move(settings_object));
- return static_cast<WorkerEnvironmentSettingsObject*>(realm->host_defined());
+ 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));
+
+ return *settings_object;
}
virtual ~WorkerEnvironmentSettingsObject() override = default;