diff --git a/Userland/Libraries/LibWeb/CSS/CSSConditionRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSConditionRule.cpp index d4057e4412..b6d142d06c 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSConditionRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSConditionRule.cpp @@ -5,15 +5,16 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include -#include 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(realm, "CSSConditionRule")); } void CSSConditionRule::for_each_effective_style_rule(Function const& callback) const diff --git a/Userland/Libraries/LibWeb/CSS/CSSConditionRule.h b/Userland/Libraries/LibWeb/CSS/CSSConditionRule.h index 1267c2d57b..c78ab2c735 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSConditionRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSConditionRule.h @@ -25,7 +25,7 @@ public: virtual void for_each_effective_style_rule(Function const& callback) const override; protected: - explicit CSSConditionRule(HTML::Window&, CSSRuleList&); + CSSConditionRule(JS::Realm&, CSSRuleList&); }; } diff --git a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp index 9b3251e0fc..bd85d48440 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp @@ -5,22 +5,23 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include -#include 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(window_object.realm(), window_object, move(font_face)); + return realm.heap().allocate(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(realm, "CSSFontFaceRule")); } CSSStyleDeclaration* CSSFontFaceRule::style() diff --git a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h index 235540ce43..a50cb9aa13 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h +++ b/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; diff --git a/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.cpp index 8b835b2da6..6977aa9ab4 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.cpp @@ -5,6 +5,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include #include @@ -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(realm, "CSSGroupingRule")); for (auto& rule : m_rules) rule.set_parent_rule(this); } diff --git a/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.h b/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.h index 9e220e3a8c..406a031037 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.h +++ b/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: diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp index 46d38d6acf..af7baf3a7c 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include #include @@ -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(window_object.realm(), move(url), document); + auto& realm = document.realm(); + return realm.heap().allocate(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(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()); diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h index 9fb4fdce34..18cbbad11a 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h @@ -9,7 +9,6 @@ #pragma once #include -#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp index af48b8d6dd..57903dd408 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp @@ -5,21 +5,23 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include +#include #include -#include 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(window_object.realm(), window_object, media_queries, rules); + return realm.heap().allocate(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(realm, "CSSMediaRule")); } void CSSMediaRule::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibWeb/CSS/CSSMediaRule.h b/Userland/Libraries/LibWeb/CSS/CSSMediaRule.h index add24d660a..c15b9b1cff 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSMediaRule.h +++ b/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; diff --git a/Userland/Libraries/LibWeb/CSS/CSSRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSRule.cpp index f04ad9033c..10b4971fb7 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRule.cpp @@ -8,12 +8,11 @@ #include #include -#include namespace Web::CSS { -CSSRule::CSSRule(HTML::Window& window_object) - : PlatformObject(window_object.cached_web_prototype("CSSRule")) +CSSRule::CSSRule(JS::Realm& realm) + : PlatformObject(realm) { } diff --git a/Userland/Libraries/LibWeb/CSS/CSSRule.h b/Userland/Libraries/LibWeb/CSS/CSSRule.h index 8a3d6649b1..d095831e25 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRule.h +++ b/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; diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp index b963480450..55f8631a87 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include #include @@ -15,22 +17,22 @@ namespace Web::CSS { -CSSRuleList* CSSRuleList::create(HTML::Window& window_object, JS::MarkedVector const& rules) +CSSRuleList* CSSRuleList::create(JS::Realm& realm, JS::MarkedVector const& rules) { - auto* rule_list = window_object.heap().allocate(window_object.realm(), window_object); + auto* rule_list = realm.heap().allocate(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(realm, "CSSRuleList")) { } -CSSRuleList* CSSRuleList::create_empty(HTML::Window& window_object) +CSSRuleList* CSSRuleList::create_empty(JS::Realm& realm) { - return window_object.heap().allocate(window_object.realm(), window_object); + return realm.heap().allocate(realm, realm); } void CSSRuleList::visit_edges(Cell::Visitor& visitor) @@ -55,7 +57,7 @@ WebIDL::ExceptionOr CSSRuleList::insert_a_css_rule(Variant 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 CSSRuleList::insert_a_css_rule(Variant()) { new_rule = parse_css_rule( - CSS::Parser::ParsingContext { static_cast(global_object()) }, + CSS::Parser::ParsingContext { realm() }, rule.get()); } else { new_rule = rule.get(); @@ -72,7 +74,7 @@ WebIDL::ExceptionOr CSSRuleList::insert_a_css_rule(Variant 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]; diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h b/Userland/Libraries/LibWeb/CSS/CSSRuleList.h index 17c9297505..dc5537891f 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h +++ b/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 const&); - static CSSRuleList* create_empty(HTML::Window&); + static CSSRuleList* create(JS::Realm&, JS::MarkedVector 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 m_rules; diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 799218c30d..04bb10de92 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -4,26 +4,27 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include #include #include -#include 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(realm, "CSSStyleDeclaration")) { } -PropertyOwningCSSStyleDeclaration* PropertyOwningCSSStyleDeclaration::create(HTML::Window& window_object, Vector properties, HashMap custom_properties) +PropertyOwningCSSStyleDeclaration* PropertyOwningCSSStyleDeclaration::create(JS::Realm& realm, Vector properties, HashMap custom_properties) { - return window_object.heap().allocate(window_object.realm(), window_object, move(properties), move(custom_properties)); + return realm.heap().allocate(realm, realm, move(properties), move(custom_properties)); } -PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(HTML::Window& window_object, Vector properties, HashMap custom_properties) - : CSSStyleDeclaration(window_object) +PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(JS::Realm& realm, Vector properties, HashMap 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 properties, HashMap custom_properties) { - auto& window_object = element.document().window(); - return window_object.heap().allocate(window_object.realm(), element, move(properties), move(custom_properties)); + auto& realm = element.realm(); + return realm.heap().allocate(realm, element, move(properties), move(custom_properties)); } ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector properties, HashMap 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()) { } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index 13dd3f7780..923d31b97b 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -55,7 +55,7 @@ public: virtual JS::ThrowCompletionOr 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, HashMap custom_properties); + static PropertyOwningCSSStyleDeclaration* create(JS::Realm&, Vector, HashMap custom_properties); virtual ~PropertyOwningCSSStyleDeclaration() override = default; @@ -83,7 +83,7 @@ public: virtual String serialized() const final override; protected: - PropertyOwningCSSStyleDeclaration(HTML::Window&, Vector, HashMap); + PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector, HashMap); virtual void update_style_attribute() { } @@ -108,7 +108,7 @@ public: bool is_updating() const { return m_updating; } private: - explicit ElementInlineCSSStyleDeclaration(DOM::Element&, Vector properties, HashMap custom_properties); + ElementInlineCSSStyleDeclaration(DOM::Element&, Vector properties, HashMap custom_properties); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp index 1ae7cb3060..c0dd7396ce 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.cpp @@ -4,23 +4,24 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include -#include namespace Web::CSS { -CSSStyleRule* CSSStyleRule::create(HTML::Window& window_object, NonnullRefPtrVector&& selectors, CSSStyleDeclaration& declaration) +CSSStyleRule* CSSStyleRule::create(JS::Realm& realm, NonnullRefPtrVector&& selectors, CSSStyleDeclaration& declaration) { - return window_object.heap().allocate(window_object.realm(), window_object, move(selectors), declaration); + return realm.heap().allocate(realm, realm, move(selectors), declaration); } -CSSStyleRule::CSSStyleRule(HTML::Window& window_object, NonnullRefPtrVector&& selectors, CSSStyleDeclaration& declaration) - : CSSRule(window_object) +CSSStyleRule::CSSStyleRule(JS::Realm& realm, NonnullRefPtrVector&& 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(realm, "CSSStyleRule")); } void CSSStyleRule::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.h b/Userland/Libraries/LibWeb/CSS/CSSStyleRule.h index 30c39e6794..d1bbe2d3e8 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleRule.h +++ b/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&&, CSSStyleDeclaration&); + static CSSStyleRule* create(JS::Realm&, NonnullRefPtrVector&&, CSSStyleDeclaration&); virtual ~CSSStyleRule() override = default; @@ -34,7 +34,7 @@ public: CSSStyleDeclaration* style(); private: - CSSStyleRule(HTML::Window&, NonnullRefPtrVector&&, CSSStyleDeclaration&); + CSSStyleRule(JS::Realm&, NonnullRefPtrVector&&, CSSStyleDeclaration&); virtual void visit_edges(Cell::Visitor&) override; virtual String serialized() const override; diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 4a781c8377..1650897264 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include #include @@ -12,16 +14,16 @@ namespace Web::CSS { -CSSStyleSheet* CSSStyleSheet::create(HTML::Window& window_object, CSSRuleList& rules, Optional location) +CSSStyleSheet* CSSStyleSheet::create(JS::Realm& realm, CSSRuleList& rules, Optional location) { - return window_object.heap().allocate(window_object.realm(), window_object, rules, move(location)); + return realm.heap().allocate(realm, realm, rules, move(location)); } -CSSStyleSheet::CSSStyleSheet(HTML::Window& window_object, CSSRuleList& rules, Optional location) - : StyleSheet(window_object) +CSSStyleSheet::CSSStyleSheet(JS::Realm& realm, CSSRuleList& rules, Optional location) + : StyleSheet(realm) , m_rules(&rules) { - set_prototype(&window_object.cached_web_prototype("CSSStyleSheet")); + set_prototype(&Bindings::ensure_web_prototype(realm, "CSSStyleSheet")); if (location.has_value()) set_location(location->to_string()); @@ -50,7 +52,7 @@ WebIDL::ExceptionOr 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. diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h index e462789496..9d2e89b5f4 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h +++ b/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 location); + static CSSStyleSheet* create(JS::Realm&, CSSRuleList& rules, Optional location); - explicit CSSStyleSheet(HTML::Window&, CSSRuleList&, Optional 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*); private: + CSSStyleSheet(JS::Realm&, CSSRuleList&, Optional location); + virtual void visit_edges(Cell::Visitor&) override; CSSRuleList* m_rules { nullptr }; diff --git a/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp index 15140c9c10..b02a29ecce 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp @@ -4,22 +4,23 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include -#include namespace Web::CSS { -CSSSupportsRule* CSSSupportsRule::create(HTML::Window& window_object, NonnullRefPtr&& supports, CSSRuleList& rules) +CSSSupportsRule* CSSSupportsRule::create(JS::Realm& realm, NonnullRefPtr&& supports, CSSRuleList& rules) { - return window_object.heap().allocate(window_object.realm(), window_object, move(supports), rules); + return realm.heap().allocate(realm, realm, move(supports), rules); } -CSSSupportsRule::CSSSupportsRule(HTML::Window& window_object, NonnullRefPtr&& supports, CSSRuleList& rules) - : CSSConditionRule(window_object, rules) +CSSSupportsRule::CSSSupportsRule(JS::Realm& realm, NonnullRefPtr&& supports, CSSRuleList& rules) + : CSSConditionRule(realm, rules) , m_supports(move(supports)) { - set_prototype(&window_object.cached_web_prototype("CSSSupportsRule")); + set_prototype(&Bindings::ensure_web_prototype(realm, "CSSSupportsRule")); } String CSSSupportsRule::condition_text() const diff --git a/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.h b/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.h index 0015ca86ed..f9619a4d2f 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.h +++ b/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&&, CSSRuleList&); + static CSSSupportsRule* create(JS::Realm&, NonnullRefPtr&&, 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&&, CSSRuleList&); + CSSSupportsRule(JS::Realm&, NonnullRefPtr&&, CSSRuleList&); virtual String serialized() const override; diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index 224d2711e6..2e898f2143 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -5,19 +5,20 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include -#include namespace Web::CSS { -MediaList* MediaList::create(HTML::Window& window_object, NonnullRefPtrVector&& media) +MediaList* MediaList::create(JS::Realm& realm, NonnullRefPtrVector&& media) { - return window_object.heap().allocate(window_object.realm(), window_object, move(media)); + return realm.heap().allocate(realm, realm, move(media)); } -MediaList::MediaList(HTML::Window& window_object, NonnullRefPtrVector&& media) - : Bindings::LegacyPlatformObject(window_object.cached_web_prototype("MediaList")) +MediaList::MediaList(JS::Realm& realm, NonnullRefPtrVector&& media) + : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype(realm, "MediaList")) , m_media(move(media)) { } diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.h b/Userland/Libraries/LibWeb/CSS/MediaList.h index 6b0f85b237..cbd2015a86 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.h +++ b/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&& media); + static MediaList* create(JS::Realm&, NonnullRefPtrVector&& media); ~MediaList() = default; String media_text() const; @@ -37,7 +37,7 @@ public: bool matches() const; private: - explicit MediaList(HTML::Window&, NonnullRefPtrVector&&); + MediaList(JS::Realm&, NonnullRefPtrVector&&); NonnullRefPtrVector m_media; }; diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp index a9765486f2..af58582d02 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp @@ -5,6 +5,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include #include @@ -23,7 +25,7 @@ MediaQueryList::MediaQueryList(DOM::Document& document, NonnullRefPtrVector(document.realm(), "MediaQueryList")); evaluate(); } diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp b/Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp index 4fedb43139..66977a579c 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp @@ -4,28 +4,23 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include -#include 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(window_object.realm(), window_object, event_name, event_init); + return realm.heap().allocate(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(realm, "MediaQueryListEvent")); } MediaQueryListEvent::~MediaQueryListEvent() = default; diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.h b/Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.h index 197f8acf95..217a4b8fcf 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQueryListEvent.h +++ b/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; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index c68e5603a3..40b2d7180d 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/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(document.window())) + : m_realm(const_cast(document.realm())) , m_document(&document) , m_url(move(url)) { } ParsingContext::ParsingContext(DOM::Document const& document) - : m_window_object(const_cast(document.window())) + : m_realm(const_cast(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 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 rules(m_context.window_object().heap()); + JS::MarkedVector 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 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 Parser::parse_as_selector(SelectorParsingMode parsing_mode) @@ -2561,13 +2561,13 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr rule) auto child_tokens = TokenStream { rule->block()->values() }; auto parser_rules = parse_a_list_of_rules(child_tokens); - JS::MarkedVector child_rules(m_context.window_object().heap()); + JS::MarkedVector 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) return {}; auto child_tokens = TokenStream { rule->block()->values() }; auto parser_rules = parse_a_list_of_rules(child_tokens); - JS::MarkedVector child_rules(m_context.window_object().heap()); + JS::MarkedVector 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) 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 const& declarations_and_at_rules) -> PropertiesAndCustomProperties @@ -2658,7 +2658,7 @@ auto Parser::extract_properties(Vector const& declarations_ PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector 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 Parser::convert_to_style_property(Declaration const& declaration) @@ -4890,7 +4890,7 @@ CSSRule* Parser::parse_font_face_rule(TokenStream& 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 Parser::parse_font_face_src(TokenStream& component_values) @@ -6505,7 +6505,7 @@ namespace Web { CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& context, StringView css, Optional 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); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 7b5b97343f..896127cb2f 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/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; diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 1b80fd7811..2fd5c1ea80 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/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(window_object.realm(), element); + return element.realm().heap().allocate(element.realm(), element); } ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element) - : CSSStyleDeclaration(element.document().window()) + : CSSStyleDeclaration(element.realm()) , m_element(element) { } @@ -541,14 +540,14 @@ Optional ResolvedCSSStyleDeclaration::property(PropertyID propert WebIDL::ExceptionOr 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 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 diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h index 2700f7dd8d..c399207ed4 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h +++ b/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 style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const; diff --git a/Userland/Libraries/LibWeb/CSS/Screen.cpp b/Userland/Libraries/LibWeb/CSS/Screen.cpp index 2a286f0451..35fee91694 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.cpp +++ b/Userland/Libraries/LibWeb/CSS/Screen.cpp @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include #include @@ -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(window.realm(), "Screen")); } void Screen::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibWeb/CSS/Screen.h b/Userland/Libraries/LibWeb/CSS/Screen.h index fb0b82df5f..d13600933e 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.h +++ b/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 create(HTML::Window&); i32 width() const { return screen_rect().width(); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp index 82b5a6cc0a..e737df9429 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleSheet.cpp @@ -8,12 +8,11 @@ #include #include #include -#include namespace Web::CSS { -StyleSheet::StyleSheet(HTML::Window& window_object) - : PlatformObject(window_object.cached_web_prototype("StyleSheet")) +StyleSheet::StyleSheet(JS::Realm& realm) + : PlatformObject(realm) { } diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheet.h b/Userland/Libraries/LibWeb/CSS/StyleSheet.h index 8766e40a5c..4aaf056b9e 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheet.h +++ b/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: diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp index d2c0b8d759..b7c3fc791a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -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(realm, document); } StyleSheetList::StyleSheetList(DOM::Document& document) - : Bindings::LegacyPlatformObject(document.window().cached_web_prototype("StyleSheetList")) + : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype(document.realm(), "StyleSheetList")) , m_document(document) { } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 3afe844ddc..7cedd45bf8 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/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); }