diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index 5a1d8a5717..a35daacd1d 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES Contrib/Test262/IsHTMLDDA.cpp CyclicModule.cpp Heap/BlockAllocator.cpp + Heap/Cell.cpp Heap/CellAllocator.cpp Heap/Handle.cpp Heap/Heap.cpp diff --git a/Userland/Libraries/LibJS/Heap/Cell.cpp b/Userland/Libraries/LibJS/Heap/Cell.cpp new file mode 100644 index 0000000000..aebe7d5bbc --- /dev/null +++ b/Userland/Libraries/LibJS/Heap/Cell.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020-2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace JS { + +ThrowCompletionOr JS::Cell::initialize(JS::Realm&) +{ + return {}; +} + +void JS::Cell::Visitor::visit(JS::Value value) +{ + if (value.is_cell()) + visit_impl(value.as_cell()); +} + +} diff --git a/Userland/Libraries/LibJS/Heap/Cell.h b/Userland/Libraries/LibJS/Heap/Cell.h index db1a7e4252..b7e808bbd6 100644 --- a/Userland/Libraries/LibJS/Heap/Cell.h +++ b/Userland/Libraries/LibJS/Heap/Cell.h @@ -14,8 +14,6 @@ #include #include #include -#include -#include namespace JS { @@ -33,7 +31,7 @@ class Cell { AK_MAKE_NONMOVABLE(Cell); public: - virtual ThrowCompletionOr initialize(Realm&) { return {}; } + virtual ThrowCompletionOr initialize(Realm&); virtual ~Cell() = default; bool is_marked() const { return m_mark; } @@ -75,11 +73,7 @@ public: visit_impl(const_cast&>(*cell.ptr())); } - void visit(Value value) - { - if (value.is_cell()) - visit_impl(value.as_cell()); - } + void visit(Value value); // Allow explicitly ignoring a GC-allocated member in a visit_edges implementation instead // of just not using it. diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h index 4e7d763361..946a2a5cc2 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.h +++ b/Userland/Libraries/LibJS/Heap/Heap.h @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace JS { diff --git a/Userland/Libraries/LibWeb/Bindings/PlatformObject.h b/Userland/Libraries/LibWeb/Bindings/PlatformObject.h index 8372d91f8f..fa135cb107 100644 --- a/Userland/Libraries/LibWeb/Bindings/PlatformObject.h +++ b/Userland/Libraries/LibWeb/Bindings/PlatformObject.h @@ -7,7 +7,6 @@ #pragma once #include -#include #include #include diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index df7b218b49..ae32b74555 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -54,6 +54,7 @@ set(SOURCES CSS/Parser/DeclarationOrAtRule.cpp CSS/Parser/Function.cpp CSS/Parser/Parser.cpp + CSS/Parser/ParsingContext.cpp CSS/Parser/Rule.cpp CSS/Parser/Token.cpp CSS/Parser/Tokenizer.cpp diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h index 92d4941cc6..e64917d5e9 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.cpp index d8b0ad8eeb..7c70628e9c 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.cpp @@ -11,6 +11,11 @@ namespace Web::CSS { +WebIDL::ExceptionOr> CSSKeyframeRule::create(JS::Realm& realm, CSS::Percentage key, Web::CSS::CSSStyleDeclaration& declarations) +{ + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, key, declarations)); +} + void CSSKeyframeRule::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.h b/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.h index 1ef0194fed..cfaf017482 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSKeyframeRule.h @@ -20,10 +20,7 @@ class CSSKeyframeRule final : public CSSRule { WEB_PLATFORM_OBJECT(CSSKeyframeRule, CSSRule); public: - static WebIDL::ExceptionOr> create(JS::Realm& realm, CSS::Percentage key, CSSStyleDeclaration& declarations) - { - return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, key, declarations)); - } + static WebIDL::ExceptionOr> create(JS::Realm& realm, CSS::Percentage key, CSSStyleDeclaration& declarations); virtual ~CSSKeyframeRule() = default; diff --git a/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.cpp index d4019d71d2..8494597499 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.cpp @@ -10,6 +10,11 @@ namespace Web::CSS { +WebIDL::ExceptionOr> CSSKeyframesRule::create(JS::Realm& realm, AK::FlyString name, Vector> keyframes) +{ + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, move(name), move(keyframes))); +} + void CSSKeyframesRule::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.h b/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.h index 2a14401952..2038e5fe4e 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSKeyframesRule.h @@ -21,10 +21,7 @@ class CSSKeyframesRule final : public CSSRule { WEB_PLATFORM_OBJECT(CSSKeyframesRule, CSSRule); public: - static WebIDL::ExceptionOr> create(JS::Realm& realm, FlyString name, Vector> keyframes) - { - return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, move(name), move(keyframes))); - } + static WebIDL::ExceptionOr> create(JS::Realm& realm, FlyString name, Vector> keyframes); virtual ~CSSKeyframesRule() = default; diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h index d9114ced0f..f153b84da9 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h @@ -11,7 +11,6 @@ #include #include #include -#include namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 44bf9e45c9..2d22d5ec62 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 509e216da0..80a6b6f54e 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -84,7 +83,6 @@ #include #include #include -#include #include #include @@ -95,43 +93,6 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur namespace Web::CSS::Parser { -ParsingContext::ParsingContext(JS::Realm& realm) - : m_realm(realm) -{ -} - -ParsingContext::ParsingContext(DOM::Document const& document, AK::URL url) - : m_realm(const_cast(document.realm())) - , m_document(&document) - , m_url(move(url)) -{ -} - -ParsingContext::ParsingContext(DOM::Document const& document) - : m_realm(const_cast(document.realm())) - , m_document(&document) - , m_url(document.url()) -{ -} - -ParsingContext::ParsingContext(DOM::ParentNode& parent_node) - : m_realm(parent_node.realm()) - , m_document(&parent_node.document()) - , m_url(parent_node.document().url()) -{ -} - -bool ParsingContext::in_quirks_mode() const -{ - return m_document ? m_document->in_quirks_mode() : false; -} - -// https://www.w3.org/TR/css-values-4/#relative-urls -AK::URL ParsingContext::complete_url(StringView relative_url) const -{ - return m_url.complete_url(relative_url); -} - ErrorOr Parser::create(ParsingContext const& context, StringView input, StringView encoding) { auto tokens = TRY(Tokenizer::tokenize(input, encoding)); @@ -9279,7 +9240,7 @@ CSS::Length CSS::Parser::Parser::parse_as_sizes_attribute() // If it does not parse correctly, or it does parse correctly but the evaluates to false, continue. TokenStream token_stream { unparsed_size }; auto media_condition = parse_media_condition(token_stream, MediaCondition::AllowOr::Yes); - if (media_condition && media_condition->evaluate(m_context.document()->window()) == CSS::MatchResult::True) { + if (media_condition && media_condition->evaluate(*m_context.window()) == CSS::MatchResult::True) { return size.value(); } else { continue; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 3e99382f0b..2dbcdc7980 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -44,6 +44,7 @@ public: bool in_quirks_mode() const; DOM::Document const* document() const { return m_document; } + HTML::Window const* window() const; AK::URL complete_url(StringView) const; PropertyID current_property_id() const { return m_current_property_id; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp b/Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp new file mode 100644 index 0000000000..671a2b35c1 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018-2022, Andreas Kling + * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2021, Tobias Christiansen + * Copyright (c) 2022, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::CSS::Parser { + +ParsingContext::ParsingContext(JS::Realm& realm) + : m_realm(realm) +{ +} + +ParsingContext::ParsingContext(DOM::Document const& document, AK::URL url) + : m_realm(const_cast(document.realm())) + , m_document(&document) + , m_url(move(url)) +{ +} + +ParsingContext::ParsingContext(DOM::Document const& document) + : m_realm(const_cast(document.realm())) + , m_document(&document) + , m_url(document.url()) +{ +} + +ParsingContext::ParsingContext(DOM::ParentNode& parent_node) + : m_realm(parent_node.realm()) + , m_document(&parent_node.document()) + , m_url(parent_node.document().url()) +{ +} + +bool ParsingContext::in_quirks_mode() const +{ + return m_document ? m_document->in_quirks_mode() : false; +} + +// https://www.w3.org/TR/css-values-4/#relative-urls +AK::URL ParsingContext::complete_url(StringView relative_url) const +{ + return m_url.complete_url(relative_url); +} + +HTML::Window const* ParsingContext::window() const +{ + return m_document ? &m_document->window() : nullptr; +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 95e783ab6f..340f97889e 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -7,6 +7,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index df94f2c553..fcad90c013 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h index 0f5a7c864b..a580d7cfc9 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h @@ -9,6 +9,7 @@ #pragma once +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/DOM/IDLEventListener.cpp b/Userland/Libraries/LibWeb/DOM/IDLEventListener.cpp index 18b5481fd7..22e8a40d63 100644 --- a/Userland/Libraries/LibWeb/DOM/IDLEventListener.cpp +++ b/Userland/Libraries/LibWeb/DOM/IDLEventListener.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include namespace Web::DOM { diff --git a/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp b/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp index ffc19db559..cf12fe9c1f 100644 --- a/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp +++ b/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp @@ -5,6 +5,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include diff --git a/Userland/Libraries/LibWeb/DOM/StaticNodeList.cpp b/Userland/Libraries/LibWeb/DOM/StaticNodeList.cpp index bf5804d902..03821977f4 100644 --- a/Userland/Libraries/LibWeb/DOM/StaticNodeList.cpp +++ b/Userland/Libraries/LibWeb/DOM/StaticNodeList.cpp @@ -5,6 +5,7 @@ */ #include +#include #include namespace Web::DOM { diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h index 8652345dfb..e97b5178af 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -8,10 +8,7 @@ #pragma once #include -#include -#include -#include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp index 82d0d6cb79..3fbb980600 100644 --- a/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp +++ b/Userland/Libraries/LibWeb/HTML/StructuredSerialize.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index 2a118284d0..19b76e2329 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp index 6072ccc74f..8409f25656 100644 --- a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp index ff97bd5bc4..2dc01f0dab 100644 --- a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/Userland/Libraries/LibWeb/WebIDL/DOMException.h b/Userland/Libraries/LibWeb/WebIDL/DOMException.h index 0c9c48a573..1ba5993bd8 100644 --- a/Userland/Libraries/LibWeb/WebIDL/DOMException.h +++ b/Userland/Libraries/LibWeb/WebIDL/DOMException.h @@ -8,7 +8,6 @@ #include #include -#include #include #include