Browse Source

LibWeb: Remove unecessary dependence on Window from CSS classes

These classes only needed Window to get at its realm. Pass a realm
directly to construct CSS classes.
Andrew Kaster 2 years ago
parent
commit
a2ccb00e1d
37 changed files with 159 additions and 146 deletions
  1. 5 4
      Userland/Libraries/LibWeb/CSS/CSSConditionRule.cpp
  2. 1 1
      Userland/Libraries/LibWeb/CSS/CSSConditionRule.h
  3. 7 6
      Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp
  4. 2 2
      Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h
  5. 5 3
      Userland/Libraries/LibWeb/CSS/CSSGroupingRule.cpp
  6. 1 1
      Userland/Libraries/LibWeb/CSS/CSSGroupingRule.h
  7. 6 4
      Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp
  8. 0 1
      Userland/Libraries/LibWeb/CSS/CSSImportRule.h
  9. 8 6
      Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp
  10. 2 2
      Userland/Libraries/LibWeb/CSS/CSSMediaRule.h
  11. 2 3
      Userland/Libraries/LibWeb/CSS/CSSRule.cpp
  12. 2 2
      Userland/Libraries/LibWeb/CSS/CSSRule.h
  13. 12 10
      Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
  14. 4 3
      Userland/Libraries/LibWeb/CSS/CSSRuleList.h
  15. 11 10
      Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp
  16. 4 4
      Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h
  17. 7 6
      Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp
  18. 2 2
      Userland/Libraries/LibWeb/CSS/CSSStyleRule.h
  19. 8 6
      Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp
  20. 3 2
      Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h
  21. 7 6
      Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp
  22. 2 2
      Userland/Libraries/LibWeb/CSS/CSSSupportsRule.h
  23. 6 5
      Userland/Libraries/LibWeb/CSS/MediaList.cpp
  24. 2 2
      Userland/Libraries/LibWeb/CSS/MediaList.h
  25. 3 1
      Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp
  26. 6 11
      Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp
  27. 3 3
      Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.h
  28. 19 19
      Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
  29. 3 3
      Userland/Libraries/LibWeb/CSS/Parser/Parser.h
  30. 4 5
      Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
  31. 2 1
      Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h
  32. 3 1
      Userland/Libraries/LibWeb/CSS/Screen.cpp
  33. 0 2
      Userland/Libraries/LibWeb/CSS/Screen.h
  34. 2 3
      Userland/Libraries/LibWeb/CSS/StyleSheet.cpp
  35. 1 1
      Userland/Libraries/LibWeb/CSS/StyleSheet.h
  36. 3 2
      Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp
  37. 1 1
      Userland/Libraries/LibWeb/DOM/Document.cpp

+ 5 - 4
Userland/Libraries/LibWeb/CSS/CSSConditionRule.cpp

@@ -5,15 +5,16 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/CSSConditionRulePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSConditionRule.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-CSSConditionRule::CSSConditionRule(HTML::Window& window_object, CSSRuleList& rules)
-    : CSSGroupingRule(window_object, rules)
+CSSConditionRule::CSSConditionRule(JS::Realm& realm, CSSRuleList& rules)
+    : CSSGroupingRule(realm, rules)
 {
-    set_prototype(&window_object.cached_web_prototype("CSSConditionRule"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSConditionRulePrototype>(realm, "CSSConditionRule"));
 }
 
 void CSSConditionRule::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const

+ 1 - 1
Userland/Libraries/LibWeb/CSS/CSSConditionRule.h

@@ -25,7 +25,7 @@ public:
     virtual void for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const override;
 
 protected:
-    explicit CSSConditionRule(HTML::Window&, CSSRuleList&);
+    CSSConditionRule(JS::Realm&, CSSRuleList&);
 };
 
 }

+ 7 - 6
Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp

@@ -5,22 +5,23 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/CSSFontFaceRulePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSFontFaceRule.h>
 #include <LibWeb/CSS/Serialize.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-CSSFontFaceRule* CSSFontFaceRule::create(HTML::Window& window_object, FontFace&& font_face)
+CSSFontFaceRule* CSSFontFaceRule::create(JS::Realm& realm, FontFace&& font_face)
 {
-    return window_object.heap().allocate<CSSFontFaceRule>(window_object.realm(), window_object, move(font_face));
+    return realm.heap().allocate<CSSFontFaceRule>(realm, realm, move(font_face));
 }
 
-CSSFontFaceRule::CSSFontFaceRule(HTML::Window& window_object, FontFace&& font_face)
-    : CSSRule(window_object)
+CSSFontFaceRule::CSSFontFaceRule(JS::Realm& realm, FontFace&& font_face)
+    : CSSRule(realm)
     , m_font_face(move(font_face))
 {
-    set_prototype(&window_object.cached_web_prototype("CSSFontFaceRule"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSFontFaceRulePrototype>(realm, "CSSFontFaceRule"));
 }
 
 CSSStyleDeclaration* CSSFontFaceRule::style()

+ 2 - 2
Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h

@@ -16,7 +16,7 @@ class CSSFontFaceRule final : public CSSRule {
     WEB_PLATFORM_OBJECT(CSSFontFaceRule, CSSRule);
 
 public:
-    static CSSFontFaceRule* create(HTML::Window&, FontFace&&);
+    static CSSFontFaceRule* create(JS::Realm&, FontFace&&);
 
     virtual ~CSSFontFaceRule() override = default;
 
@@ -26,7 +26,7 @@ public:
     CSSStyleDeclaration* style();
 
 private:
-    explicit CSSFontFaceRule(HTML::Window&, FontFace&&);
+    CSSFontFaceRule(JS::Realm&, FontFace&&);
 
     virtual String serialized() const override;
 

+ 5 - 3
Userland/Libraries/LibWeb/CSS/CSSGroupingRule.cpp

@@ -5,6 +5,8 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/CSSGroupingRulePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/Bindings/MainThreadVM.h>
 #include <LibWeb/CSS/CSSGroupingRule.h>
 #include <LibWeb/CSS/CSSRuleList.h>
@@ -12,11 +14,11 @@
 
 namespace Web::CSS {
 
-CSSGroupingRule::CSSGroupingRule(HTML::Window& window_object, CSSRuleList& rules)
-    : CSSRule(window_object)
+CSSGroupingRule::CSSGroupingRule(JS::Realm& realm, CSSRuleList& rules)
+    : CSSRule(realm)
     , m_rules(rules)
 {
-    set_prototype(&window_object.cached_web_prototype("CSSGroupingRule"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSGroupingRulePrototype>(realm, "CSSGroupingRule"));
     for (auto& rule : m_rules)
         rule.set_parent_rule(this);
 }

+ 1 - 1
Userland/Libraries/LibWeb/CSS/CSSGroupingRule.h

@@ -31,7 +31,7 @@ public:
     virtual void set_parent_style_sheet(CSSStyleSheet*) override;
 
 protected:
-    explicit CSSGroupingRule(HTML::Window&, CSSRuleList&);
+    CSSGroupingRule(JS::Realm&, CSSRuleList&);
     virtual void visit_edges(Cell::Visitor&) override;
 
 private:

+ 6 - 4
Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp

@@ -8,6 +8,8 @@
 
 #include <AK/Debug.h>
 #include <AK/URL.h>
+#include <LibWeb/Bindings/CSSImportRulePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSImportRule.h>
 #include <LibWeb/CSS/Parser/Parser.h>
 #include <LibWeb/DOM/Document.h>
@@ -18,16 +20,16 @@ namespace Web::CSS {
 
 CSSImportRule* CSSImportRule::create(AK::URL url, DOM::Document& document)
 {
-    auto& window_object = document.window();
-    return window_object.heap().allocate<CSSImportRule>(window_object.realm(), move(url), document);
+    auto& realm = document.realm();
+    return realm.heap().allocate<CSSImportRule>(realm, move(url), document);
 }
 
 CSSImportRule::CSSImportRule(AK::URL url, DOM::Document& document)
-    : CSSRule(document.window())
+    : CSSRule(document.realm())
     , m_url(move(url))
     , m_document(document)
 {
-    set_prototype(&document.window().cached_web_prototype("CSSImportRule"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSImportRulePrototype>(document.realm(), "CSSImportRule"));
 
     dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Loading import URL: {}", m_url);
     auto request = LoadRequest::create_for_url_on_page(m_url, document.page());

+ 0 - 1
Userland/Libraries/LibWeb/CSS/CSSImportRule.h

@@ -9,7 +9,6 @@
 #pragma once
 
 #include <AK/URL.h>
-#include <LibJS/Heap/Handle.h>
 #include <LibWeb/CSS/CSSRule.h>
 #include <LibWeb/CSS/CSSStyleSheet.h>
 #include <LibWeb/DOM/DocumentLoadEventDelayer.h>

+ 8 - 6
Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp

@@ -5,21 +5,23 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibJS/Runtime/Realm.h>
+#include <LibWeb/Bindings/CSSMediaRulePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSMediaRule.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-CSSMediaRule* CSSMediaRule::create(HTML::Window& window_object, MediaList& media_queries, CSSRuleList& rules)
+CSSMediaRule* CSSMediaRule::create(JS::Realm& realm, MediaList& media_queries, CSSRuleList& rules)
 {
-    return window_object.heap().allocate<CSSMediaRule>(window_object.realm(), window_object, media_queries, rules);
+    return realm.heap().allocate<CSSMediaRule>(realm, realm, media_queries, rules);
 }
 
-CSSMediaRule::CSSMediaRule(HTML::Window& window_object, MediaList& media, CSSRuleList& rules)
-    : CSSConditionRule(window_object, rules)
+CSSMediaRule::CSSMediaRule(JS::Realm& realm, MediaList& media, CSSRuleList& rules)
+    : CSSConditionRule(realm, rules)
     , m_media(media)
 {
-    set_prototype(&window_object.cached_web_prototype("CSSMediaRule"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSMediaRulePrototype>(realm, "CSSMediaRule"));
 }
 
 void CSSMediaRule::visit_edges(Cell::Visitor& visitor)

+ 2 - 2
Userland/Libraries/LibWeb/CSS/CSSMediaRule.h

@@ -18,7 +18,7 @@ class CSSMediaRule final : public CSSConditionRule {
     WEB_PLATFORM_OBJECT(CSSMediaRule, CSSConditionRule);
 
 public:
-    static CSSMediaRule* create(HTML::Window&, MediaList& media_queries, CSSRuleList&);
+    static CSSMediaRule* create(JS::Realm&, MediaList& media_queries, CSSRuleList&);
 
     virtual ~CSSMediaRule() = default;
 
@@ -33,7 +33,7 @@ public:
     bool evaluate(HTML::Window const& window) { return m_media.evaluate(window); }
 
 private:
-    explicit CSSMediaRule(HTML::Window&, MediaList&, CSSRuleList&);
+    CSSMediaRule(JS::Realm&, MediaList&, CSSRuleList&);
 
     virtual void visit_edges(Cell::Visitor&) override;
     virtual String serialized() const override;

+ 2 - 3
Userland/Libraries/LibWeb/CSS/CSSRule.cpp

@@ -8,12 +8,11 @@
 
 #include <LibWeb/CSS/CSSRule.h>
 #include <LibWeb/CSS/CSSStyleSheet.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-CSSRule::CSSRule(HTML::Window& window_object)
-    : PlatformObject(window_object.cached_web_prototype("CSSRule"))
+CSSRule::CSSRule(JS::Realm& realm)
+    : PlatformObject(realm)
 {
 }
 

+ 2 - 2
Userland/Libraries/LibWeb/CSS/CSSRule.h

@@ -16,7 +16,7 @@
 namespace Web::CSS {
 
 class CSSRule : public Bindings::PlatformObject {
-    WEB_PLATFORM_OBJECT(CSSRule, JS::Object);
+    WEB_PLATFORM_OBJECT(CSSRule, Bindings::PlatformObject);
 
 public:
     virtual ~CSSRule() = default;
@@ -45,7 +45,7 @@ public:
     bool fast_is() const = delete;
 
 protected:
-    explicit CSSRule(HTML::Window&);
+    explicit CSSRule(JS::Realm&);
 
     virtual String serialized() const = 0;
 

+ 12 - 10
Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp

@@ -5,6 +5,8 @@
  */
 
 #include <AK/TypeCasts.h>
+#include <LibWeb/Bindings/CSSRuleListPrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSImportRule.h>
 #include <LibWeb/CSS/CSSMediaRule.h>
 #include <LibWeb/CSS/CSSRule.h>
@@ -15,22 +17,22 @@
 
 namespace Web::CSS {
 
-CSSRuleList* CSSRuleList::create(HTML::Window& window_object, JS::MarkedVector<CSSRule*> const& rules)
+CSSRuleList* CSSRuleList::create(JS::Realm& realm, JS::MarkedVector<CSSRule*> const& rules)
 {
-    auto* rule_list = window_object.heap().allocate<CSSRuleList>(window_object.realm(), window_object);
+    auto* rule_list = realm.heap().allocate<CSSRuleList>(realm, realm);
     for (auto* rule : rules)
         rule_list->m_rules.append(*rule);
     return rule_list;
 }
 
-CSSRuleList::CSSRuleList(HTML::Window& window_object)
-    : Bindings::LegacyPlatformObject(window_object.cached_web_prototype("CSSRuleList"))
+CSSRuleList::CSSRuleList(JS::Realm& realm)
+    : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype<Bindings::CSSRuleListPrototype>(realm, "CSSRuleList"))
 {
 }
 
-CSSRuleList* CSSRuleList::create_empty(HTML::Window& window_object)
+CSSRuleList* CSSRuleList::create_empty(JS::Realm& realm)
 {
-    return window_object.heap().allocate<CSSRuleList>(window_object.realm(), window_object);
+    return realm.heap().allocate<CSSRuleList>(realm, realm);
 }
 
 void CSSRuleList::visit_edges(Cell::Visitor& visitor)
@@ -55,7 +57,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
 
     // 2. If index is greater than length, then throw an IndexSizeError exception.
     if (index > length)
-        return WebIDL::IndexSizeError::create(global_object(), "CSS rule index out of bounds.");
+        return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds.");
 
     // 3. Set new rule to the results of performing parse a CSS rule on argument rule.
     // NOTE: The insert-a-css-rule spec expects `rule` to be a string, but the CSSStyleSheet.insertRule()
@@ -64,7 +66,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
     CSSRule* new_rule = nullptr;
     if (rule.has<StringView>()) {
         new_rule = parse_css_rule(
-            CSS::Parser::ParsingContext { static_cast<HTML::Window&>(global_object()) },
+            CSS::Parser::ParsingContext { realm() },
             rule.get<StringView>());
     } else {
         new_rule = rule.get<CSSRule*>();
@@ -72,7 +74,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
 
     // 4. If new rule is a syntax error, throw a SyntaxError exception.
     if (!new_rule)
-        return WebIDL::SyntaxError::create(global_object(), "Unable to parse CSS rule.");
+        return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule.");
 
     // FIXME: 5. If new rule cannot be inserted into list at the zero-index position index due to constraints specified by CSS, then throw a HierarchyRequestError exception. [CSS21]
 
@@ -93,7 +95,7 @@ WebIDL::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index)
 
     // 2. If index is greater than or equal to length, then throw an IndexSizeError exception.
     if (index >= length)
-        return WebIDL::IndexSizeError::create(global_object(), "CSS rule index out of bounds.");
+        return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds.");
 
     // 3. Set old rule to the indexth item in list.
     CSSRule& old_rule = m_rules[index];

+ 4 - 3
Userland/Libraries/LibWeb/CSS/CSSRuleList.h

@@ -23,10 +23,9 @@ class CSSRuleList : public Bindings::LegacyPlatformObject {
     WEB_PLATFORM_OBJECT(CSSRuleList, Bindings::LegacyPlatformObject);
 
 public:
-    static CSSRuleList* create(HTML::Window&, JS::MarkedVector<CSSRule*> const&);
-    static CSSRuleList* create_empty(HTML::Window&);
+    static CSSRuleList* create(JS::Realm&, JS::MarkedVector<CSSRule*> const&);
+    static CSSRuleList* create_empty(JS::Realm&);
 
-    explicit CSSRuleList(HTML::Window&);
     ~CSSRuleList() = default;
 
     CSSRule const* item(size_t index) const
@@ -65,6 +64,8 @@ public:
     bool evaluate_media_queries(HTML::Window const&);
 
 private:
+    explicit CSSRuleList(JS::Realm&);
+
     virtual void visit_edges(Cell::Visitor&) override;
 
     Vector<CSSRule&> m_rules;

+ 11 - 10
Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp

@@ -4,26 +4,27 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/CSSStyleDeclarationPrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSStyleDeclaration.h>
 #include <LibWeb/CSS/Parser/Parser.h>
 #include <LibWeb/DOM/Document.h>
 #include <LibWeb/DOM/Element.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-CSSStyleDeclaration::CSSStyleDeclaration(HTML::Window& window_object)
-    : PlatformObject(window_object.cached_web_prototype("CSSStyleDeclaration"))
+CSSStyleDeclaration::CSSStyleDeclaration(JS::Realm& realm)
+    : PlatformObject(Bindings::ensure_web_prototype<Bindings::CSSStyleDeclarationPrototype>(realm, "CSSStyleDeclaration"))
 {
 }
 
-PropertyOwningCSSStyleDeclaration* PropertyOwningCSSStyleDeclaration::create(HTML::Window& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
+PropertyOwningCSSStyleDeclaration* PropertyOwningCSSStyleDeclaration::create(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
 {
-    return window_object.heap().allocate<PropertyOwningCSSStyleDeclaration>(window_object.realm(), window_object, move(properties), move(custom_properties));
+    return realm.heap().allocate<PropertyOwningCSSStyleDeclaration>(realm, realm, move(properties), move(custom_properties));
 }
 
-PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(HTML::Window& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
-    : CSSStyleDeclaration(window_object)
+PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
+    : CSSStyleDeclaration(realm)
     , m_properties(move(properties))
     , m_custom_properties(move(custom_properties))
 {
@@ -38,12 +39,12 @@ String PropertyOwningCSSStyleDeclaration::item(size_t index) const
 
 ElementInlineCSSStyleDeclaration* ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
 {
-    auto& window_object = element.document().window();
-    return window_object.heap().allocate<ElementInlineCSSStyleDeclaration>(window_object.realm(), element, move(properties), move(custom_properties));
+    auto& realm = element.realm();
+    return realm.heap().allocate<ElementInlineCSSStyleDeclaration>(realm, element, move(properties), move(custom_properties));
 }
 
 ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
-    : PropertyOwningCSSStyleDeclaration(element.document().window(), move(properties), move(custom_properties))
+    : PropertyOwningCSSStyleDeclaration(element.realm(), move(properties), move(custom_properties))
     , m_element(element.make_weak_ptr<DOM::Element>())
 {
 }

+ 4 - 4
Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h

@@ -55,7 +55,7 @@ public:
     virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override;
 
 protected:
-    explicit CSSStyleDeclaration(HTML::Window&);
+    explicit CSSStyleDeclaration(JS::Realm&);
 };
 
 class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration {
@@ -63,7 +63,7 @@ class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration {
     friend class ElementInlineCSSStyleDeclaration;
 
 public:
-    static PropertyOwningCSSStyleDeclaration* create(HTML::Window&, Vector<StyleProperty>, HashMap<String, StyleProperty> custom_properties);
+    static PropertyOwningCSSStyleDeclaration* create(JS::Realm&, Vector<StyleProperty>, HashMap<String, StyleProperty> custom_properties);
 
     virtual ~PropertyOwningCSSStyleDeclaration() override = default;
 
@@ -83,7 +83,7 @@ public:
     virtual String serialized() const final override;
 
 protected:
-    PropertyOwningCSSStyleDeclaration(HTML::Window&, Vector<StyleProperty>, HashMap<String, StyleProperty>);
+    PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<String, StyleProperty>);
 
     virtual void update_style_attribute() { }
 
@@ -108,7 +108,7 @@ public:
     bool is_updating() const { return m_updating; }
 
 private:
-    explicit ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
+    ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
 
     virtual void visit_edges(Cell::Visitor&) override;
 

+ 7 - 6
Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp

@@ -4,23 +4,24 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/CSSStyleRulePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSStyleRule.h>
 #include <LibWeb/CSS/Parser/Parser.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-CSSStyleRule* CSSStyleRule::create(HTML::Window& window_object, NonnullRefPtrVector<Web::CSS::Selector>&& selectors, CSSStyleDeclaration& declaration)
+CSSStyleRule* CSSStyleRule::create(JS::Realm& realm, NonnullRefPtrVector<Web::CSS::Selector>&& selectors, CSSStyleDeclaration& declaration)
 {
-    return window_object.heap().allocate<CSSStyleRule>(window_object.realm(), window_object, move(selectors), declaration);
+    return realm.heap().allocate<CSSStyleRule>(realm, realm, move(selectors), declaration);
 }
 
-CSSStyleRule::CSSStyleRule(HTML::Window& window_object, NonnullRefPtrVector<Selector>&& selectors, CSSStyleDeclaration& declaration)
-    : CSSRule(window_object)
+CSSStyleRule::CSSStyleRule(JS::Realm& realm, NonnullRefPtrVector<Selector>&& selectors, CSSStyleDeclaration& declaration)
+    : CSSRule(realm)
     , m_selectors(move(selectors))
     , m_declaration(declaration)
 {
-    set_prototype(&window_object.cached_web_prototype("CSSStyleRule"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSStyleRulePrototype>(realm, "CSSStyleRule"));
 }
 
 void CSSStyleRule::visit_edges(Cell::Visitor& visitor)

+ 2 - 2
Userland/Libraries/LibWeb/CSS/CSSStyleRule.h

@@ -19,7 +19,7 @@ class CSSStyleRule final : public CSSRule {
     WEB_PLATFORM_OBJECT(CSSStyleRule, CSSRule);
 
 public:
-    static CSSStyleRule* create(HTML::Window&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&);
+    static CSSStyleRule* create(JS::Realm&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&);
 
     virtual ~CSSStyleRule() override = default;
 
@@ -34,7 +34,7 @@ public:
     CSSStyleDeclaration* style();
 
 private:
-    CSSStyleRule(HTML::Window&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&);
+    CSSStyleRule(JS::Realm&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&);
 
     virtual void visit_edges(Cell::Visitor&) override;
     virtual String serialized() const override;

+ 8 - 6
Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp

@@ -4,6 +4,8 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/CSSStyleSheetPrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSStyleSheet.h>
 #include <LibWeb/CSS/Parser/Parser.h>
 #include <LibWeb/CSS/StyleSheetList.h>
@@ -12,16 +14,16 @@
 
 namespace Web::CSS {
 
-CSSStyleSheet* CSSStyleSheet::create(HTML::Window& window_object, CSSRuleList& rules, Optional<AK::URL> location)
+CSSStyleSheet* CSSStyleSheet::create(JS::Realm& realm, CSSRuleList& rules, Optional<AK::URL> location)
 {
-    return window_object.heap().allocate<CSSStyleSheet>(window_object.realm(), window_object, rules, move(location));
+    return realm.heap().allocate<CSSStyleSheet>(realm, realm, rules, move(location));
 }
 
-CSSStyleSheet::CSSStyleSheet(HTML::Window& window_object, CSSRuleList& rules, Optional<AK::URL> location)
-    : StyleSheet(window_object)
+CSSStyleSheet::CSSStyleSheet(JS::Realm& realm, CSSRuleList& rules, Optional<AK::URL> location)
+    : StyleSheet(realm)
     , m_rules(&rules)
 {
-    set_prototype(&window_object.cached_web_prototype("CSSStyleSheet"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSStyleSheetPrototype>(realm, "CSSStyleSheet"));
 
     if (location.has_value())
         set_location(location->to_string());
@@ -50,7 +52,7 @@ WebIDL::ExceptionOr<unsigned> CSSStyleSheet::insert_rule(StringView rule, unsign
 
     // 4. If parsed rule is a syntax error, return parsed rule.
     if (!parsed_rule)
-        return WebIDL::SyntaxError::create(global_object(), "Unable to parse CSS rule.");
+        return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule.");
 
     // FIXME: 5. If parsed rule is an @import rule, and the constructed flag is set, throw a SyntaxError DOMException.
 

+ 3 - 2
Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h

@@ -24,9 +24,8 @@ class CSSStyleSheet final
     WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet);
 
 public:
-    static CSSStyleSheet* create(HTML::Window&, CSSRuleList& rules, Optional<AK::URL> location);
+    static CSSStyleSheet* create(JS::Realm&, CSSRuleList& rules, Optional<AK::URL> location);
 
-    explicit CSSStyleSheet(HTML::Window&, CSSRuleList&, Optional<AK::URL> location);
     virtual ~CSSStyleSheet() override = default;
 
     void set_owner_css_rule(CSSRule* rule) { m_owner_css_rule = rule; }
@@ -51,6 +50,8 @@ public:
     void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
 
 private:
+    CSSStyleSheet(JS::Realm&, CSSRuleList&, Optional<AK::URL> location);
+
     virtual void visit_edges(Cell::Visitor&) override;
 
     CSSRuleList* m_rules { nullptr };

+ 7 - 6
Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp

@@ -4,22 +4,23 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/CSSSupportsRulePrototype.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/CSSSupportsRule.h>
 #include <LibWeb/CSS/Parser/Parser.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-CSSSupportsRule* CSSSupportsRule::create(HTML::Window& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
+CSSSupportsRule* CSSSupportsRule::create(JS::Realm& realm, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
 {
-    return window_object.heap().allocate<CSSSupportsRule>(window_object.realm(), window_object, move(supports), rules);
+    return realm.heap().allocate<CSSSupportsRule>(realm, realm, move(supports), rules);
 }
 
-CSSSupportsRule::CSSSupportsRule(HTML::Window& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
-    : CSSConditionRule(window_object, rules)
+CSSSupportsRule::CSSSupportsRule(JS::Realm& realm, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
+    : CSSConditionRule(realm, rules)
     , m_supports(move(supports))
 {
-    set_prototype(&window_object.cached_web_prototype("CSSSupportsRule"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSSupportsRulePrototype>(realm, "CSSSupportsRule"));
 }
 
 String CSSSupportsRule::condition_text() const

+ 2 - 2
Userland/Libraries/LibWeb/CSS/CSSSupportsRule.h

@@ -20,7 +20,7 @@ class CSSSupportsRule final : public CSSConditionRule {
     WEB_PLATFORM_OBJECT(CSSSupportsRule, CSSConditionRule);
 
 public:
-    static CSSSupportsRule* create(HTML::Window&, NonnullRefPtr<Supports>&&, CSSRuleList&);
+    static CSSSupportsRule* create(JS::Realm&, NonnullRefPtr<Supports>&&, CSSRuleList&);
 
     virtual ~CSSSupportsRule() = default;
 
@@ -31,7 +31,7 @@ public:
     virtual bool condition_matches() const override { return m_supports->matches(); }
 
 private:
-    explicit CSSSupportsRule(HTML::Window&, NonnullRefPtr<Supports>&&, CSSRuleList&);
+    CSSSupportsRule(JS::Realm&, NonnullRefPtr<Supports>&&, CSSRuleList&);
 
     virtual String serialized() const override;
 

+ 6 - 5
Userland/Libraries/LibWeb/CSS/MediaList.cpp

@@ -5,19 +5,20 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/Bindings/MediaListPrototype.h>
 #include <LibWeb/CSS/MediaList.h>
 #include <LibWeb/CSS/Parser/Parser.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-MediaList* MediaList::create(HTML::Window& window_object, NonnullRefPtrVector<MediaQuery>&& media)
+MediaList* MediaList::create(JS::Realm& realm, NonnullRefPtrVector<MediaQuery>&& media)
 {
-    return window_object.heap().allocate<MediaList>(window_object.realm(), window_object, move(media));
+    return realm.heap().allocate<MediaList>(realm, realm, move(media));
 }
 
-MediaList::MediaList(HTML::Window& window_object, NonnullRefPtrVector<MediaQuery>&& media)
-    : Bindings::LegacyPlatformObject(window_object.cached_web_prototype("MediaList"))
+MediaList::MediaList(JS::Realm& realm, NonnullRefPtrVector<MediaQuery>&& media)
+    : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype<Bindings::MediaListPrototype>(realm, "MediaList"))
     , m_media(move(media))
 {
 }

+ 2 - 2
Userland/Libraries/LibWeb/CSS/MediaList.h

@@ -20,7 +20,7 @@ class MediaList final : public Bindings::LegacyPlatformObject {
     WEB_PLATFORM_OBJECT(MediaList, Bindings::LegacyPlatformObject);
 
 public:
-    static MediaList* create(HTML::Window&, NonnullRefPtrVector<MediaQuery>&& media);
+    static MediaList* create(JS::Realm&, NonnullRefPtrVector<MediaQuery>&& media);
     ~MediaList() = default;
 
     String media_text() const;
@@ -37,7 +37,7 @@ public:
     bool matches() const;
 
 private:
-    explicit MediaList(HTML::Window&, NonnullRefPtrVector<MediaQuery>&&);
+    MediaList(JS::Realm&, NonnullRefPtrVector<MediaQuery>&&);
 
     NonnullRefPtrVector<MediaQuery> m_media;
 };

+ 3 - 1
Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp

@@ -5,6 +5,8 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/Bindings/MediaQueryListPrototype.h>
 #include <LibWeb/CSS/MediaQueryList.h>
 #include <LibWeb/DOM/Document.h>
 #include <LibWeb/DOM/EventDispatcher.h>
@@ -23,7 +25,7 @@ MediaQueryList::MediaQueryList(DOM::Document& document, NonnullRefPtrVector<Medi
     , m_document(document)
     , m_media(move(media))
 {
-    set_prototype(&document.window().cached_web_prototype("MediaQueryList"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::MediaQueryListPrototype>(document.realm(), "MediaQueryList"));
     evaluate();
 }
 

+ 6 - 11
Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp

@@ -4,28 +4,23 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/Bindings/MediaQueryListEventPrototype.h>
 #include <LibWeb/CSS/MediaQueryListEvent.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-MediaQueryListEvent* MediaQueryListEvent::create(HTML::Window& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init)
+MediaQueryListEvent* MediaQueryListEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MediaQueryListEventInit const& event_init)
 {
-    return window_object.heap().allocate<MediaQueryListEvent>(window_object.realm(), window_object, event_name, event_init);
+    return realm.heap().allocate<MediaQueryListEvent>(realm, realm, event_name, event_init);
 }
 
-MediaQueryListEvent* MediaQueryListEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init)
-{
-    return create(window_object, event_name, event_init);
-}
-
-MediaQueryListEvent::MediaQueryListEvent(HTML::Window& window_object, FlyString const& event_name, MediaQueryListEventInit const& event_init)
-    : DOM::Event(window_object, event_name, event_init)
+MediaQueryListEvent::MediaQueryListEvent(JS::Realm& realm, FlyString const& event_name, MediaQueryListEventInit const& event_init)
+    : DOM::Event(realm, event_name, event_init)
     , m_media(event_init.media)
     , m_matches(event_init.matches)
 {
-    set_prototype(&window_object.cached_web_prototype("MediaQueryListEvent"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::MediaQueryListEventPrototype>(realm, "MediaQueryListEvent"));
 }
 
 MediaQueryListEvent::~MediaQueryListEvent() = default;

+ 3 - 3
Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.h

@@ -19,16 +19,16 @@ class MediaQueryListEvent final : public DOM::Event {
     WEB_PLATFORM_OBJECT(MediaQueryListEvent, DOM::Event);
 
 public:
-    static MediaQueryListEvent* create(HTML::Window&, FlyString const& event_name, MediaQueryListEventInit const& event_init = {});
-    static MediaQueryListEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, MediaQueryListEventInit const& event_init);
+    static MediaQueryListEvent* construct_impl(JS::Realm&, FlyString const& event_name, MediaQueryListEventInit const& event_init = {});
 
-    MediaQueryListEvent(HTML::Window&, FlyString const& event_name, MediaQueryListEventInit const& event_init);
     virtual ~MediaQueryListEvent() override;
 
     String const& media() const { return m_media; }
     bool matches() const { return m_matches; }
 
 private:
+    MediaQueryListEvent(JS::Realm&, FlyString const& event_name, MediaQueryListEventInit const& event_init);
+
     String m_media;
     bool m_matches;
 };

+ 19 - 19
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -40,31 +40,31 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur
 namespace Web::CSS::Parser {
 
 ParsingContext::ParsingContext()
-    : m_window_object(Bindings::main_thread_internal_window_object())
+    : m_realm(*Bindings::main_thread_vm().current_realm())
 {
 }
 
-ParsingContext::ParsingContext(HTML::Window& window_object)
-    : m_window_object(window_object)
+ParsingContext::ParsingContext(JS::Realm& realm)
+    : m_realm(realm)
 {
 }
 
 ParsingContext::ParsingContext(DOM::Document const& document, AK::URL url)
-    : m_window_object(const_cast<HTML::Window&>(document.window()))
+    : m_realm(const_cast<JS::Realm&>(document.realm()))
     , m_document(&document)
     , m_url(move(url))
 {
 }
 
 ParsingContext::ParsingContext(DOM::Document const& document)
-    : m_window_object(const_cast<HTML::Window&>(document.window()))
+    : m_realm(const_cast<JS::Realm&>(document.realm()))
     , m_document(&document)
     , m_url(document.url())
 {
 }
 
 ParsingContext::ParsingContext(DOM::ParentNode& parent_node)
-    : m_window_object(parent_node.document().window())
+    : m_realm(parent_node.realm())
     , m_document(&parent_node.document())
     , m_url(parent_node.document().url())
 {
@@ -118,7 +118,7 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<AK::URL> location)
     auto style_sheet = parse_a_stylesheet(m_token_stream, {});
 
     // Interpret all of the resulting top-level qualified rules as style rules, defined below.
-    JS::MarkedVector<CSSRule*> rules(m_context.window_object().heap());
+    JS::MarkedVector<CSSRule*> rules(m_context.realm().heap());
     for (auto& raw_rule : style_sheet.rules) {
         auto* rule = convert_to_rule(raw_rule);
         // If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, it’s a parse error. Discard that rule.
@@ -126,8 +126,8 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<AK::URL> location)
             rules.append(rule);
     }
 
-    auto* rule_list = CSSRuleList::create(m_context.window_object(), rules);
-    return CSSStyleSheet::create(m_context.window_object(), *rule_list, move(location));
+    auto* rule_list = CSSRuleList::create(m_context.realm(), rules);
+    return CSSStyleSheet::create(m_context.realm(), *rule_list, move(location));
 }
 
 Optional<SelectorList> Parser::parse_as_selector(SelectorParsingMode parsing_mode)
@@ -2561,13 +2561,13 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
 
             auto child_tokens = TokenStream { rule->block()->values() };
             auto parser_rules = parse_a_list_of_rules(child_tokens);
-            JS::MarkedVector<CSSRule*> child_rules(m_context.window_object().heap());
+            JS::MarkedVector<CSSRule*> child_rules(m_context.realm().heap());
             for (auto& raw_rule : parser_rules) {
                 if (auto* child_rule = convert_to_rule(raw_rule))
                     child_rules.append(child_rule);
             }
-            auto* rule_list = CSSRuleList::create(m_context.window_object(), child_rules);
-            return CSSMediaRule::create(m_context.window_object(), *MediaList::create(m_context.window_object(), move(media_query_list)), *rule_list);
+            auto* rule_list = CSSRuleList::create(m_context.realm(), child_rules);
+            return CSSMediaRule::create(m_context.realm(), *MediaList::create(m_context.realm(), move(media_query_list)), *rule_list);
         }
         if (rule->at_rule_name().equals_ignoring_case("supports"sv)) {
             auto supports_tokens = TokenStream { rule->prelude() };
@@ -2584,14 +2584,14 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
                 return {};
             auto child_tokens = TokenStream { rule->block()->values() };
             auto parser_rules = parse_a_list_of_rules(child_tokens);
-            JS::MarkedVector<CSSRule*> child_rules(m_context.window_object().heap());
+            JS::MarkedVector<CSSRule*> child_rules(m_context.realm().heap());
             for (auto& raw_rule : parser_rules) {
                 if (auto* child_rule = convert_to_rule(raw_rule))
                     child_rules.append(child_rule);
             }
 
-            auto* rule_list = CSSRuleList::create(m_context.window_object(), child_rules);
-            return CSSSupportsRule::create(m_context.window_object(), supports.release_nonnull(), *rule_list);
+            auto* rule_list = CSSRuleList::create(m_context.realm(), child_rules);
+            return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), *rule_list);
         }
 
         // FIXME: More at rules!
@@ -2629,7 +2629,7 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
         return {};
     }
 
-    return CSSStyleRule::create(m_context.window_object(), move(selectors.value()), *declaration);
+    return CSSStyleRule::create(m_context.realm(), move(selectors.value()), *declaration);
 }
 
 auto Parser::extract_properties(Vector<DeclarationOrAtRule> const& declarations_and_at_rules) -> PropertiesAndCustomProperties
@@ -2658,7 +2658,7 @@ auto Parser::extract_properties(Vector<DeclarationOrAtRule> const& declarations_
 PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector<DeclarationOrAtRule> const& declarations_and_at_rules)
 {
     auto [properties, custom_properties] = extract_properties(declarations_and_at_rules);
-    return PropertyOwningCSSStyleDeclaration::create(m_context.window_object(), move(properties), move(custom_properties));
+    return PropertyOwningCSSStyleDeclaration::create(m_context.realm(), move(properties), move(custom_properties));
 }
 
 Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& declaration)
@@ -4890,7 +4890,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream<ComponentValue>& tokens)
         unicode_range.empend(0x0u, 0x10FFFFu);
     }
 
-    return CSSFontFaceRule::create(m_context.window_object(), FontFace { font_family.release_value(), move(src), move(unicode_range) });
+    return CSSFontFaceRule::create(m_context.realm(), FontFace { font_family.release_value(), move(src), move(unicode_range) });
 }
 
 Vector<FontFace::Source> Parser::parse_font_face_src(TokenStream<ComponentValue>& component_values)
@@ -6505,7 +6505,7 @@ namespace Web {
 CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& context, StringView css, Optional<AK::URL> location)
 {
     if (css.is_empty())
-        return CSS::CSSStyleSheet::create(context.window_object(), *CSS::CSSRuleList::create_empty(context.window_object()), location);
+        return CSS::CSSStyleSheet::create(context.realm(), *CSS::CSSRuleList::create_empty(context.realm()), location);
     CSS::Parser::Parser parser(context, css);
     return parser.parse_as_css_stylesheet(location);
 }

+ 3 - 3
Userland/Libraries/LibWeb/CSS/Parser/Parser.h

@@ -36,7 +36,7 @@ namespace Web::CSS::Parser {
 class ParsingContext {
 public:
     ParsingContext();
-    explicit ParsingContext(HTML::Window&);
+    explicit ParsingContext(JS::Realm&);
     explicit ParsingContext(DOM::Document const&);
     explicit ParsingContext(DOM::Document const&, AK::URL);
     explicit ParsingContext(DOM::ParentNode&);
@@ -48,10 +48,10 @@ public:
     PropertyID current_property_id() const { return m_current_property_id; }
     void set_current_property_id(PropertyID property_id) { m_current_property_id = property_id; }
 
-    HTML::Window& window_object() const { return m_window_object; }
+    JS::Realm& realm() const { return m_realm; }
 
 private:
-    HTML::Window& m_window_object;
+    JS::Realm& m_realm;
     DOM::Document const* m_document { nullptr };
     PropertyID m_current_property_id { PropertyID::Invalid };
     AK::URL m_url;

+ 4 - 5
Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp

@@ -21,12 +21,11 @@ namespace Web::CSS {
 
 ResolvedCSSStyleDeclaration* ResolvedCSSStyleDeclaration::create(DOM::Element& element)
 {
-    auto& window_object = element.document().window();
-    return window_object.heap().allocate<ResolvedCSSStyleDeclaration>(window_object.realm(), element);
+    return element.realm().heap().allocate<ResolvedCSSStyleDeclaration>(element.realm(), element);
 }
 
 ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element)
-    : CSSStyleDeclaration(element.document().window())
+    : CSSStyleDeclaration(element.realm())
     , m_element(element)
 {
 }
@@ -541,14 +540,14 @@ Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID propert
 WebIDL::ExceptionOr<void> ResolvedCSSStyleDeclaration::set_property(PropertyID, StringView, StringView)
 {
     // 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
-    return WebIDL::NoModificationAllowedError::create(global_object(), "Cannot modify properties in result of getComputedStyle()");
+    return WebIDL::NoModificationAllowedError::create(realm(), "Cannot modify properties in result of getComputedStyle()");
 }
 
 // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty
 WebIDL::ExceptionOr<String> ResolvedCSSStyleDeclaration::remove_property(PropertyID)
 {
     // 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
-    return WebIDL::NoModificationAllowedError::create(global_object(), "Cannot remove properties from result of getComputedStyle()");
+    return WebIDL::NoModificationAllowedError::create(realm(), "Cannot remove properties from result of getComputedStyle()");
 }
 
 String ResolvedCSSStyleDeclaration::serialized() const

+ 2 - 1
Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h

@@ -15,7 +15,6 @@ class ResolvedCSSStyleDeclaration final : public CSSStyleDeclaration {
 
 public:
     static ResolvedCSSStyleDeclaration* create(DOM::Element& element);
-    explicit ResolvedCSSStyleDeclaration(DOM::Element&);
 
     virtual ~ResolvedCSSStyleDeclaration() override = default;
 
@@ -28,6 +27,8 @@ public:
     virtual String serialized() const override;
 
 private:
+    explicit ResolvedCSSStyleDeclaration(DOM::Element&);
+
     virtual void visit_edges(Cell::Visitor&) override;
 
     RefPtr<StyleValue> style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const;

+ 3 - 1
Userland/Libraries/LibWeb/CSS/Screen.cpp

@@ -5,6 +5,8 @@
  */
 
 #include <LibGfx/Rect.h>
+#include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/Bindings/ScreenPrototype.h>
 #include <LibWeb/CSS/Screen.h>
 #include <LibWeb/DOM/Document.h>
 #include <LibWeb/Page/Page.h>
@@ -20,7 +22,7 @@ Screen::Screen(HTML::Window& window)
     : PlatformObject(window.realm())
     , m_window(window)
 {
-    set_prototype(&window.cached_web_prototype("Screen"));
+    set_prototype(&Bindings::ensure_web_prototype<Bindings::ScreenPrototype>(window.realm(), "Screen"));
 }
 
 void Screen::visit_edges(Cell::Visitor& visitor)

+ 0 - 2
Userland/Libraries/LibWeb/CSS/Screen.h

@@ -17,8 +17,6 @@ class Screen final : public Bindings::PlatformObject {
     WEB_PLATFORM_OBJECT(Screen, Bindings::PlatformObject);
 
 public:
-    using AllowOwnPtr = TrueType;
-
     static JS::NonnullGCPtr<Screen> create(HTML::Window&);
 
     i32 width() const { return screen_rect().width(); }

+ 2 - 3
Userland/Libraries/LibWeb/CSS/StyleSheet.cpp

@@ -8,12 +8,11 @@
 #include <LibWeb/CSS/CSSStyleSheet.h>
 #include <LibWeb/CSS/StyleSheet.h>
 #include <LibWeb/DOM/Element.h>
-#include <LibWeb/HTML/Window.h>
 
 namespace Web::CSS {
 
-StyleSheet::StyleSheet(HTML::Window& window_object)
-    : PlatformObject(window_object.cached_web_prototype("StyleSheet"))
+StyleSheet::StyleSheet(JS::Realm& realm)
+    : PlatformObject(realm)
 {
 }
 

+ 1 - 1
Userland/Libraries/LibWeb/CSS/StyleSheet.h

@@ -46,7 +46,7 @@ public:
     void set_parent_css_style_sheet(CSSStyleSheet*);
 
 protected:
-    explicit StyleSheet(HTML::Window&);
+    explicit StyleSheet(JS::Realm&);
     virtual void visit_edges(Cell::Visitor&) override;
 
 private:

+ 3 - 2
Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp

@@ -5,6 +5,7 @@
  */
 
 #include <AK/QuickSort.h>
+#include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/Bindings/StyleSheetListPrototype.h>
 #include <LibWeb/CSS/StyleSheetList.h>
 #include <LibWeb/DOM/Document.h>
@@ -36,12 +37,12 @@ void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
 
 StyleSheetList* StyleSheetList::create(DOM::Document& document)
 {
-    auto& realm = document.window().realm();
+    auto& realm = document.realm();
     return realm.heap().allocate<StyleSheetList>(realm, document);
 }
 
 StyleSheetList::StyleSheetList(DOM::Document& document)
-    : Bindings::LegacyPlatformObject(document.window().cached_web_prototype("StyleSheetList"))
+    : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype<Bindings::StyleSheetListPrototype>(document.realm(), "StyleSheetList"))
     , m_document(document)
 {
 }

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -1709,7 +1709,7 @@ void Document::evaluate_media_queries_and_report_changes()
             CSS::MediaQueryListEventInit init;
             init.media = media_query_list->media();
             init.matches = now_matches;
-            auto event = CSS::MediaQueryListEvent::create(window(), HTML::EventNames::change, init);
+            auto event = CSS::MediaQueryListEvent::create(realm(), HTML::EventNames::change, init);
             event->set_is_trusted(true);
             media_query_list->dispatch_event(*event);
         }