diff --git a/Libraries/LibIDL/Types.h b/Libraries/LibIDL/Types.h index 2f4a538f81..c397e8fae7 100644 --- a/Libraries/LibIDL/Types.h +++ b/Libraries/LibIDL/Types.h @@ -30,16 +30,6 @@ static size_t get_function_shortest_length(FunctionType& function) return length; } -enum class SequenceStorageType { - Vector, // Used to safely store non-JS values - RootVector, // Used to safely store JS::Value and anything that inherits JS::Cell, e.g. JS::Object -}; - -struct CppType { - ByteString name; - SequenceStorageType sequence_storage_type; -}; - class Context; class ParameterizedType; class UnionType; diff --git a/Libraries/LibWeb/Animations/Animatable.cpp b/Libraries/LibWeb/Animations/Animatable.cpp index dcac6b2e29..879d3eddf0 100644 --- a/Libraries/LibWeb/Animations/Animatable.cpp +++ b/Libraries/LibWeb/Animations/Animatable.cpp @@ -26,7 +26,7 @@ struct Animatable::Transition { Animatable::Impl::~Impl() = default; // https://www.w3.org/TR/web-animations-1/#dom-animatable-animate -WebIDL::ExceptionOr> Animatable::animate(Optional> keyframes, Variant const& options) +WebIDL::ExceptionOr> Animatable::animate(GC::Ptr keyframes, Variant const& options) { // 1. Let target be the object on which this method was called. GC::Ref target { *static_cast(this) }; @@ -46,7 +46,7 @@ WebIDL::ExceptionOr> Animatable::animate(Optional> timeline; if (options.has() && options.get().timeline.has_value()) - timeline = options.get().timeline->ptr(); + timeline = options.get().timeline.value(); if (!timeline.has_value()) timeline = target->document().timeline(); diff --git a/Libraries/LibWeb/Animations/Animatable.h b/Libraries/LibWeb/Animations/Animatable.h index 29be181cb7..a29f13593d 100644 --- a/Libraries/LibWeb/Animations/Animatable.h +++ b/Libraries/LibWeb/Animations/Animatable.h @@ -39,7 +39,7 @@ public: Yes }; - WebIDL::ExceptionOr> animate(Optional> keyframes, Variant const& options = {}); + WebIDL::ExceptionOr> animate(GC::Ptr keyframes, Variant const& options = {}); WebIDL::ExceptionOr>> get_animations(Optional const& options = {}); WebIDL::ExceptionOr>> get_animations_internal(GetAnimationsSorted sorted, Optional const& options = {}); diff --git a/Libraries/LibWeb/Animations/Animation.cpp b/Libraries/LibWeb/Animations/Animation.cpp index 3eed31c84c..34350908d1 100644 --- a/Libraries/LibWeb/Animations/Animation.cpp +++ b/Libraries/LibWeb/Animations/Animation.cpp @@ -225,7 +225,7 @@ WebIDL::ExceptionOr> Animation::validate_a_css_numberish_tim m_timeline && m_timeline->is_progress_based() && // time is not a CSSNumeric value with percent units: - (!time.has>() || !time.get>()->type().matches_percentage())) { + (!time.has>() || !time.get>()->type().matches_percentage())) { // throw a TypeError. // return false; return WebIDL::SimpleException { @@ -240,14 +240,14 @@ WebIDL::ExceptionOr> Animation::validate_a_css_numberish_tim (!m_timeline || !m_timeline->is_progress_based()) && // time is a CSSNumericValue, and - time.has>() && + time.has>() && // the units of time are not duration units: - !time.get>()->type().matches_time({}) && + !time.get>()->type().matches_time({}) && // AD-HOC: While it's not mentioned in the spec WPT also expects us to support CSSNumericValue number value, see // https://github.com/w3c/csswg-drafts/issues/13196 - !time.get>()->type().matches_number({})) { + !time.get>()->type().matches_number({})) { // throw a TypeError. // return false. return WebIDL::SimpleException { @@ -266,7 +266,7 @@ WebIDL::ExceptionOr> Animation::validate_a_css_numberish_tim // FIXME: Figure out which element we should use for this, for now we just use the document element of the current // window - return TimeValue::from_css_numberish(time.downcast>(), DOM::AbstractElement { *as(realm().global_object()).associated_document().document_element() }); + return TimeValue::from_css_numberish(time.downcast>(), DOM::AbstractElement { *as(realm().global_object()).associated_document().document_element() }); VERIFY_NOT_REACHED(); } diff --git a/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Libraries/LibWeb/Animations/AnimationEffect.cpp index d5fabab4bb..ac61d42368 100644 --- a/Libraries/LibWeb/Animations/AnimationEffect.cpp +++ b/Libraries/LibWeb/Animations/AnimationEffect.cpp @@ -72,7 +72,7 @@ Bindings::OptionalEffectTiming to_optional_effect_timing(Bindings::EffectTiming [](double const& value) -> Variant { return value; }, [](String const& value) -> Variant { return value; }, // NB: We check that this isn't the case in the caller - [](GC::Root const&) -> Variant { VERIFY_NOT_REACHED(); }), + [](GC::Ref) -> Variant { VERIFY_NOT_REACHED(); }), .easing = effect_timing.easing, .end_delay = effect_timing.end_delay, .fill = effect_timing.fill, diff --git a/Libraries/LibWeb/Animations/AnimationPlaybackEvent.cpp b/Libraries/LibWeb/Animations/AnimationPlaybackEvent.cpp index a8e63067ae..916e73b242 100644 --- a/Libraries/LibWeb/Animations/AnimationPlaybackEvent.cpp +++ b/Libraries/LibWeb/Animations/AnimationPlaybackEvent.cpp @@ -25,18 +25,10 @@ WebIDL::ExceptionOr> AnimationPlaybackEvent::con return create(realm, type, event_init); } -AnimationPlaybackEvent::CSSNumberishInternal AnimationPlaybackEvent::to_numberish_internal(NullableCSSNumberish const& numberish_root) -{ - return numberish_root.visit( - [](Empty) -> CSSNumberishInternal { return Empty {}; }, - [](GC::Root const& root) -> CSSNumberishInternal { return GC::Ref { *root }; }, - [](auto const& other) -> CSSNumberishInternal { return other; }); -} - AnimationPlaybackEvent::AnimationPlaybackEvent(JS::Realm& realm, FlyString const& type, Bindings::AnimationPlaybackEventInit const& event_init) : DOM::Event(realm, type, event_init) - , m_current_time(to_numberish_internal(event_init.current_time)) - , m_timeline_time(to_numberish_internal(event_init.timeline_time)) + , m_current_time(event_init.current_time) + , m_timeline_time(event_init.timeline_time) { } @@ -53,21 +45,14 @@ void AnimationPlaybackEvent::visit_edges(Visitor& visitor) visitor.visit(m_timeline_time); } -NullableCSSNumberish AnimationPlaybackEvent::to_nullable_numberish(CSSNumberishInternal const& numberish) -{ - return numberish.visit( - [](GC::Ref const& ref) -> NullableCSSNumberish { return GC::Root { *ref }; }, - [](auto const& other) -> NullableCSSNumberish { return other; }); -} - NullableCSSNumberish AnimationPlaybackEvent::current_time() const { - return to_nullable_numberish(m_current_time); + return m_current_time; } NullableCSSNumberish AnimationPlaybackEvent::timeline_time() const { - return to_nullable_numberish(m_timeline_time); + return m_timeline_time; } } diff --git a/Libraries/LibWeb/Animations/AnimationPlaybackEvent.h b/Libraries/LibWeb/Animations/AnimationPlaybackEvent.h index 32827c9fce..146fe9332f 100644 --- a/Libraries/LibWeb/Animations/AnimationPlaybackEvent.h +++ b/Libraries/LibWeb/Animations/AnimationPlaybackEvent.h @@ -34,15 +34,11 @@ private: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor&) override; - using CSSNumberishInternal = Variant>; - static CSSNumberishInternal to_numberish_internal(NullableCSSNumberish const&); - static NullableCSSNumberish to_nullable_numberish(CSSNumberishInternal const&); - // https://drafts.csswg.org/web-animations-2/#dom-animationplaybackevent-currenttime - CSSNumberishInternal m_current_time; + NullableCSSNumberish m_current_time; // https://drafts.csswg.org/web-animations-2/#dom-animationplaybackevent-timelinetime - CSSNumberishInternal m_timeline_time; + NullableCSSNumberish m_timeline_time; }; } diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Libraries/LibWeb/Animations/KeyframeEffect.cpp index d011fd4c23..ce93caafe8 100644 --- a/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -664,8 +664,8 @@ GC::Ref KeyframeEffect::create(JS::Realm& realm) // https://www.w3.org/TR/web-animations-1/#dom-keyframeeffect-keyframeeffect WebIDL::ExceptionOr> KeyframeEffect::construct_impl( JS::Realm& realm, - GC::Root const& target, - Optional> const& keyframes, + GC::Ptr target, + GC::Ptr keyframes, Variant options) { // 1. Create a new KeyframeEffect object, effect. @@ -711,7 +711,7 @@ WebIDL::ExceptionOr> KeyframeEffect::construct_impl( // returned as a CSSNumericValue when resolving the duration in getComputedTiming(). Future versions of // the spec may enable setting the duration as a CSSNumeric value, where the unit is a valid time unit or // percent. - if (timing_input.duration.has>()) + if (timing_input.duration.has>()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Setting duration as a CSSNumericValue is not supported"sv }; // 5. Call the procedure to update the timing properties of an animation effect of effect from timing input. @@ -894,10 +894,10 @@ WebIDL::ExceptionOr> KeyframeEffect::get_keyframes() } // https://www.w3.org/TR/web-animations-1/#dom-keyframeeffect-setkeyframes -WebIDL::ExceptionOr KeyframeEffect::set_keyframes(Optional> const& keyframe_object) +WebIDL::ExceptionOr KeyframeEffect::set_keyframes(GC::Ptr keyframe_object) { m_keyframe_objects.clear(); - m_keyframes = TRY(process_a_keyframes_argument(realm(), keyframe_object.has_value() ? GC::Ptr { keyframe_object->ptr() } : GC::Ptr {})); + m_keyframes = TRY(process_a_keyframes_argument(realm(), keyframe_object)); // FIXME: After processing the keyframe argument, we need to turn the set of keyframes into a set of computed // keyframes using the procedure outlined in the second half of // https://www.w3.org/TR/web-animations-1/#calculating-computed-keyframes. For now, just compute the diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.h b/Libraries/LibWeb/Animations/KeyframeEffect.h index d46a46b2fd..aa0fc5c556 100644 --- a/Libraries/LibWeb/Animations/KeyframeEffect.h +++ b/Libraries/LibWeb/Animations/KeyframeEffect.h @@ -76,8 +76,8 @@ public: static WebIDL::ExceptionOr> construct_impl( JS::Realm&, - GC::Root const& target, - Optional> const& keyframes, + GC::Ptr target, + GC::Ptr keyframes, Variant options = Bindings::KeyframeEffectOptions {}); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, GC::Ref source); @@ -99,7 +99,7 @@ public: void set_composite(Bindings::CompositeOperation value); WebIDL::ExceptionOr> get_keyframes(); - WebIDL::ExceptionOr set_keyframes(Optional> const&); + WebIDL::ExceptionOr set_keyframes(GC::Ptr); KeyFrameSet const* key_frame_set() { return m_key_frame_set; } void set_key_frame_set(RefPtr key_frame_set) { m_key_frame_set = key_frame_set; } diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.cpp b/Libraries/LibWeb/Animations/ScrollTimeline.cpp index fc6c3d5b91..74b8436655 100644 --- a/Libraries/LibWeb/Animations/ScrollTimeline.cpp +++ b/Libraries/LibWeb/Animations/ScrollTimeline.cpp @@ -36,7 +36,7 @@ GC::Ref ScrollTimeline::construct_impl(JS::Realm& realm, Binding // If the source member of options is present, // The source member of options. if (options.source.has_value()) - return options.source.value().ptr(); + return options.source.value(); // Otherwise, // The scrollingElement of the Document associated with the Window that is the current global object. diff --git a/Libraries/LibWeb/Animations/TimeValue.cpp b/Libraries/LibWeb/Animations/TimeValue.cpp index 5e68e93f89..4bacddeb95 100644 --- a/Libraries/LibWeb/Animations/TimeValue.cpp +++ b/Libraries/LibWeb/Animations/TimeValue.cpp @@ -16,7 +16,7 @@ TimeValue TimeValue::from_css_numberish(CSS::CSSNumberish const& time, DOM::Abst if (time.has()) return { Type::Milliseconds, time.get() }; - auto const& numeric_value = time.get>(); + auto const& numeric_value = time.get>(); // NB: Skip creating a calculation node for simple unit values if (auto const* unit_value = as_if(*numeric_value)) { @@ -70,7 +70,7 @@ CSS::CSSNumberish TimeValue::as_css_numberish(JS::Realm& realm) const return value; case Type::Percentage: GC::Ref numeric_value = CSS::CSSUnitValue::create(realm, value, "percent"_fly_string); - return GC::Root { numeric_value }; + return numeric_value; } VERIFY_NOT_REACHED(); diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp index 3c2feeadc0..f4c6eb1393 100644 --- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/Libraries/LibWeb/CSS/CSSKeywordValue.cpp b/Libraries/LibWeb/CSS/CSSKeywordValue.cpp index b9055c3597..0881f198fe 100644 --- a/Libraries/LibWeb/CSS/CSSKeywordValue.cpp +++ b/Libraries/LibWeb/CSS/CSSKeywordValue.cpp @@ -124,8 +124,8 @@ GC::Ref rectify_a_keywordish_value(JS::Realm& realm, CSSKeyword // To rectify a keywordish value val, perform the following steps: return keywordish.visit( // 1. If val is a CSSKeywordValue, return val. - [](GC::Root const& value) -> GC::Ref { - return *value; + [](GC::Ref const& value) -> GC::Ref { + return value; }, // 2. If val is a DOMString, return a new CSSKeywordValue with its value internal slot set to val. diff --git a/Libraries/LibWeb/CSS/CSSKeywordValue.h b/Libraries/LibWeb/CSS/CSSKeywordValue.h index dc39891754..80c87ce8f1 100644 --- a/Libraries/LibWeb/CSS/CSSKeywordValue.h +++ b/Libraries/LibWeb/CSS/CSSKeywordValue.h @@ -12,7 +12,7 @@ namespace Web::CSS { // https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-csskeywordish -using CSSKeywordish = Variant>; +using CSSKeywordish = Variant>; // https://drafts.css-houdini.org/css-typed-om-1/#csskeywordvalue class CSSKeywordValue final : public CSSStyleValue { diff --git a/Libraries/LibWeb/CSS/CSSMathMin.cpp b/Libraries/LibWeb/CSS/CSSMathMin.cpp index 113263b7d5..886f62f664 100644 --- a/Libraries/LibWeb/CSS/CSSMathMin.cpp +++ b/Libraries/LibWeb/CSS/CSSMathMin.cpp @@ -44,7 +44,7 @@ WebIDL::ExceptionOr> CSSMathMin::add_all_types_into_math_min } // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssmathmin-cssmathmin -WebIDL::ExceptionOr> CSSMathMin::construct_impl(JS::Realm& realm, Vector values) +WebIDL::ExceptionOr> CSSMathMin::construct_impl(JS::Realm& realm, ReadonlySpan values) { // The CSSMathMin(...args) and CSSMathMax(...args) constructors are defined identically to the above, except that // in the last step they return a new CSSMathMin or CSSMathMax object, respectively. diff --git a/Libraries/LibWeb/CSS/CSSMathMin.h b/Libraries/LibWeb/CSS/CSSMathMin.h index 0083f5b203..8698aeb46d 100644 --- a/Libraries/LibWeb/CSS/CSSMathMin.h +++ b/Libraries/LibWeb/CSS/CSSMathMin.h @@ -17,7 +17,7 @@ class CSSMathMin final : public CSSMathValue { public: [[nodiscard]] static GC::Ref create(JS::Realm&, NumericType, GC::Ref); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Vector); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, ReadonlySpan); static WebIDL::ExceptionOr> add_all_types_into_math_min(JS::Realm&, GC::RootVector> const&); virtual ~CSSMathMin() override; diff --git a/Libraries/LibWeb/CSS/CSSMathProduct.cpp b/Libraries/LibWeb/CSS/CSSMathProduct.cpp index 343a78d5e0..92e80ee194 100644 --- a/Libraries/LibWeb/CSS/CSSMathProduct.cpp +++ b/Libraries/LibWeb/CSS/CSSMathProduct.cpp @@ -43,7 +43,7 @@ WebIDL::ExceptionOr> CSSMathProduct::multiply_all_types_ } // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssmathproduct-cssmathproduct -WebIDL::ExceptionOr> CSSMathProduct::construct_impl(JS::Realm& realm, Vector values) +WebIDL::ExceptionOr> CSSMathProduct::construct_impl(JS::Realm& realm, ReadonlySpan values) { // The CSSMathProduct(...args) constructor is defined identically to the above, except that in step 3 it multiplies // the types instead of adding, and in the last step it returns a CSSMathProduct. diff --git a/Libraries/LibWeb/CSS/CSSMathProduct.h b/Libraries/LibWeb/CSS/CSSMathProduct.h index 30a74be9d4..57ebb305d4 100644 --- a/Libraries/LibWeb/CSS/CSSMathProduct.h +++ b/Libraries/LibWeb/CSS/CSSMathProduct.h @@ -17,7 +17,7 @@ class CSSMathProduct final : public CSSMathValue { public: [[nodiscard]] static GC::Ref create(JS::Realm&, NumericType, GC::Ref); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Vector); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, ReadonlySpan); static WebIDL::ExceptionOr> multiply_all_types_into_math_product(JS::Realm&, GC::RootVector> const&); virtual ~CSSMathProduct() override; diff --git a/Libraries/LibWeb/CSS/CSSMathSum.cpp b/Libraries/LibWeb/CSS/CSSMathSum.cpp index 3208801d62..4db823068b 100644 --- a/Libraries/LibWeb/CSS/CSSMathSum.cpp +++ b/Libraries/LibWeb/CSS/CSSMathSum.cpp @@ -43,7 +43,7 @@ WebIDL::ExceptionOr> CSSMathSum::add_all_types_into_math_sum } // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssmathsum-cssmathsum -WebIDL::ExceptionOr> CSSMathSum::construct_impl(JS::Realm& realm, Vector values) +WebIDL::ExceptionOr> CSSMathSum::construct_impl(JS::Realm& realm, ReadonlySpan values) { // The CSSMathSum(...args) constructor must, when called, perform the following steps: diff --git a/Libraries/LibWeb/CSS/CSSMathSum.h b/Libraries/LibWeb/CSS/CSSMathSum.h index 52d9c9697e..84f3fce027 100644 --- a/Libraries/LibWeb/CSS/CSSMathSum.h +++ b/Libraries/LibWeb/CSS/CSSMathSum.h @@ -17,7 +17,7 @@ class CSSMathSum final : public CSSMathValue { public: [[nodiscard]] static GC::Ref create(JS::Realm&, NumericType, GC::Ref); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Vector); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, ReadonlySpan); static WebIDL::ExceptionOr> add_all_types_into_math_sum(JS::Realm&, GC::RootVector> const&); virtual ~CSSMathSum() override; diff --git a/Libraries/LibWeb/CSS/CSSNumericValue.cpp b/Libraries/LibWeb/CSS/CSSNumericValue.cpp index 0c71a56762..e62bb28917 100644 --- a/Libraries/LibWeb/CSS/CSSNumericValue.cpp +++ b/Libraries/LibWeb/CSS/CSSNumericValue.cpp @@ -63,7 +63,7 @@ void CSSNumericValue::initialize(JS::Realm& realm) Base::initialize(realm); } -static bool all_values_are_css_unit_values_with_the_same_unit(GC::RootVector> const& values) +static bool all_values_are_css_unit_values_with_the_same_unit(ReadonlySpan> const& values) { VERIFY(!values.is_empty()); return all_of(values, [&](auto& value) { @@ -74,7 +74,7 @@ static bool all_values_are_css_unit_values_with_the_same_unit(GC::RootVector -static GC::Ref apply_math_operation_on_css_unit_values(JS::Realm& realm, GC::RootVector> const& values, Operation&& operation) +static GC::Ref apply_math_operation_on_css_unit_values(JS::Realm& realm, ReadonlySpan> values, Operation&& operation) { auto& first_unit_value = as(*values[0]); auto& unit = first_unit_value.unit(); @@ -86,7 +86,7 @@ static GC::Ref apply_math_operation_on_css_unit_values(JS::Real } // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssnumericvalue-add -WebIDL::ExceptionOr> CSSNumericValue::add(Vector const& initial_values) +WebIDL::ExceptionOr> CSSNumericValue::add(ReadonlySpan initial_values) { auto& realm = this->realm(); @@ -118,7 +118,7 @@ WebIDL::ExceptionOr> CSSNumericValue::add(Vector> CSSNumericValue::sub(Vector const& initial_values) +WebIDL::ExceptionOr> CSSNumericValue::sub(ReadonlySpan initial_values) { auto& realm = this->realm(); @@ -136,19 +136,19 @@ CSSNumberish CSSNumericValue::negate() { // 1. If this is a CSSMathNegate object, return this’s value internal slot. if (auto* negate = as_if(*this)) - return GC::Root { negate->value().ptr() }; + return GC::Ref { negate->value() }; // 2. If this is a CSSUnitValue object, return a new CSSUnitValue with the same unit internal slot as this, and a // value internal slot set to the negation of this’s. if (auto* unit_value = as_if(*this)) - return GC::Root { CSSUnitValue::create(realm(), -unit_value->value(), unit_value->unit()).ptr() }; + return GC::Ref { CSSUnitValue::create(realm(), -unit_value->value(), unit_value->unit()) }; // 3. Otherwise, return a new CSSMathNegate object whose value internal slot is set to this. - return GC::Root { CSSMathNegate::construct_impl(realm(), GC::Root { this }).ptr() }; + return GC::Ref { CSSMathNegate::construct_impl(realm(), GC::Ref { *this }) }; } // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssnumericvalue-mul -WebIDL::ExceptionOr> CSSNumericValue::mul(Vector const& initial_values) +WebIDL::ExceptionOr> CSSNumericValue::mul(ReadonlySpan initial_values) { auto& realm = this->realm(); // 1. Replace each item of values with the result of rectifying a numberish value for the item. @@ -209,7 +209,7 @@ WebIDL::ExceptionOr> CSSNumericValue::mul(Vector> CSSNumericValue::div(Vector const& initial_values) +WebIDL::ExceptionOr> CSSNumericValue::div(ReadonlySpan initial_values) { auto& realm = this->realm(); @@ -227,7 +227,7 @@ WebIDL::ExceptionOr CSSNumericValue::invert() { // 1. If this is a CSSMathInvert object, return this’s value internal slot. if (auto* invert = as_if(*this)) - return GC::Root { invert->value().ptr() }; + return CSSNumberish { GC::Ref { invert->value() } }; // 2. If this is a CSSUnitValue object with unit internal slot set to "number": if (auto* unit_value = as_if(*this); unit_value && unit_value->unit() == "number"sv) { @@ -237,15 +237,15 @@ WebIDL::ExceptionOr CSSNumericValue::invert() // 2. Else return a new CSSUnitValue with the unit internal slot set to "number", and a value internal slot set // to 1 divided by this’s {CSSUnitValue/value}} internal slot. - return GC::Root { CSSUnitValue::create(realm(), 1.0 / unit_value->value(), "number"_fly_string).ptr() }; + return CSSNumberish { GC::Ref { CSSUnitValue::create(realm(), 1.0 / unit_value->value(), "number"_fly_string) } }; } // 3. Otherwise, return a new CSSMathInvert object whose value internal slot is set to this. - return GC::Root { CSSMathInvert::construct_impl(realm(), GC::Root { this }).ptr() }; + return CSSNumberish { GC::Ref { CSSMathInvert::construct_impl(realm(), GC::Ref { *this }) } }; } // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssnumericvalue-min -WebIDL::ExceptionOr> CSSNumericValue::min(Vector const& initial_values) +WebIDL::ExceptionOr> CSSNumericValue::min(ReadonlySpan initial_values) { auto& realm = this->realm(); @@ -275,7 +275,7 @@ WebIDL::ExceptionOr> CSSNumericValue::min(Vector> CSSNumericValue::max(Vector const& initial_values) +WebIDL::ExceptionOr> CSSNumericValue::max(ReadonlySpan initial_values) { auto& realm = this->realm(); @@ -305,7 +305,7 @@ WebIDL::ExceptionOr> CSSNumericValue::max(Vector values) const +bool CSSNumericValue::equals_for_bindings(ReadonlySpan values) const { // The equals(...values) method, when called on a CSSNumericValue this, must perform the following steps: @@ -432,8 +432,8 @@ GC::Ref rectify_a_numberish_value(JS::Realm& realm, CSSNumberis // To rectify a numberish value num, optionally to a given unit unit (defaulting to "number"), perform the following steps: return numberish.visit( // 1. If num is a CSSNumericValue, return num. - [](GC::Root const& num) -> GC::Ref { - return GC::Ref { *num }; + [](GC::Ref num) -> GC::Ref { + return num; }, // 2. If num is a double, return a new CSSUnitValue with its value internal slot set to num and its unit // internal slot set to unit. diff --git a/Libraries/LibWeb/CSS/CSSNumericValue.h b/Libraries/LibWeb/CSS/CSSNumericValue.h index 8a8f8f3ad0..5c8c8d4c77 100644 --- a/Libraries/LibWeb/CSS/CSSNumericValue.h +++ b/Libraries/LibWeb/CSS/CSSNumericValue.h @@ -36,14 +36,14 @@ public: }; virtual ~CSSNumericValue() override = default; - WebIDL::ExceptionOr> add(Vector const&); - WebIDL::ExceptionOr> sub(Vector const&); - WebIDL::ExceptionOr> mul(Vector const&); - WebIDL::ExceptionOr> div(Vector const&); - WebIDL::ExceptionOr> min(Vector const&); - WebIDL::ExceptionOr> max(Vector const&); + WebIDL::ExceptionOr> add(ReadonlySpan); + WebIDL::ExceptionOr> sub(ReadonlySpan); + WebIDL::ExceptionOr> mul(ReadonlySpan); + WebIDL::ExceptionOr> div(ReadonlySpan); + WebIDL::ExceptionOr> min(ReadonlySpan); + WebIDL::ExceptionOr> max(ReadonlySpan); - bool equals_for_bindings(Vector) const; + bool equals_for_bindings(ReadonlySpan) const; virtual bool is_equal_numeric_value(GC::Ref other) const = 0; WebIDL::ExceptionOr> to(FlyString const& unit) const; diff --git a/Libraries/LibWeb/CSS/CSSPerspective.cpp b/Libraries/LibWeb/CSS/CSSPerspective.cpp index fbf3c7544b..8004b88e5d 100644 --- a/Libraries/LibWeb/CSS/CSSPerspective.cpp +++ b/Libraries/LibWeb/CSS/CSSPerspective.cpp @@ -24,7 +24,7 @@ static WebIDL::ExceptionOr to_internal(JS::Realm& r // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssperspective-cssperspective return value.visit( // 1. If length is a CSSNumericValue: - [](GC::Root const& numeric_value) -> WebIDL::ExceptionOr { + [](GC::Ref const& numeric_value) -> WebIDL::ExceptionOr { // 1. If length does not match , throw a TypeError. if (!numeric_value->type().matches_length({})) { return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "CSSPerspective length component doesn't match "sv }; @@ -135,13 +135,7 @@ WebIDL::ExceptionOr> CSSPerspective::to_matrix() co CSSPerspectiveValue CSSPerspective::length() const { - return m_length.visit( - [](GC::Ref const& numeric_value) -> CSSPerspectiveValue { - return GC::Root { numeric_value }; - }, - [](GC::Ref const& keyword_value) -> CSSPerspectiveValue { - return CSSKeywordish { keyword_value }; - }); + return m_length; } WebIDL::ExceptionOr CSSPerspective::set_length(CSSPerspectiveValue value) diff --git a/Libraries/LibWeb/CSS/CSSPerspective.h b/Libraries/LibWeb/CSS/CSSPerspective.h index 4ea60d938a..14e8432a0c 100644 --- a/Libraries/LibWeb/CSS/CSSPerspective.h +++ b/Libraries/LibWeb/CSS/CSSPerspective.h @@ -14,7 +14,7 @@ namespace Web::CSS { // https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-cssperspectivevalue // NB: CSSKeywordish is flattened here, because our bindings generator flattens nested variants. -using CSSPerspectiveValue = Variant, String, GC::Root>; +using CSSPerspectiveValue = Variant, String, GC::Ref>; using CSSPerspectiveValueInternal = Variant, GC::Ref>; // https://drafts.css-houdini.org/css-typed-om-1/#cssperspective diff --git a/Libraries/LibWeb/CSS/CSSRotate.h b/Libraries/LibWeb/CSS/CSSRotate.h index 21d15c3bd7..1848d32386 100644 --- a/Libraries/LibWeb/CSS/CSSRotate.h +++ b/Libraries/LibWeb/CSS/CSSRotate.h @@ -27,9 +27,9 @@ public: virtual WebIDL::ExceptionOr> to_matrix() const override; - CSSNumberish x() const { return GC::Root { m_x }; } - CSSNumberish y() const { return GC::Root { m_y }; } - CSSNumberish z() const { return GC::Root { m_z }; } + CSSNumberish x() const { return m_x; } + CSSNumberish y() const { return m_y; } + CSSNumberish z() const { return m_z; } GC::Ref angle() const { return m_angle; } WebIDL::ExceptionOr set_x(CSSNumberish value); WebIDL::ExceptionOr set_y(CSSNumberish value); diff --git a/Libraries/LibWeb/CSS/CSSScale.h b/Libraries/LibWeb/CSS/CSSScale.h index dedb519a1a..d8bbe87fb6 100644 --- a/Libraries/LibWeb/CSS/CSSScale.h +++ b/Libraries/LibWeb/CSS/CSSScale.h @@ -26,9 +26,9 @@ public: virtual WebIDL::ExceptionOr> to_matrix() const override; - CSSNumberish x() const { return GC::Root { m_x }; } - CSSNumberish y() const { return GC::Root { m_y }; } - CSSNumberish z() const { return GC::Root { m_z }; } + CSSNumberish x() const { return m_x; } + CSSNumberish y() const { return m_y; } + CSSNumberish z() const { return m_z; } WebIDL::ExceptionOr set_x(CSSNumberish value); WebIDL::ExceptionOr set_y(CSSNumberish value); WebIDL::ExceptionOr set_z(CSSNumberish value); diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index e1cdd480c6..bb18bf2107 100644 --- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -92,7 +92,7 @@ WebIDL::ExceptionOr> CSSStyleSheet::construct_impl(JS::Re if (options->media.has()) { sheet->set_media(options->media.get()); } else { - sheet->m_media = *options->media.get>(); + sheet->m_media = *options->media.get>(); } } diff --git a/Libraries/LibWeb/CSS/CSSTransformValue.cpp b/Libraries/LibWeb/CSS/CSSTransformValue.cpp index e3e8978ba0..069da23187 100644 --- a/Libraries/LibWeb/CSS/CSSTransformValue.cpp +++ b/Libraries/LibWeb/CSS/CSSTransformValue.cpp @@ -18,13 +18,17 @@ namespace Web::CSS { GC_DEFINE_ALLOCATOR(CSSTransformValue); -GC::Ref CSSTransformValue::create(JS::Realm& realm, Vector> transforms) +GC::Ref CSSTransformValue::create(JS::Realm& realm, ReadonlySpan> transforms) { - return realm.create(realm, move(transforms)); + Vector> converted_transforms; + converted_transforms.ensure_capacity(transforms.size()); + for (auto const& transform : transforms) + converted_transforms.append(transform); + return realm.create(realm, move(converted_transforms)); } // https://drafts.css-houdini.org/css-typed-om-1/#dom-csstransformvalue-csstransformvalue -WebIDL::ExceptionOr> CSSTransformValue::construct_impl(JS::Realm& realm, Vector> const& transforms) +WebIDL::ExceptionOr> CSSTransformValue::construct_impl(JS::Realm& realm, ReadonlySpan> const& transforms) { // The CSSTransformValue(transforms) constructor must, when called, perform the following steps: @@ -33,11 +37,7 @@ WebIDL::ExceptionOr> CSSTransformValue::construct_imp return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "CSSTransformValue's transforms list cannot be empty."sv }; // 2. Return a new CSSTransformValue whose values to iterate over is transforms. - Vector> converted_transforms; - converted_transforms.ensure_capacity(transforms.size()); - for (auto const& transform : transforms) - converted_transforms.append(*transform); - return CSSTransformValue::create(realm, move(converted_transforms)); + return CSSTransformValue::create(realm, transforms); } CSSTransformValue::CSSTransformValue(JS::Realm& realm, Vector> transforms) diff --git a/Libraries/LibWeb/CSS/CSSTransformValue.h b/Libraries/LibWeb/CSS/CSSTransformValue.h index fdb9c6cd26..a830defd0b 100644 --- a/Libraries/LibWeb/CSS/CSSTransformValue.h +++ b/Libraries/LibWeb/CSS/CSSTransformValue.h @@ -17,8 +17,8 @@ class CSSTransformValue final : public CSSStyleValue { GC_DECLARE_ALLOCATOR(CSSTransformValue); public: - [[nodiscard]] static GC::Ref create(JS::Realm&, Vector>); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Vector> const&); + [[nodiscard]] static GC::Ref create(JS::Realm&, ReadonlySpan>); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, ReadonlySpan> const&); virtual ~CSSTransformValue() override; diff --git a/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp b/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp index cab15e8d18..4484cc7ee7 100644 --- a/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp +++ b/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp @@ -16,13 +16,13 @@ namespace Web::CSS { GC_DEFINE_ALLOCATOR(CSSUnparsedValue); -GC::Ref CSSUnparsedValue::create(JS::Realm& realm, Vector value) +GC::Ref CSSUnparsedValue::create(JS::Realm& realm, ReadonlySpan value) { - // NB: Convert our GC::Roots into GC::Refs. + // NB: Convert our Span into a Vector of Refs. Vector converted_value; for (auto const& variant : value) { variant.visit( - [&](GC::Root const& it) { converted_value.append(GC::Ref { *it }); }, + [&](GC::Ref it) { converted_value.append(it); }, [&](String const& it) { converted_value.append(it); }); } @@ -30,14 +30,14 @@ GC::Ref CSSUnparsedValue::create(JS::Realm& realm, Vector> CSSUnparsedValue::construct_impl(JS::Realm& realm, Vector value) +WebIDL::ExceptionOr> CSSUnparsedValue::construct_impl(JS::Realm& realm, ReadonlySpan value) { // AD-HOC: There is no spec for this, see https://github.com/w3c/css-houdini-drafts/issues/1146 return CSSUnparsedValue::create(realm, move(value)); } -CSSUnparsedValue::CSSUnparsedValue(JS::Realm& realm, Vector value) +CSSUnparsedValue::CSSUnparsedValue(JS::Realm& realm, ReadonlySpan value) : CSSStyleValue(realm) , m_tokens(move(value)) { diff --git a/Libraries/LibWeb/CSS/CSSUnparsedValue.h b/Libraries/LibWeb/CSS/CSSUnparsedValue.h index 62c27359bb..7127575190 100644 --- a/Libraries/LibWeb/CSS/CSSUnparsedValue.h +++ b/Libraries/LibWeb/CSS/CSSUnparsedValue.h @@ -12,7 +12,6 @@ namespace Web::CSS { using CSSUnparsedSegment = Variant>; -using GCRootCSSUnparsedSegment = Variant>; // https://drafts.css-houdini.org/css-typed-om-1/#cssunparsedvalue class CSSUnparsedValue final : public CSSStyleValue { @@ -20,8 +19,8 @@ class CSSUnparsedValue final : public CSSStyleValue { GC_DECLARE_ALLOCATOR(CSSUnparsedValue); public: - [[nodiscard]] static GC::Ref create(JS::Realm&, Vector); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Vector); + [[nodiscard]] static GC::Ref create(JS::Realm&, ReadonlySpan); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, ReadonlySpan); virtual ~CSSUnparsedValue() override; @@ -34,7 +33,7 @@ public: virtual WebIDL::ExceptionOr> create_an_internal_representation(PropertyNameAndID const&, PerformTypeCheck) const override; private: - explicit CSSUnparsedValue(JS::Realm&, Vector); + explicit CSSUnparsedValue(JS::Realm&, ReadonlySpan); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor&) override; diff --git a/Libraries/LibWeb/CSS/FontFace.cpp b/Libraries/LibWeb/CSS/FontFace.cpp index e51a02e3ac..2943db7cd5 100644 --- a/Libraries/LibWeb/CSS/FontFace.cpp +++ b/Libraries/LibWeb/CSS/FontFace.cpp @@ -177,7 +177,7 @@ GC::Ref FontFace::construct_impl(JS::Realm& realm, String family, Font font_face->m_urls = ParsedFontFace::sources_from_style_value(*parsed_source); font_face->m_urls.remove_all_matching(is_unsupported_source); } else { - auto buffer_source = source.get>(); + auto buffer_source = source.get>(); auto maybe_buffer = WebIDL::get_buffer_source_copy(buffer_source->raw_object()); if (maybe_buffer.is_error()) { VERIFY(maybe_buffer.error().code() == ENOMEM); diff --git a/Libraries/LibWeb/CSS/FontFace.h b/Libraries/LibWeb/CSS/FontFace.h index 77714ce4a9..0d9ecbb595 100644 --- a/Libraries/LibWeb/CSS/FontFace.h +++ b/Libraries/LibWeb/CSS/FontFace.h @@ -23,7 +23,7 @@ class FontFace final : public Bindings::PlatformObject { GC_DECLARE_ALLOCATOR(FontFace); public: - using FontFaceSource = Variant>; + using FontFaceSource = Variant>; [[nodiscard]] static GC::Ref construct_impl(JS::Realm&, String family, FontFaceSource source, Bindings::FontFaceDescriptors const& descriptors); [[nodiscard]] static GC::Ref create_css_connected(JS::Realm&, CSSFontFaceRule&); diff --git a/Libraries/LibWeb/CSS/FontFaceSet.cpp b/Libraries/LibWeb/CSS/FontFaceSet.cpp index 6a1a16f03a..9ca2e46388 100644 --- a/Libraries/LibWeb/CSS/FontFaceSet.cpp +++ b/Libraries/LibWeb/CSS/FontFaceSet.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -375,7 +376,7 @@ void FontFaceSet::fire_a_font_load_event(FlyString name, Vectorset_has(font_face)) load_event_init.fontfaces.append(font_face); diff --git a/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.cpp b/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.cpp index dc9337b4ff..1070b7b25c 100644 --- a/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.cpp +++ b/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.cpp @@ -29,8 +29,7 @@ FontFaceSetLoadEvent::FontFaceSetLoadEvent(JS::Realm& realm, FlyString const& ev { m_fontfaces.ensure_capacity(event_init.fontfaces.size()); for (auto const& font_face : event_init.fontfaces) { - VERIFY(font_face); - m_fontfaces.unchecked_append(*font_face); + m_fontfaces.unchecked_append(font_face); } } diff --git a/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.h b/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.h index ccb7276cef..c1cf89e799 100644 --- a/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.h +++ b/Libraries/LibWeb/CSS/FontFaceSetLoadEvent.h @@ -6,7 +6,6 @@ #pragma once -#include #include #include @@ -17,15 +16,15 @@ class FontFaceSetLoadEvent : public DOM::Event { GC_DECLARE_ALLOCATOR(FontFaceSetLoadEvent); public: - [[nodiscard]] static GC::Ref create(JS::Realm&, FlyString const& type, Bindings::FontFaceSetLoadEventInit const& event_init = {}); - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& type, Bindings::FontFaceSetLoadEventInit const& event_init = {}); + [[nodiscard]] static GC::Ref create(JS::Realm&, FlyString const& type, Bindings::FontFaceSetLoadEventInit const&); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& type, Bindings::FontFaceSetLoadEventInit const&); virtual ~FontFaceSetLoadEvent() override = default; Vector> const& fontfaces() const { return m_fontfaces; } private: - FontFaceSetLoadEvent(JS::Realm&, FlyString const& type, Bindings::FontFaceSetLoadEventInit const& event_init = {}); + FontFaceSetLoadEvent(JS::Realm&, FlyString const& type, Bindings::FontFaceSetLoadEventInit const&); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor&) override; diff --git a/Libraries/LibWeb/CSS/StylePropertyMap.cpp b/Libraries/LibWeb/CSS/StylePropertyMap.cpp index 56a3499e8a..1dd7129a13 100644 --- a/Libraries/LibWeb/CSS/StylePropertyMap.cpp +++ b/Libraries/LibWeb/CSS/StylePropertyMap.cpp @@ -47,10 +47,10 @@ void StylePropertyMap::initialize(JS::Realm& realm) Base::initialize(realm); } -static bool any_have_non_matching_associated_property(FlyString const& property, Vector, String>> values) +static bool any_have_non_matching_associated_property(FlyString const& property, ReadonlySpan, String>> values) { - return any_of(values, [&property](Variant, String> const& value) { - if (auto* style_value = value.get_pointer>()) { + return any_of(values, [&property](Variant, String> const& value) { + if (auto* style_value = value.get_pointer>()) { if (auto associated_property = (*style_value)->associated_property(); associated_property.has_value() && associated_property != property) return true; @@ -60,11 +60,11 @@ static bool any_have_non_matching_associated_property(FlyString const& property, } // https://drafts.css-houdini.org/css-typed-om-1/#create-an-internal-representation -static WebIDL::ExceptionOr> create_an_internal_representation(JS::VM& vm, PropertyNameAndID const& property, Variant, String> const& value) +static WebIDL::ExceptionOr> create_an_internal_representation(JS::VM& vm, PropertyNameAndID const& property, Variant, String> const& value) { // To create an internal representation, given a string property and a string or CSSStyleValue value: return value.visit( - [&property](GC::Root const& css_style_value) { + [&property](GC::Ref const& css_style_value) { return css_style_value->create_an_internal_representation(property, CSSStyleValue::PerformTypeCheck::Yes); }, [&](String const& css_text) -> WebIDL::ExceptionOr> { @@ -116,7 +116,7 @@ static WebIDL::ExceptionOr> normalize_overflow_c } // https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-set -WebIDL::ExceptionOr StylePropertyMap::set(FlyString property_name, Vector, String>> values) +WebIDL::ExceptionOr StylePropertyMap::set(FlyString property_name, ReadonlySpan, String>> values) { // The set(property, ...values) method, when called on a StylePropertyMap this, must perform the following steps: @@ -221,7 +221,7 @@ WebIDL::ExceptionOr StylePropertyMap::set(FlyString property_name, Vector< } // https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-append -WebIDL::ExceptionOr StylePropertyMap::append(FlyString property_name, Vector, String>> values) +WebIDL::ExceptionOr StylePropertyMap::append(FlyString property_name, ReadonlySpan, String>> values) { // The append(property, ...values) method, when called on a StylePropertyMap this, must perform the following steps: diff --git a/Libraries/LibWeb/CSS/StylePropertyMap.h b/Libraries/LibWeb/CSS/StylePropertyMap.h index bdaa477109..2ba56f1f3b 100644 --- a/Libraries/LibWeb/CSS/StylePropertyMap.h +++ b/Libraries/LibWeb/CSS/StylePropertyMap.h @@ -20,8 +20,8 @@ public: virtual ~StylePropertyMap() override; - WebIDL::ExceptionOr set(FlyString property, Vector, String>> values); - WebIDL::ExceptionOr append(FlyString property, Vector, String>> values); + WebIDL::ExceptionOr set(FlyString property, ReadonlySpan, String>> values); + WebIDL::ExceptionOr append(FlyString property, ReadonlySpan, String>> values); WebIDL::ExceptionOr delete_(FlyString property); WebIDL::ExceptionOr clear(); diff --git a/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp index de78a69d8b..96214e3c6f 100644 --- a/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp @@ -52,7 +52,7 @@ bool UnresolvedStyleValue::equals(StyleValue const& other) const static GC::Ref reify_a_list_of_component_values(JS::Realm&, Vector); // https://drafts.css-houdini.org/css-typed-om-1/#reify-var -static GC::Root reify_a_var_reference(JS::Realm& realm, Parser::Function function) +static GC::Ptr reify_a_var_reference(JS::Realm& realm, Parser::Function function) { // NB: A var() might not be representable as a CSSVariableReferenceValue, for example if it has invalid syntax or // it contains an ASF in its variable-name slot. In those cases, we return null here, so it's treated like a @@ -90,7 +90,7 @@ static GC::Root reify_a_var_reference(JS::Realm& real class Reifier { public: - static Vector reify(JS::Realm& realm, Vector const& source_values) + static Vector reify(JS::Realm& realm, Vector const& source_values) { Reifier reifier; reifier.process_values(realm, source_values); @@ -112,7 +112,7 @@ private: // serializing it like a regular function. if (auto var_reference = reify_a_var_reference(realm, component_value.function())) { serialize_unserialized_values(); - m_reified_values.append(move(var_reference)); + m_reified_values.append(GC::Ref { *var_reference }); continue; } } @@ -143,7 +143,7 @@ private: m_unserialized_values.clear_with_capacity(); } - Vector m_reified_values {}; + Vector m_reified_values {}; Vector m_unserialized_values {}; }; diff --git a/Libraries/LibWeb/Clipboard/Clipboard.cpp b/Libraries/LibWeb/Clipboard/Clipboard.cpp index 97b534f511..2c9838c57f 100644 --- a/Libraries/LibWeb/Clipboard/Clipboard.cpp +++ b/Libraries/LibWeb/Clipboard/Clipboard.cpp @@ -398,7 +398,7 @@ GC::Ref Clipboard::read_text() } // https://w3c.github.io/clipboard-apis/#dom-clipboard-write -GC::Ref Clipboard::write(Vector> const& data) +GC::Ref Clipboard::write(GC::RootVector> const& data) { // 1. Let realm be this's relevant realm. auto& realm = HTML::relevant_realm(*this); diff --git a/Libraries/LibWeb/Clipboard/Clipboard.h b/Libraries/LibWeb/Clipboard/Clipboard.h index 038414b23c..01bea9bd4f 100644 --- a/Libraries/LibWeb/Clipboard/Clipboard.h +++ b/Libraries/LibWeb/Clipboard/Clipboard.h @@ -27,7 +27,7 @@ public: GC::Ref read(Bindings::ClipboardUnsanitizedFormats formats = {}); GC::Ref read_text(); - GC::Ref write(Vector> const&); + GC::Ref write(GC::RootVector> const&); GC::Ref write_text(String); private: diff --git a/Libraries/LibWeb/Clipboard/ClipboardItem.cpp b/Libraries/LibWeb/Clipboard/ClipboardItem.cpp index 2327814015..a5c24473c9 100644 --- a/Libraries/LibWeb/Clipboard/ClipboardItem.cpp +++ b/Libraries/LibWeb/Clipboard/ClipboardItem.cpp @@ -16,7 +16,7 @@ namespace Web::Clipboard { GC_DEFINE_ALLOCATOR(ClipboardItem); // https://w3c.github.io/clipboard-apis/#dom-clipboarditem-clipboarditem -WebIDL::ExceptionOr> ClipboardItem::construct_impl(JS::Realm& realm, OrderedHashMap> const& items, Bindings::ClipboardItemOptions const& options) +WebIDL::ExceptionOr> ClipboardItem::construct_impl(JS::Realm& realm, GC::OrderedRootHashMap> const& items, Bindings::ClipboardItemOptions const& options) { // 1. If items is empty, then throw a TypeError. if (items.is_empty()) diff --git a/Libraries/LibWeb/Clipboard/ClipboardItem.h b/Libraries/LibWeb/Clipboard/ClipboardItem.h index 01c784a55f..9a121a83c7 100644 --- a/Libraries/LibWeb/Clipboard/ClipboardItem.h +++ b/Libraries/LibWeb/Clipboard/ClipboardItem.h @@ -35,7 +35,7 @@ public: GC::Ref data; // The actual data for this representation. }; - static WebIDL::ExceptionOr> construct_impl(JS::Realm&, OrderedHashMap> const& items, Bindings::ClipboardItemOptions const& options = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, GC::OrderedRootHashMap> const& items, Bindings::ClipboardItemOptions const& options = {}); virtual ~ClipboardItem() override; diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index 5e8a9d656a..000c148200 100644 --- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -56,8 +56,7 @@ static JS::ThrowCompletionOr hash_algorithm_identifier_ } if (hash_value.is_object()) { auto const hash_object = TRY(hash_value.to_object(vm)); - auto const hash_object_root = GC::make_root(hash_object); - return normalize_an_algorithm(*realm, hash_object_root, "digest"_string); + return normalize_an_algorithm(*realm, hash_object, "digest"_string); } VERIFY_NOT_REACHED(); }(); diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.h b/Libraries/LibWeb/Crypto/CryptoAlgorithms.h index ce4a69cfde..fa594e650d 100644 --- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.h +++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.h @@ -22,9 +22,9 @@ namespace Web::Crypto { -using AlgorithmIdentifier = Variant, String>; +using AlgorithmIdentifier = Variant, String>; using NamedCurve = String; -using KeyDataType = Variant, JsonWebKey>; +using KeyDataType = Variant, JsonWebKey>; // https://wicg.github.io/webcrypto-modern-algos/#encapsulation struct EncapsulatedKey { diff --git a/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index 09e1a72438..a2b96c7ab8 100644 --- a/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -109,9 +109,8 @@ WebIDL::ExceptionOr normalize_an_algorithm(JS:: if (algorithm.has()) { // Return the result of running the normalize an algorithm algorithm, // with the alg set to a new Algorithm dictionary whose name attribute is alg, and with the op set to op. - auto dictionary = GC::make_root(JS::Object::create(realm, realm.intrinsics().object_prototype())); + auto dictionary = JS::Object::create(realm, realm.intrinsics().object_prototype()); TRY(dictionary->create_data_property("name"_utf16_fly_string, JS::PrimitiveString::create(vm, algorithm.get()))); - return normalize_an_algorithm(realm, dictionary, operation); } @@ -127,7 +126,7 @@ WebIDL::ExceptionOr normalize_an_algorithm(JS:: // 3. If an error occurred, return the error and terminate this algorithm. // Note: We're not going to bother creating an Algorithm object, all we want is the name attribute so that we can // fetch the actual algorithm factory from the registeredAlgorithms map. - auto initial_algorithm = TRY(algorithm.get>()->get("name"_utf16_fly_string)); + auto initial_algorithm = TRY(algorithm.get>()->get("name"_utf16_fly_string)); if (initial_algorithm.is_undefined()) { return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Algorithm"); @@ -159,7 +158,7 @@ WebIDL::ExceptionOr normalize_an_algorithm(JS:: // 12. For each dictionary dictionary in dictionaries: // Note: All of these steps are handled by the create_methods and parameter_from_value methods. auto methods = desired_type.create_methods(realm); - auto parameter = TRY(desired_type.parameter_from_value(vm, algorithm.get>())); + auto parameter = TRY(desired_type.parameter_from_value(vm, algorithm.get>())); // 9. Set the name attribute of normalizedAlgorithm to algName. VERIFY(parameter->name.is_empty()); @@ -447,7 +446,7 @@ GC::Ref SubtleCrypto::generate_key(AlgorithmIdentifier algorith } // https://w3c.github.io/webcrypto/#SubtleCrypto-method-importKey -JS::ThrowCompletionOr> SubtleCrypto::import_key(Bindings::KeyFormat format, Variant, Bindings::JsonWebKey> key_data, AlgorithmIdentifier algorithm, bool extractable, Vector key_usages) +JS::ThrowCompletionOr> SubtleCrypto::import_key(Bindings::KeyFormat format, Variant, Bindings::JsonWebKey> key_data, AlgorithmIdentifier algorithm, bool extractable, Vector key_usages) { auto& realm = this->realm(); @@ -469,7 +468,7 @@ JS::ThrowCompletionOr> SubtleCrypto::import_key(Binding } // 2. Let keyData be the result of getting a copy of the bytes held by the keyData parameter passed to the importKey() method. - real_key_data = MUST(WebIDL::get_buffer_source_copy(*key_data.get>()->raw_object())); + real_key_data = MUST(WebIDL::get_buffer_source_copy(*key_data.get>()->raw_object())); } if (format == Bindings::KeyFormat::Jwk) { @@ -1079,7 +1078,7 @@ GC::Ref SubtleCrypto::unwrap_key(Bindings::KeyFormat format, Ke auto normalized_key_algorithm = normalized_key_algorithm_or_error.release_value(); // 7. Let wrappedKey be the result of getting a copy of the bytes held by the wrappedKey parameter passed to the unwrapKey() method. - auto real_wrapped_key = MUST(WebIDL::get_buffer_source_copy(*wrapped_key.get>()->raw_object())); + auto real_wrapped_key = MUST(WebIDL::get_buffer_source_copy(*wrapped_key.get>()->raw_object())); // 9. Let promise be a new Promise. auto promise = WebIDL::create_promise(realm); diff --git a/Libraries/LibWeb/Crypto/SubtleCrypto.h b/Libraries/LibWeb/Crypto/SubtleCrypto.h index 69773a0268..de8b894364 100644 --- a/Libraries/LibWeb/Crypto/SubtleCrypto.h +++ b/Libraries/LibWeb/Crypto/SubtleCrypto.h @@ -37,7 +37,7 @@ public: GC::Ref derive_bits(AlgorithmIdentifier algorithm, GC::Ref base_key, Optional length_optional); GC::Ref derive_key(AlgorithmIdentifier algorithm, GC::Ref base_key, AlgorithmIdentifier derived_key_type, bool extractable, Vector key_usages); - JS::ThrowCompletionOr> import_key(Bindings::KeyFormat format, Variant, Bindings::JsonWebKey> key_data, AlgorithmIdentifier algorithm, bool extractable, Vector key_usages); + JS::ThrowCompletionOr> import_key(Bindings::KeyFormat format, Variant, Bindings::JsonWebKey> key_data, AlgorithmIdentifier algorithm, bool extractable, Vector key_usages); GC::Ref export_key(Bindings::KeyFormat format, GC::Ref key); GC::Ref wrap_key(Bindings::KeyFormat format, GC::Ref key, GC::Ref wrapping_key, AlgorithmIdentifier wrap_algorithm); diff --git a/Libraries/LibWeb/DOM/AbortController.cpp b/Libraries/LibWeb/DOM/AbortController.cpp index 6bf606aadb..fe0c21f0bf 100644 --- a/Libraries/LibWeb/DOM/AbortController.cpp +++ b/Libraries/LibWeb/DOM/AbortController.cpp @@ -41,10 +41,10 @@ void AbortController::visit_edges(Cell::Visitor& visitor) } // https://dom.spec.whatwg.org/#dom-abortcontroller-abort -void AbortController::abort(JS::Value reason) +void AbortController::abort(Optional reason) { // The abort(reason) method steps are to signal abort on this’s signal with reason if it is given. - m_signal->signal_abort(reason); + m_signal->signal_abort(reason.value_or(JS::js_undefined())); } } diff --git a/Libraries/LibWeb/DOM/AbortController.h b/Libraries/LibWeb/DOM/AbortController.h index 049c12322a..1a18caf0d4 100644 --- a/Libraries/LibWeb/DOM/AbortController.h +++ b/Libraries/LibWeb/DOM/AbortController.h @@ -24,7 +24,7 @@ public: // https://dom.spec.whatwg.org/#dom-abortcontroller-signal GC::Ref signal() const { return *m_signal; } - void abort(JS::Value reason); + void abort(Optional reason); private: AbortController(JS::Realm&, GC::Ref); diff --git a/Libraries/LibWeb/DOM/AbortSignal.cpp b/Libraries/LibWeb/DOM/AbortSignal.cpp index 1f1b2fc81c..2ee89c2247 100644 --- a/Libraries/LibWeb/DOM/AbortSignal.cpp +++ b/Libraries/LibWeb/DOM/AbortSignal.cpp @@ -144,12 +144,13 @@ size_t AbortSignal::external_memory_size() const } // https://dom.spec.whatwg.org/#dom-abortsignal-abort -WebIDL::ExceptionOr> AbortSignal::abort(JS::VM& vm, JS::Value reason) +WebIDL::ExceptionOr> AbortSignal::abort(JS::VM& vm, Optional maybe_reason) { // 1. Let signal be a new AbortSignal object. auto signal = TRY(construct_impl(*vm.current_realm())); // 2. Set signal’s abort reason to reason if it is given; otherwise to a new "AbortError" DOMException. + auto reason = maybe_reason.value_or(JS::js_undefined()); if (reason.is_undefined()) reason = WebIDL::AbortError::create(*vm.current_realm(), "Aborted without reason"_utf16).ptr(); @@ -185,14 +186,14 @@ WebIDL::ExceptionOr> AbortSignal::timeout(JS::VM& vm, WebID } // https://dom.spec.whatwg.org/#dom-abortsignal-any -WebIDL::ExceptionOr> AbortSignal::any(JS::VM& vm, Vector> const& signals) +WebIDL::ExceptionOr> AbortSignal::any(JS::VM& vm, ReadonlySpan> signals) { // The static any(signals) method steps are to return the result of creating a dependent abort signal from signals using AbortSignal and the current realm. return create_dependent_abort_signal(*vm.current_realm(), signals); } // https://dom.spec.whatwg.org/#create-a-dependent-abort-signal -WebIDL::ExceptionOr> AbortSignal::create_dependent_abort_signal(JS::Realm& realm, Vector> const& signals) +WebIDL::ExceptionOr> AbortSignal::create_dependent_abort_signal(JS::Realm& realm, ReadonlySpan> signals) { // 1. Let resultSignal be a new object implementing signalInterface using realm. auto result_signal = TRY(construct_impl(realm)); diff --git a/Libraries/LibWeb/DOM/AbortSignal.h b/Libraries/LibWeb/DOM/AbortSignal.h index 94ceb89b47..eec6758078 100644 --- a/Libraries/LibWeb/DOM/AbortSignal.h +++ b/Libraries/LibWeb/DOM/AbortSignal.h @@ -46,11 +46,11 @@ public: JS::ThrowCompletionOr throw_if_aborted() const; - static WebIDL::ExceptionOr> abort(JS::VM&, JS::Value reason); + static WebIDL::ExceptionOr> abort(JS::VM&, Optional reason); static WebIDL::ExceptionOr> timeout(JS::VM&, Web::WebIDL::UnsignedLongLong milliseconds); - static WebIDL::ExceptionOr> any(JS::VM&, Vector> const&); + static WebIDL::ExceptionOr> any(JS::VM&, ReadonlySpan>); - static WebIDL::ExceptionOr> create_dependent_abort_signal(JS::Realm&, Vector> const&); + static WebIDL::ExceptionOr> create_dependent_abort_signal(JS::Realm&, ReadonlySpan>); private: explicit AbortSignal(JS::Realm&); diff --git a/Libraries/LibWeb/DOM/ChildNode.h b/Libraries/LibWeb/DOM/ChildNode.h index e36673c54b..cddfbc9439 100644 --- a/Libraries/LibWeb/DOM/ChildNode.h +++ b/Libraries/LibWeb/DOM/ChildNode.h @@ -16,7 +16,7 @@ template class ChildNode { public: // https://dom.spec.whatwg.org/#dom-childnode-before - WebIDL::ExceptionOr before(Vector, Utf16String>> const& nodes) + WebIDL::ExceptionOr before(ReadonlySpan, Utf16String>> nodes) { auto* node = static_cast(this); @@ -46,7 +46,7 @@ public: } // https://dom.spec.whatwg.org/#dom-childnode-after - WebIDL::ExceptionOr after(Vector, Utf16String>> const& nodes) + WebIDL::ExceptionOr after(ReadonlySpan, Utf16String>> nodes) { auto* node = static_cast(this); @@ -70,7 +70,7 @@ public: } // https://dom.spec.whatwg.org/#dom-childnode-replacewith - WebIDL::ExceptionOr replace_with(Vector, Utf16String>> const& nodes) + WebIDL::ExceptionOr replace_with(ReadonlySpan, Utf16String>> nodes) { auto* node = static_cast(this); @@ -117,7 +117,7 @@ protected: ChildNode() = default; private: - GC::Ptr viable_previous_sibling_for_insertion(Vector, Utf16String>> const& nodes) + GC::Ptr viable_previous_sibling_for_insertion(ReadonlySpan, Utf16String>> const& nodes) { auto* node = static_cast(this); @@ -125,11 +125,11 @@ private: bool contained_in_nodes = false; for (auto const& node_or_string : nodes) { - if (!node_or_string.template has>()) + if (!node_or_string.template has>()) continue; - auto const& node_in_vector = node_or_string.template get>(); - if (node_in_vector.cell() == sibling) { + auto const& node_in_vector = node_or_string.template get>(); + if (node_in_vector == sibling) { contained_in_nodes = true; break; } @@ -142,7 +142,7 @@ private: return nullptr; } - GC::Ptr viable_next_sibling_for_insertion(Vector, Utf16String>> const& nodes) + GC::Ptr viable_next_sibling_for_insertion(ReadonlySpan, Utf16String>> const& nodes) { auto* node = static_cast(this); @@ -150,11 +150,11 @@ private: bool contained_in_nodes = false; for (auto const& node_or_string : nodes) { - if (!node_or_string.template has>()) + if (!node_or_string.template has>()) continue; - auto const& node_in_vector = node_or_string.template get>(); - if (node_in_vector.cell() == sibling) { + auto const& node_in_vector = node_or_string.template get>(); + if (node_in_vector == sibling) { contained_in_nodes = true; break; } diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index f75f7efa62..f5682880e1 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include #include #include @@ -2678,11 +2680,11 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov // https://w3c.github.io/pointerevents/#the-pointerout-event if (old_hovered_node && old_hovered_node != m_hovered_node) { - Bindings::PointerEventInit pointer_event_init {}; + Bindings::PointerEventInit pointer_event_init; pointer_event_init.bubbles = true; pointer_event_init.cancelable = true; pointer_event_init.composed = true; - pointer_event_init.related_target = GC::Root { m_hovered_node.ptr() }; + pointer_event_init.related_target = m_hovered_node; pointer_event_init.is_primary = true; pointer_event_init.pointer_type = UIEvents::PointerTypes::Mouse; pointer_event_init.view = window_proxy; @@ -2700,7 +2702,7 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov mouse_event_init.bubbles = true; mouse_event_init.cancelable = true; mouse_event_init.composed = true; - mouse_event_init.related_target = GC::Root { m_hovered_node.ptr() }; + mouse_event_init.related_target = m_hovered_node; mouse_event_init.view = window_proxy; if (hover_event_data.has_value()) populate_mouse_event_init_from_hover_event_data(mouse_event_init, *hover_event_data, window_proxy); @@ -2713,8 +2715,8 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov // https://w3c.github.io/pointerevents/#the-pointerleave-event if (!pointer_leave_targets.is_empty()) { for (auto const& target : pointer_leave_targets) { - Bindings::PointerEventInit pointer_event_init {}; - pointer_event_init.related_target = GC::Root { m_hovered_node.ptr() }; + Bindings::PointerEventInit pointer_event_init; + pointer_event_init.related_target = m_hovered_node; pointer_event_init.is_primary = true; pointer_event_init.pointer_type = UIEvents::PointerTypes::Mouse; pointer_event_init.view = window_proxy; @@ -2731,7 +2733,7 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov if (!mouse_leave_targets.is_empty()) { for (auto const& target : mouse_leave_targets) { Bindings::MouseEventInit mouse_event_init {}; - mouse_event_init.related_target = GC::Root { m_hovered_node.ptr() }; + mouse_event_init.related_target = m_hovered_node; if (hover_event_data.has_value()) populate_mouse_event_init_from_hover_event_data(mouse_event_init, *hover_event_data, window_proxy); auto offset = target.offset; @@ -2743,11 +2745,11 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov // https://w3c.github.io/pointerevents/#the-pointerover-event if (m_hovered_node && m_hovered_node != old_hovered_node) { - Bindings::PointerEventInit pointer_event_init {}; + Bindings::PointerEventInit pointer_event_init; pointer_event_init.bubbles = true; pointer_event_init.cancelable = true; pointer_event_init.composed = true; - pointer_event_init.related_target = GC::Root { old_hovered_node.ptr() }; + pointer_event_init.related_target = old_hovered_node; pointer_event_init.is_primary = true; pointer_event_init.pointer_type = UIEvents::PointerTypes::Mouse; pointer_event_init.view = window_proxy; @@ -2765,7 +2767,7 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov mouse_event_init.bubbles = true; mouse_event_init.cancelable = true; mouse_event_init.composed = true; - mouse_event_init.related_target = GC::Root { old_hovered_node.ptr() }; + mouse_event_init.related_target = old_hovered_node; mouse_event_init.view = window_proxy; if (hover_event_data.has_value()) populate_mouse_event_init_from_hover_event_data(mouse_event_init, *hover_event_data, window_proxy); @@ -2781,8 +2783,8 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov // Leave events are dispatched in the opposite order. if (!entered_ancestors.is_empty()) { for (auto target : entered_ancestors.in_reverse()) { - Bindings::PointerEventInit pointer_event_init {}; - pointer_event_init.related_target = GC::Root { old_hovered_node.ptr() }; + Bindings::PointerEventInit pointer_event_init; + pointer_event_init.related_target = old_hovered_node; pointer_event_init.is_primary = true; pointer_event_init.pointer_type = UIEvents::PointerTypes::Mouse; pointer_event_init.view = window_proxy; @@ -2793,7 +2795,7 @@ void Document::set_hovered_node(GC::Ptr node, Optional hov mark_mouse_transition_event_as_trusted_if_needed(pointer_event, hover_event_data); target.node->dispatch_event(pointer_event); Bindings::MouseEventInit mouse_event_init {}; - mouse_event_init.related_target = GC::Root { old_hovered_node.ptr() }; + mouse_event_init.related_target = old_hovered_node; if (hover_event_data.has_value()) populate_mouse_event_init_from_hover_event_data(mouse_event_init, *hover_event_data, window_proxy); auto mouse_event = UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseenter, mouse_event_init, page_offset.x().to_double(), page_offset.y().to_double(), offset.x().to_double(), offset.y().to_double()); @@ -3076,7 +3078,7 @@ WebIDL::ExceptionOr> Document::create_event(StringView interface) } else if (interface.equals_ignoring_ascii_case("keyboardevent"sv)) { event = UIEvents::KeyboardEvent::create(realm, String {}); } else if (interface.equals_ignoring_ascii_case("messageevent"sv)) { - event = HTML::MessageEvent::create(realm, String {}); + event = HTML::MessageEvent::create(realm, FlyString {}, Bindings::MessageEventInit {}); } else if (interface.equals_ignoring_ascii_case("mouseevent"sv) || interface.equals_ignoring_ascii_case("mouseevents"sv)) { event = UIEvents::MouseEvent::create(realm, FlyString {}); @@ -3209,8 +3211,8 @@ WebIDL::ExceptionOr> Document::import_node(GC::Ref node, Var subtree = !options.self_only; // 2. If options["customElementRegistry"] exists, then set registry to it. - if (options.custom_element_registry.has_value()) - registry = options.custom_element_registry->ptr(); + if (options.custom_element_registry) + registry = options.custom_element_registry; // 3. If registry’s is scoped is false and registry is not this’s custom element registry, then throw a // "NotSupportedError" DOMException. diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 770888d227..1eb7c80a9f 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -386,7 +386,7 @@ GC::Ptr Element::get_attribute_node_ns(Optional const& namespac } // https://dom.spec.whatwg.org/#dom-element-setattribute -WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) +WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Ref, GC::Ref, Utf16String> const& value) { // 1. If qualifiedName is not a valid attribute local name, then throw an "InvalidCharacterError" DOMException. if (!is_valid_attribute_local_name(qualified_name)) @@ -421,12 +421,12 @@ WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualifie } // https://dom.spec.whatwg.org/#dom-element-setattribute -WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, String> const& value) +WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Ref, GC::Ref, String> const& value) { return set_attribute_for_bindings(move(qualified_name), value.visit( - [](auto const& trusted_type) -> Variant, GC::Root, GC::Root, Utf16String> { return trusted_type; }, - [](String const& string) -> Variant, GC::Root, GC::Root, Utf16String> { return Utf16String::from_utf8(string); })); + [](auto const& trusted_type) -> Variant, GC::Ref, GC::Ref, Utf16String> { return trusted_type; }, + [](String const& string) -> Variant, GC::Ref, GC::Ref, Utf16String> { return Utf16String::from_utf8(string); })); } // https://dom.spec.whatwg.org/#valid-namespace-prefix @@ -540,7 +540,7 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Option } // https://dom.spec.whatwg.org/#dom-element-setattributens -WebIDL::ExceptionOr Element::set_attribute_ns_for_bindings(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) +WebIDL::ExceptionOr Element::set_attribute_ns_for_bindings(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Ref, GC::Ref, Utf16String> const& value) { // 1. Let (namespace, prefix, localName) be the result of validating and extracting namespace and qualifiedName given "attribute". auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name, ValidationContext::Attribute)); diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 22143c65d3..5436a5c395 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -129,10 +129,10 @@ public: Optional lang() const; void invalidate_lang_value(); - WebIDL::ExceptionOr set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value); - WebIDL::ExceptionOr set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, String> const& value); + WebIDL::ExceptionOr set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Ref, GC::Ref, Utf16String> const& value); + WebIDL::ExceptionOr set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Ref, GC::Ref, String> const& value); - WebIDL::ExceptionOr set_attribute_ns_for_bindings(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value); + WebIDL::ExceptionOr set_attribute_ns_for_bindings(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Ref, GC::Ref, Utf16String> const& value); void set_attribute_value(FlyString const& local_name, String const& value, Optional const& prefix = {}, Optional const& namespace_ = {}); WebIDL::ExceptionOr> set_attribute_node_for_bindings(Attr&); WebIDL::ExceptionOr> set_attribute_node_ns_for_bindings(Attr&); diff --git a/Libraries/LibWeb/DOM/EventTarget.cpp b/Libraries/LibWeb/DOM/EventTarget.cpp index bf57cc9686..920211e19e 100644 --- a/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Libraries/LibWeb/DOM/EventTarget.cpp @@ -158,8 +158,8 @@ static FlattenedAddEventListenerOptions flatten_add_event_listener_options(Varia passive = add_event_listener_options.passive; // 3. If options["signal"] exists, then set signal to options["signal"]. - if (add_event_listener_options.signal.has_value()) - signal = add_event_listener_options.signal->ptr(); + if (add_event_listener_options.signal) + signal = add_event_listener_options.signal; } // 5. Return capture, passive, once, and signal. diff --git a/Libraries/LibWeb/DOM/NodeOperations.cpp b/Libraries/LibWeb/DOM/NodeOperations.cpp index 29e4f72071..ada5b1f415 100644 --- a/Libraries/LibWeb/DOM/NodeOperations.cpp +++ b/Libraries/LibWeb/DOM/NodeOperations.cpp @@ -16,12 +16,12 @@ namespace Web::DOM { // https://dom.spec.whatwg.org/#convert-nodes-into-a-node -WebIDL::ExceptionOr> convert_nodes_to_single_node(Vector, Utf16String>> const& nodes, Document& document) +WebIDL::ExceptionOr> convert_nodes_to_single_node(ReadonlySpan, Utf16String>> nodes, Document& document) { // 1. Replace each string of nodes with a new Text node whose data is the string and node document is document. - auto potentially_convert_string_to_text_node = [&document](Variant, Utf16String> const& node) -> GC::Ref { - if (node.has>()) - return *node.get>(); + auto potentially_convert_string_to_text_node = [&document](Variant, Utf16String> const& node) -> GC::Ref { + if (node.has>()) + return node.get>(); return document.realm().create(document, node.get()); }; diff --git a/Libraries/LibWeb/DOM/NodeOperations.h b/Libraries/LibWeb/DOM/NodeOperations.h index e45a8b57a7..fa8e40ba29 100644 --- a/Libraries/LibWeb/DOM/NodeOperations.h +++ b/Libraries/LibWeb/DOM/NodeOperations.h @@ -13,6 +13,6 @@ namespace Web::DOM { -WebIDL::ExceptionOr> convert_nodes_to_single_node(Vector, Utf16String>> const& nodes, DOM::Document& document); +WebIDL::ExceptionOr> convert_nodes_to_single_node(ReadonlySpan, Utf16String>> nodes, DOM::Document& document); } diff --git a/Libraries/LibWeb/DOM/ParentNode.cpp b/Libraries/LibWeb/DOM/ParentNode.cpp index b29b7fbbe2..35f616e86b 100644 --- a/Libraries/LibWeb/DOM/ParentNode.cpp +++ b/Libraries/LibWeb/DOM/ParentNode.cpp @@ -187,7 +187,7 @@ GC::Ref ParentNode::get_elements_by_tag_name_ns(Optional ParentNode::prepend(Vector, Utf16String>> const& nodes) +WebIDL::ExceptionOr ParentNode::prepend(ReadonlySpan, Utf16String>> const& nodes) { // 1. Let node be the result of converting nodes into a node given nodes and this’s node document. auto node = TRY(convert_nodes_to_single_node(nodes, document())); @@ -198,7 +198,7 @@ WebIDL::ExceptionOr ParentNode::prepend(Vector, Utf return {}; } -WebIDL::ExceptionOr ParentNode::append(Vector, Utf16String>> const& nodes) +WebIDL::ExceptionOr ParentNode::append(ReadonlySpan, Utf16String>> const& nodes) { // 1. Let node be the result of converting nodes into a node given nodes and this’s node document. auto node = TRY(convert_nodes_to_single_node(nodes, document())); @@ -209,7 +209,7 @@ WebIDL::ExceptionOr ParentNode::append(Vector, Utf1 return {}; } -WebIDL::ExceptionOr ParentNode::replace_children(Vector, Utf16String>> const& nodes) +WebIDL::ExceptionOr ParentNode::replace_children(ReadonlySpan, Utf16String>> const& nodes) { // 1. Let node be the result of converting nodes into a node given nodes and this’s node document. auto node = TRY(convert_nodes_to_single_node(nodes, document())); diff --git a/Libraries/LibWeb/DOM/ParentNode.h b/Libraries/LibWeb/DOM/ParentNode.h index cd8a66d984..c60992b9fe 100644 --- a/Libraries/LibWeb/DOM/ParentNode.h +++ b/Libraries/LibWeb/DOM/ParentNode.h @@ -33,9 +33,9 @@ public: GC::Ref get_elements_by_tag_name(FlyString const&); GC::Ref get_elements_by_tag_name_ns(Optional, FlyString const&); - WebIDL::ExceptionOr prepend(Vector, Utf16String>> const& nodes); - WebIDL::ExceptionOr append(Vector, Utf16String>> const& nodes); - WebIDL::ExceptionOr replace_children(Vector, Utf16String>> const& nodes); + WebIDL::ExceptionOr prepend(ReadonlySpan, Utf16String>> const& nodes); + WebIDL::ExceptionOr append(ReadonlySpan, Utf16String>> const& nodes); + WebIDL::ExceptionOr replace_children(ReadonlySpan, Utf16String>> const& nodes); WebIDL::ExceptionOr move_before(GC::Ref node, GC::Ptr child); GC::Ref get_elements_by_class_name(StringView); diff --git a/Libraries/LibWeb/DOMURL/DOMURL.cpp b/Libraries/LibWeb/DOMURL/DOMURL.cpp index 32b8224660..e427fbfe6e 100644 --- a/Libraries/LibWeb/DOMURL/DOMURL.cpp +++ b/Libraries/LibWeb/DOMURL/DOMURL.cpp @@ -467,13 +467,13 @@ Optional parse(StringView input, Optional base_url, O if (blob_url_entry.has_value()) { url->set_blob_url_entry(URL::BlobURLEntry { .object = blob_url_entry->object.visit( - [](GC::Root const& blob) -> URL::BlobURLEntry::Object { + [](GC::Ref const& blob) -> URL::BlobURLEntry::Object { return URL::BlobURLEntry::Blob { .type = blob->type(), .data = MUST(ByteBuffer::copy(blob->raw_bytes())), }; }, - [](GC::Root const&) -> URL::BlobURLEntry::Object { return URL::BlobURLEntry::MediaSource {}; }), + [](GC::Ref const&) -> URL::BlobURLEntry::Object { return URL::BlobURLEntry::MediaSource {}; }), .environment { .origin = blob_url_entry->environment->origin() }, }); } diff --git a/Libraries/LibWeb/Encoding/TextDecoder.cpp b/Libraries/LibWeb/Encoding/TextDecoder.cpp index 7cfaf42af9..ef39c3b307 100644 --- a/Libraries/LibWeb/Encoding/TextDecoder.cpp +++ b/Libraries/LibWeb/Encoding/TextDecoder.cpp @@ -63,13 +63,13 @@ void TextDecoder::initialize(JS::Realm& realm) } // https://encoding.spec.whatwg.org/#dom-textdecoder-decode -WebIDL::ExceptionOr TextDecoder::decode(Optional> const& input, Optional const&) const +WebIDL::ExceptionOr TextDecoder::decode(GC::Ptr input, Optional const&) const { - if (!input.has_value()) + if (!input) return TRY_OR_THROW_OOM(vm(), m_decoder.to_utf8({})); // FIXME: Implement the streaming stuff. - auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input.value()->raw_object()); + auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input->raw_object()); if (data_buffer_or_error.is_error()) return WebIDL::OperationError::create(realm(), "Failed to copy bytes from ArrayBuffer"_utf16); auto& data_buffer = data_buffer_or_error.value(); diff --git a/Libraries/LibWeb/Encoding/TextDecoder.h b/Libraries/LibWeb/Encoding/TextDecoder.h index 366479fc71..835b85ec03 100644 --- a/Libraries/LibWeb/Encoding/TextDecoder.h +++ b/Libraries/LibWeb/Encoding/TextDecoder.h @@ -30,7 +30,7 @@ public: virtual ~TextDecoder() override; - WebIDL::ExceptionOr decode(Optional> const&, Optional const& options = {}) const; + WebIDL::ExceptionOr decode(GC::Ptr, Optional const& options = {}) const; private: TextDecoder(JS::Realm&, TextCodec::Decoder&, FlyString encoding, ErrorMode error_mode, bool ignore_bom); diff --git a/Libraries/LibWeb/Fetch/Body.cpp b/Libraries/LibWeb/Fetch/Body.cpp index 7e91400677..b84be1e855 100644 --- a/Libraries/LibWeb/Fetch/Body.cpp +++ b/Libraries/LibWeb/Fetch/Body.cpp @@ -444,10 +444,11 @@ MultipartParsingErrorOr> parse_multip } // 3. Let value be a new File object with name filename, type contentType, and body body. - auto blob = FileAPI::Blob::create(realm, MUST(ByteBuffer::copy(body.bytes())), header.content_type.release_value()); + auto content_type = header.content_type.release_value(); + auto blob = FileAPI::Blob::create(realm, MUST(ByteBuffer::copy(body.bytes())), content_type); Bindings::FilePropertyBag options {}; - options.type = blob->type(); - value = MUST(FileAPI::File::create(realm, { GC::make_root(blob) }, header.filename.release_value(), move(options))); + options.type = move(content_type); + value = MUST(FileAPI::File::create(realm, { { blob } }, header.filename.release_value(), move(options))); } // 11. Otherwise: else { diff --git a/Libraries/LibWeb/Fetch/BodyInit.cpp b/Libraries/LibWeb/Fetch/BodyInit.cpp index ded9cf2823..f3b5eaf277 100644 --- a/Libraries/LibWeb/Fetch/BodyInit.cpp +++ b/Libraries/LibWeb/Fetch/BodyInit.cpp @@ -26,7 +26,7 @@ namespace Web::Fetch { Infrastructure::BodyWithType safely_extract_body(JS::Realm& realm, BodyInitOrReadableBytes const& object) { // 1. If object is a ReadableStream object, then: - if (auto const* stream = object.get_pointer>()) { + if (auto const* stream = object.get_pointer>()) { // 1. Assert: object is neither disturbed nor locked. VERIFY(!((*stream)->is_disturbed() || (*stream)->is_locked())); } @@ -46,12 +46,12 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, GC::Ptr stream; // 2. If object is a ReadableStream object, then set stream to object. - if (auto const* stream_handle = object.get_pointer>()) { - stream = const_cast(stream_handle->cell()); + if (auto const* maybe_stream = object.get_pointer>()) { + stream = *maybe_stream; } // 3. Otherwise, if object is a Blob object, set stream to the result of running object’s get stream. - else if (auto const* blob_handle = object.get_pointer>()) { - stream = blob_handle->cell()->get_stream(); + else if (auto* blob = object.get_pointer>()) { + stream = (*blob)->get_stream(); } // 4. Otherwise, set stream to a new ReadableStream object, and set up stream with byte reading support. else { @@ -76,7 +76,7 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, // 10. Switch on object. TRY(object.visit( - [&](GC::Root const& blob) -> WebIDL::ExceptionOr { + [&](GC::Ref blob) -> WebIDL::ExceptionOr { // Set source to object. source = blob; // Set length to object’s size. @@ -96,12 +96,12 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, source = bytes; return {}; }, - [&](GC::Root const& buffer_source) -> WebIDL::ExceptionOr { + [&](GC::Ref buffer_source) -> WebIDL::ExceptionOr { // Set source to a copy of the bytes held by object. source = MUST(WebIDL::get_buffer_source_copy(*buffer_source->raw_object())); return {}; }, - [&](GC::Root const& form_data) -> WebIDL::ExceptionOr { + [&](GC::Ref form_data) -> WebIDL::ExceptionOr { // Set action to this step: run the multipart/form-data encoding algorithm, with object’s entry list and UTF-8. auto serialized_form_data = MUST(HTML::serialize_to_multipart_form_data(form_data->entry_list())); // Set source to object. @@ -111,7 +111,7 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, type = ByteString::formatted("multipart/form-data; boundary={}", serialized_form_data.boundary); return {}; }, - [&](GC::Root const& url_search_params) -> WebIDL::ExceptionOr { + [&](GC::Ref url_search_params) -> WebIDL::ExceptionOr { // Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list. auto search_params_string = url_search_params->to_string(); source = MUST(ByteBuffer::copy(search_params_string.bytes())); @@ -127,7 +127,7 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, type = "text/plain;charset=UTF-8"sv; return {}; }, - [&](GC::Root const& stream) -> WebIDL::ExceptionOr { + [&](GC::Ref stream) -> WebIDL::ExceptionOr { // If keepalive is true, then throw a TypeError. if (keepalive) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Cannot extract body from stream when keepalive is set"sv }; diff --git a/Libraries/LibWeb/Fetch/BodyInit.h b/Libraries/LibWeb/Fetch/BodyInit.h index 6522c7df1d..6a195ddce2 100644 --- a/Libraries/LibWeb/Fetch/BodyInit.h +++ b/Libraries/LibWeb/Fetch/BodyInit.h @@ -16,10 +16,10 @@ namespace Web::Fetch { // https://fetch.spec.whatwg.org/#bodyinit -using BodyInit = Variant, GC::Root, GC::Root, GC::Root, GC::Root, String>; -using NullableBodyInit = Variant, GC::Root, GC::Root, GC::Root, GC::Root, String, Empty>; +using BodyInit = Variant, GC::Ref, GC::Ref, GC::Ref, GC::Ref, String>; +using NullableBodyInit = Variant, GC::Ref, GC::Ref, GC::Ref, GC::Ref, String, Empty>; -using BodyInitOrReadableBytes = Variant, GC::Root, GC::Root, GC::Root, GC::Root, String, ReadonlyBytes, Core::ImmutableBytes>; +using BodyInitOrReadableBytes = Variant, GC::Ref, GC::Ref, GC::Ref, GC::Ref, String, ReadonlyBytes, Core::ImmutableBytes>; WEB_API Infrastructure::BodyWithType safely_extract_body(JS::Realm&, BodyInitOrReadableBytes const&); WEB_API WebIDL::ExceptionOr extract_body(JS::Realm&, BodyInitOrReadableBytes const&, bool keepalive = false); diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index f12b7de190..eeefb0caee 100644 --- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -1546,7 +1546,7 @@ GC::Ptr http_redirect_fetch(JS::Realm& realm, Infrastructure::F auto converted_source = source.visit( [](ByteBuffer const& byte_buffer) -> BodyInitOrReadableBytes { return byte_buffer.bytes(); }, [](Core::ImmutableBytes const& bytes) -> BodyInitOrReadableBytes { return bytes; }, - [](GC::Ref const& blob) -> BodyInitOrReadableBytes { return GC::make_root(blob); }, + [](GC::Ref blob) -> BodyInitOrReadableBytes { return blob; }, [](Empty) -> BodyInitOrReadableBytes { VERIFY_NOT_REACHED(); }); auto [body, _] = safely_extract_body(realm, converted_source); request->set_body(body); @@ -2005,7 +2005,7 @@ GC::Ref http_network_or_cache_fetch(JS::Realm& realm, Infrastru auto converted_source = source.visit( [](ByteBuffer const& byte_buffer) -> BodyInitOrReadableBytes { return byte_buffer.bytes(); }, [](Core::ImmutableBytes const& bytes) -> BodyInitOrReadableBytes { return bytes; }, - [](GC::Ref const& blob) -> BodyInitOrReadableBytes { return GC::make_root(blob); }, + [](GC::Ref blob) -> BodyInitOrReadableBytes { return blob; }, [](Empty) -> BodyInitOrReadableBytes { VERIFY_NOT_REACHED(); }); auto [body, _] = safely_extract_body(realm, converted_source); request->set_body(body); diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp index d326c80e1e..a4d6650a6d 100644 --- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp +++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -19,26 +19,12 @@ namespace Web::Fetch::Infrastructure { GC_DEFINE_ALLOCATOR(Body); -static Body::SourceTypeInternal to_source_type_internal(Body::SourceType&& source_type) -{ - return source_type.visit( - [](Empty) -> Body::SourceTypeInternal { return Empty {}; }, - [](ByteBuffer& buffer) -> Body::SourceTypeInternal { return move(buffer); }, - [](Core::ImmutableBytes& bytes) -> Body::SourceTypeInternal { return move(bytes); }, - [](GC::Root const& blob) -> Body::SourceTypeInternal { return GC::Ref { *blob }; }); -} - GC::Ref Body::create(JS::VM& vm, GC::Ref stream) { return vm.heap().allocate(stream); } GC::Ref Body::create(JS::VM& vm, GC::Ref stream, SourceType source, Optional length) -{ - return create(vm, stream, to_source_type_internal(move(source)), length); -} - -GC::Ref Body::create(JS::VM& vm, GC::Ref stream, SourceTypeInternal source, Optional length) { return vm.heap().allocate(stream, source, length); } @@ -48,7 +34,7 @@ Body::Body(GC::Ref stream) { } -Body::Body(GC::Ref stream, SourceTypeInternal source, Optional length) +Body::Body(GC::Ref stream, SourceType source, Optional length) : m_stream(stream) , m_source(move(source)) , m_length(move(length)) diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h index 03feee59a2..04c6a177d1 100644 --- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h +++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h @@ -31,8 +31,7 @@ class WEB_API Body final : public JS::Cell { GC_DECLARE_ALLOCATOR(Body); public: - using SourceType = Variant>; - using SourceTypeInternal = Variant>; + using SourceType = Variant>; // processBody must be an algorithm accepting a byte sequence. using ProcessBodyCallback = GC::Ref>; // processBodyError must be an algorithm optionally accepting an exception. @@ -44,11 +43,10 @@ public: [[nodiscard]] static GC::Ref create(JS::VM&, GC::Ref); [[nodiscard]] static GC::Ref create(JS::VM&, GC::Ref, SourceType, Optional); - [[nodiscard]] static GC::Ref create(JS::VM&, GC::Ref, SourceTypeInternal, Optional); [[nodiscard]] GC::Ref stream() const { return *m_stream; } void set_stream(GC::Ref value) { m_stream = value; } - [[nodiscard]] SourceTypeInternal const& source() const { return m_source; } + [[nodiscard]] SourceType const& source() const { return m_source; } void set_source(Core::ImmutableBytes, Optional length); [[nodiscard]] Optional const& length() const { return m_length; } @@ -76,7 +74,7 @@ public: private: explicit Body(GC::Ref); - Body(GC::Ref, SourceTypeInternal, Optional); + Body(GC::Ref, SourceType, Optional); // https://fetch.spec.whatwg.org/#concept-body-stream // A stream (a ReadableStream object). @@ -84,7 +82,7 @@ private: // https://fetch.spec.whatwg.org/#concept-body-source // A source (null, a byte sequence, a Blob object, or a FormData object), initially null. - SourceTypeInternal m_source; + SourceType m_source; // https://fetch.spec.whatwg.org/#concept-body-total-bytes // A length (null or an integer), initially null. diff --git a/Libraries/LibWeb/Fetch/Request.cpp b/Libraries/LibWeb/Fetch/Request.cpp index e584295cad..3642cdf5fa 100644 --- a/Libraries/LibWeb/Fetch/Request.cpp +++ b/Libraries/LibWeb/Fetch/Request.cpp @@ -160,13 +160,13 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, // 6. Otherwise: else { // 1. Assert: input is a Request object. - VERIFY(input.has>()); + VERIFY(input.has>()); // 2. Set request to input’s request. - input_request = input.get>()->request(); + input_request = input.get>()->request(); // 3. Set signal to input’s signal. - input_signal = input.get>()->signal(); + input_signal = input.get>()->signal(); } // 7. Let origin be this’s relevant settings object’s origin. @@ -402,7 +402,7 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, // 26. If init["signal"] exists, then set signal to it. if (init.signal.has_value()) - input_signal = *init.signal; + input_signal = init.signal->ptr(); // 27. If init["priority"] exists, then: if (init.priority.has_value()) @@ -414,7 +414,7 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, // 29. Let signals be « signal » if signal is non-null; otherwise « ». auto& this_relevant_realm = HTML::relevant_realm(*request_object); - Vector> signals; + GC::RootVector> signals; if (input_signal != nullptr) signals.append(*input_signal); @@ -464,8 +464,8 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, // 34. Let inputBody be input’s request’s body if input is a Request object; otherwise null. Optional input_body; - if (input.has>()) - input_body = input.get>()->request()->body(); + if (input.has>()) + input_body = input.get>()->request()->body(); // 35. If either init["body"] exists and is non-null or inputBody is non-null, and request’s method is `GET` or `HEAD`, then throw a TypeError. if (((init.body.has_value() && !init.body->has()) || (input_body.has_value() && !input_body.value().has())) && request->method().is_one_of("GET"sv, "HEAD"sv)) @@ -477,7 +477,7 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, // 37. If init["body"] exists and is non-null, then: if (init.body.has_value() && !init.body->has()) { // 1. Let bodyWithType be the result of extracting init["body"], with keepalive set to request's keepalive. - auto body_with_type = TRY(extract_body(realm, init.body->downcast, GC::Root, GC::Root, GC::Root, GC::Root, String>(), request->keepalive())); + auto body_with_type = TRY(extract_body(realm, init.body->downcast, GC::Ref, GC::Ref, GC::Ref, GC::Ref, String>(), request->keepalive())); // 2. Set initBody to bodyWithType’s body. init_body = body_with_type.body; @@ -514,7 +514,7 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, // 41. If initBody is null and inputBody is non-null, then: if (!init_body.has_value() && input_body.has_value()) { // 2. If input is unusable, then throw a TypeError. - if (input.has>() && input.get>()->is_unusable()) + if (input.has>() && input.get>()->is_unusable()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Request is unusable"sv }; // FIXME: 2. Set finalBody to the result of creating a proxy for inputBody. @@ -671,7 +671,7 @@ WebIDL::ExceptionOr> Request::clone() const // 4. Let clonedSignal be the result of creating a dependent abort signal from « this’s signal », using AbortSignal and this’s relevant realm. auto& relevant_realm = HTML::relevant_realm(*this); - auto cloned_signal = TRY(DOM::AbortSignal::create_dependent_abort_signal(relevant_realm, { m_signal })); + auto cloned_signal = TRY(DOM::AbortSignal::create_dependent_abort_signal(relevant_realm, { { *m_signal } })); // 5. Let clonedRequestObject be the result of creating a Request object, given clonedRequest, this’s headers’s guard, clonedSignal and this’s relevant realm. auto cloned_request_object = Request::create(relevant_realm, cloned_request, m_headers->guard(), cloned_signal); diff --git a/Libraries/LibWeb/Fetch/Request.h b/Libraries/LibWeb/Fetch/Request.h index 7a6060f632..16512ea813 100644 --- a/Libraries/LibWeb/Fetch/Request.h +++ b/Libraries/LibWeb/Fetch/Request.h @@ -20,7 +20,7 @@ namespace Web::Fetch { // https://fetch.spec.whatwg.org/#requestinfo -using RequestInfo = Variant, String>; +using RequestInfo = Variant, String>; // https://fetch.spec.whatwg.org/#request class Request final diff --git a/Libraries/LibWeb/Fetch/Response.cpp b/Libraries/LibWeb/Fetch/Response.cpp index 9ad5c9aa22..96235fab14 100644 --- a/Libraries/LibWeb/Fetch/Response.cpp +++ b/Libraries/LibWeb/Fetch/Response.cpp @@ -156,7 +156,7 @@ WebIDL::ExceptionOr> Response::construct_impl(JS::Realm& realm // 4. If body is non-null, then set bodyWithType to the result of extracting body. if (!body.has()) - body_with_type = TRY(extract_body(realm, body.downcast, GC::Root, GC::Root, GC::Root, GC::Root, String>())); + body_with_type = TRY(extract_body(realm, body.downcast, GC::Ref, GC::Ref, GC::Ref, GC::Ref, String>())); // 5. Perform initialize a response given this, init, and bodyWithType. TRY(response_object->initialize_response(init, body_with_type)); diff --git a/Libraries/LibWeb/FileAPI/Blob.cpp b/Libraries/LibWeb/FileAPI/Blob.cpp index f20fef2ba2..9c0df642e0 100644 --- a/Libraries/LibWeb/FileAPI/Blob.cpp +++ b/Libraries/LibWeb/FileAPI/Blob.cpp @@ -107,12 +107,12 @@ ErrorOr process_blob_parts(BlobParts const& blob_parts, Optional const& buffer_source) -> ErrorOr { + [&](GC::Ref const& buffer_source) -> ErrorOr { auto data_buffer = TRY(WebIDL::get_buffer_source_copy(*buffer_source->raw_object())); return bytes.try_append(data_buffer.bytes()); }, // 3. If element is a Blob, append the bytes it represents to bytes. - [&](GC::Root const& blob) -> ErrorOr { + [&](GC::Ref const& blob) -> ErrorOr { return bytes.try_append(blob->raw_bytes()); })); } @@ -223,7 +223,9 @@ GC::Ref Blob::create(JS::Realm& realm, Optional con WebIDL::ExceptionOr> Blob::construct_impl(JS::Realm& realm, Optional const& blob_parts, Optional const& options) { - return create(realm, blob_parts.has_value() ? blob_parts.value() : Optional {}, options); + if (blob_parts.has_value()) + return create(realm, BlobPartsOrByteBuffer { blob_parts.value() }, options); + return create(realm, {}, options); } // https://w3c.github.io/FileAPI/#dfn-slice diff --git a/Libraries/LibWeb/FileAPI/Blob.h b/Libraries/LibWeb/FileAPI/Blob.h index f78a2fd120..b8d7e023d1 100644 --- a/Libraries/LibWeb/FileAPI/Blob.h +++ b/Libraries/LibWeb/FileAPI/Blob.h @@ -17,8 +17,8 @@ namespace Web::FileAPI { -using BlobPart = Variant, GC::Root, String>; -using BlobParts = Vector; +using BlobPart = Variant, GC::Ref, String>; +using BlobParts = GC::ConservativeVector; using BlobPartsOrByteBuffer = Variant; [[nodiscard]] ErrorOr convert_line_endings_to_native(StringView string); diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp index b3b1e14bfa..6eef516822 100644 --- a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp +++ b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp @@ -20,7 +20,7 @@ namespace Web::FileAPI { BlobURLStore& blob_url_store() { - static HashMap store; + static GC::ConservativeHashMap store; return store; } diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.h b/Libraries/LibWeb/FileAPI/BlobURLStore.h index 13a097f988..56043a4eec 100644 --- a/Libraries/LibWeb/FileAPI/BlobURLStore.h +++ b/Libraries/LibWeb/FileAPI/BlobURLStore.h @@ -6,8 +6,8 @@ #pragma once -#include #include +#include #include #include #include @@ -17,14 +17,14 @@ namespace Web::FileAPI { // https://w3c.github.io/FileAPI/#blob-url-entry struct BlobURLEntry { - using Object = Variant, GC::Root>; + using Object = Variant, GC::Ref>; Object object; - GC::Root environment; + GC::Ref environment; }; // https://w3c.github.io/FileAPI/#BlobURLStore -using BlobURLStore = HashMap; +using BlobURLStore = GC::ConservativeHashMap; BlobURLStore& blob_url_store(); ErrorOr generate_new_blob_url(); diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 13975f7d1e..992d0c15d6 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -485,7 +485,7 @@ struct StyleSheetIdentifier; struct TransitionProperties; // https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-cssnumberish -using CSSNumberish = Variant>; +using CSSNumberish = Variant>; using PaintOrderList = Array; using StyleValueVector = Vector>; using StyleValueTuple = Vector>; diff --git a/Libraries/LibWeb/HTML/BroadcastChannel.cpp b/Libraries/LibWeb/HTML/BroadcastChannel.cpp index 3f7b7c0667..c92b0c556d 100644 --- a/Libraries/LibWeb/HTML/BroadcastChannel.cpp +++ b/Libraries/LibWeb/HTML/BroadcastChannel.cpp @@ -11,12 +11,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -208,7 +210,7 @@ void BroadcastChannel::deliver_message_locally(BroadcastChannelMessage const& me // origin initialized to sourceOrigin, and then abort these steps. auto data_or_error = structured_deserialize(vm, message.serialized_message, target_realm); if (data_or_error.is_exception()) { - Bindings::MessageEventInit event_init {}; + Bindings::MessageEventInit event_init; auto event = MessageEvent::create(target_realm, HTML::EventNames::messageerror, event_init, message.source_origin); event->set_is_trusted(true); destination->dispatch_event(event); @@ -217,7 +219,7 @@ void BroadcastChannel::deliver_message_locally(BroadcastChannelMessage const& me // 4. Fire an event named message at destination, using MessageEvent, with the data attribute initialized to data and // its origin initialized to sourceOrigin. - Bindings::MessageEventInit event_init {}; + Bindings::MessageEventInit event_init; event_init.data = data_or_error.release_value(); auto event = MessageEvent::create(target_realm, HTML::EventNames::message, event_init, message.source_origin); event->set_is_trusted(true); diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp index 9e4ff186be..56b04037c1 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp +++ b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp @@ -16,36 +16,36 @@ namespace Web::HTML { Gfx::IntSize canvas_image_source_dimensions(CanvasImageSource const& image) { return image.visit( - [](GC::Root const& source) -> Gfx::IntSize { + [](GC::Ref source) -> Gfx::IntSize { if (auto frame = source->current_image_frame(); frame.has_value()) return frame->size(); // FIXME: This is very janky and not correct. return { source->width(), source->height() }; }, - [](GC::Root const& source) -> Gfx::IntSize { + [](GC::Ref source) -> Gfx::IntSize { if (auto decoded_image_frame = source->current_image_frame(); decoded_image_frame.has_value()) return decoded_image_frame->size(); // FIXME: This is very janky and not correct. return { source->width()->anim_val()->value(), source->height()->anim_val()->value() }; }, - [](GC::Root const& source) -> Gfx::IntSize { + [](GC::Ref source) -> Gfx::IntSize { if (auto painting_surface = source->surface()) return painting_surface->size(); return { source->width(), source->height() }; }, - [](GC::Root const& source) -> Gfx::IntSize { + [](GC::Ref source) -> Gfx::IntSize { if (auto* bitmap = source->bitmap()) return bitmap->size(); return { source->width(), source->height() }; }, - [](GC::Root const& source) -> Gfx::IntSize { + [](GC::Ref source) -> Gfx::IntSize { if (auto bitmap = source->bitmap()) return bitmap->size(); return {}; }, - [](GC::Root const& source) -> Gfx::IntSize { + [](GC::Ref source) -> Gfx::IntSize { return { source->video_width(), source->video_height() }; }); } @@ -53,7 +53,7 @@ Gfx::IntSize canvas_image_source_dimensions(CanvasImageSource const& image) Optional canvas_image_source_frame(CanvasImageSource const& image) { return image.visit( - [](OneOf, GC::Root> auto const& element) -> Optional { + [](OneOf, GC::Ref> auto const& element) -> Optional { auto image_data = element->decoded_image_data(); if (!image_data) return {}; @@ -66,20 +66,20 @@ Optional canvas_image_source_frame(CanvasImageSource con return image_data->frame(0, size); }, - [](GC::Root const& canvas) -> Optional { + [](GC::Ref const& canvas) -> Optional { canvas->present(); auto surface = canvas->surface(); if (!surface) return Gfx::DecodedImageFrame { *canvas->get_bitmap_from_surface() }; return Gfx::DecodedImageFrame { *surface->snapshot_bitmap() }; }, - [](OneOf, GC::Root> auto const& source) -> Optional { + [](OneOf, GC::Ref> auto const& source) -> Optional { auto bitmap = source->bitmap(); if (!bitmap) return {}; return Gfx::DecodedImageFrame { *bitmap }; }, - [](GC::Root const& source) -> Optional { + [](GC::Ref const& source) -> Optional { return source->current_decoded_image_frame(); }); } diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h index d13df75a98..8a897abfc6 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h +++ b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h @@ -22,7 +22,7 @@ namespace Web::HTML { // https://html.spec.whatwg.org/multipage/canvas.html#canvasimagesource // NOTE: This is the Variant created by the IDL wrapper generator, and needs to be updated accordingly. -using CanvasImageSource = Variant, GC::Root, GC::Root, GC::Root, GC::Root, GC::Root>; +using CanvasImageSource = Variant, GC::Ref, GC::Ref, GC::Ref, GC::Ref, GC::Ref>; Gfx::IntSize canvas_image_source_dimensions(CanvasImageSource const&); Optional canvas_image_source_frame(CanvasImageSource const&); diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h b/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h index 2d37f4f995..3a94a7ff12 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h +++ b/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h @@ -19,7 +19,7 @@ template class CanvasFillStrokeStyles { public: ~CanvasFillStrokeStyles() = default; - using FillOrStrokeStyleVariant = Variant, GC::Root>; + using FillOrStrokeStyleVariant = Variant, GC::Ref>; void set_fill_style(FillOrStrokeStyleVariant style); FillOrStrokeStyleVariant fill_style() const; diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasState.h b/Libraries/LibWeb/HTML/Canvas/CanvasState.h index af27552cb7..41ac40087f 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasState.h +++ b/Libraries/LibWeb/HTML/Canvas/CanvasState.h @@ -59,7 +59,7 @@ public: Optional as_color() const; Gfx::Color to_color_but_fixme_should_accept_any_paint_style() const; - using JsFillOrStrokeStyle = Variant, GC::Root>; + using JsFillOrStrokeStyle = Variant, GC::Ref>; JsFillOrStrokeStyle to_js_fill_or_stroke_style() const { @@ -68,7 +68,7 @@ public: return color.to_string(Gfx::Color::HTMLCompatibleSerialization::Yes); }, [&](auto handle) -> JsFillOrStrokeStyle { - return GC::make_root(handle); + return handle; }); } diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index 0d04b9a8ea..f60a2e18f1 100644 --- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -911,7 +911,7 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI // 1. Switch on image: auto usability = TRY(image.visit( // HTMLOrSVGImageElement - [](GC::Root const& image_element) -> WebIDL::ExceptionOr> { + [](GC::Ref image_element) -> WebIDL::ExceptionOr> { // If image's current request's state is broken, then throw an "InvalidStateError" DOMException. if (image_element->current_request().state() == HTML::ImageRequest::State::Broken) return WebIDL::InvalidStateError::create(image_element->realm(), "Image element state is broken"_utf16); @@ -927,7 +927,7 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI return Optional {}; }, // FIXME: Don't duplicate this for HTMLImageElement and SVGImageElement. - [](GC::Root const& image_element) -> WebIDL::ExceptionOr> { + [](GC::Ref image_element) -> WebIDL::ExceptionOr> { // FIXME: If image's current request's state is broken, then throw an "InvalidStateError" DOMException. // If image is not fully decodable, then return bad. @@ -941,7 +941,7 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI return Optional {}; }, - [](GC::Root const& video_element) -> WebIDL::ExceptionOr> { + [](GC::Ref video_element) -> WebIDL::ExceptionOr> { // If image's readyState attribute is either HAVE_NOTHING or HAVE_METADATA, then return bad. if (video_element->ready_state() == HTML::HTMLMediaElement::ReadyState::HaveNothing || video_element->ready_state() == HTML::HTMLMediaElement::ReadyState::HaveMetadata) { return { CanvasImageSourceUsability::Bad }; @@ -950,14 +950,14 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI }, // OffscreenCanvas - [](GC::Root const& offscreen_canvas) -> WebIDL::ExceptionOr> { + [](GC::Ref offscreen_canvas) -> WebIDL::ExceptionOr> { // If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException. if (offscreen_canvas->width() == 0 || offscreen_canvas->height() == 0) return WebIDL::InvalidStateError::create(offscreen_canvas->realm(), "OffscreenCanvas width or height is zero"_utf16); return Optional {}; }, // HTMLCanvasElement - [](GC::Root const& canvas_element) -> WebIDL::ExceptionOr> { + [](GC::Ref canvas_element) -> WebIDL::ExceptionOr> { // If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException. if (canvas_element->width() == 0 || canvas_element->height() == 0) return WebIDL::InvalidStateError::create(canvas_element->realm(), "Canvas width or height is zero"_utf16); @@ -966,7 +966,7 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI // ImageBitmap // FIXME: VideoFrame - [](GC::Root const& image_bitmap) -> WebIDL::ExceptionOr> { + [](GC::Ref image_bitmap) -> WebIDL::ExceptionOr> { if (image_bitmap->is_detached()) return WebIDL::InvalidStateError::create(image_bitmap->realm(), "Image bitmap is detached"_utf16); return Optional {}; @@ -984,20 +984,20 @@ bool image_is_not_origin_clean(CanvasImageSource const& image) // An object image is not origin-clean if, switching on image's type: return image.visit( // HTMLOrSVGImageElement - [](GC::Root const&) { + [](GC::Ref) { // FIXME: image's current request's image data is CORS-cross-origin. return false; }, - [](GC::Root const&) { + [](GC::Ref) { // FIXME: image's current request's image data is CORS-cross-origin. return false; }, - [](GC::Root const&) { + [](GC::Ref) { // FIXME: image's media data is CORS-cross-origin. return false; }, // HTMLCanvasElement, ImageBitmap or OffscreenCanvas - [](OneOf, GC::Root, GC::Root> auto const&) { + [](OneOf, GC::Ref, GC::Ref> auto const&) { // FIXME: image's bitmap's origin-clean flag is false. return false; }); diff --git a/Libraries/LibWeb/HTML/CloseWatcher.cpp b/Libraries/LibWeb/HTML/CloseWatcher.cpp index d448202298..ccf4225b37 100644 --- a/Libraries/LibWeb/HTML/CloseWatcher.cpp +++ b/Libraries/LibWeb/HTML/CloseWatcher.cpp @@ -69,9 +69,7 @@ WebIDL::ExceptionOr> CloseWatcher::construct_impl(JS::Real auto close_watcher = establish(window, GC::create_function(realm.heap(), [] { return true; })); // 3. If options["signal"] exists, then: - if (options.signal.has_value()) { - auto signal = options.signal->ptr(); - + if (auto signal = options.signal) { // 3.1 If options["signal"]'s aborted, then destroy closeWatcher. if (signal->aborted()) { close_watcher->destroy(); diff --git a/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp b/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp index 436f978542..0c4d69ec18 100644 --- a/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp +++ b/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp @@ -330,7 +330,7 @@ JS::ThrowCompletionOr CustomElementRegistry::define(String const& name, We } // https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-get -Variant, Empty> CustomElementRegistry::get(String const& name) const +Variant, Empty> CustomElementRegistry::get(String const& name) const { // 1. If this's custom element definition set contains an item with name name, then return that item's constructor. auto existing_definition_iterator = m_custom_element_definitions.find_if([&name](auto const& definition) { @@ -338,18 +338,18 @@ Variant, Empty> CustomElementRegistry::get(String }); if (!existing_definition_iterator.is_end()) - return GC::make_root((*existing_definition_iterator)->constructor()); + return GC::Ref { (*existing_definition_iterator)->constructor() }; // 2. Return undefined. return Empty {}; } // https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-getname -Optional CustomElementRegistry::get_name(GC::Root const& constructor) const +Optional CustomElementRegistry::get_name(GC::Ref constructor) const { // 1. If this's custom element definition set contains an item with constructor constructor, then return that item's name. auto existing_definition_iterator = m_custom_element_definitions.find_if([&constructor](auto const& definition) { - return definition->constructor().callback == constructor.cell()->callback; + return definition->constructor().callback == constructor->callback; }); if (!existing_definition_iterator.is_end()) diff --git a/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h b/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h index f5d08a7f13..e92593f022 100644 --- a/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h +++ b/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.h @@ -25,8 +25,8 @@ public: virtual ~CustomElementRegistry() override; JS::ThrowCompletionOr define(String const& name, WebIDL::CallbackType* constructor, Bindings::ElementDefinitionOptions const&); - Variant, Empty> get(String const& name) const; - Optional get_name(GC::Root const& constructor) const; + Variant, Empty> get(String const& name) const; + Optional get_name(GC::Ref constructor) const; WebIDL::ExceptionOr> when_defined(String const& name); void upgrade(GC::Ref root) const; WebIDL::ExceptionOr initialize_for_bindings(GC::Ref root); diff --git a/Libraries/LibWeb/HTML/DataTransfer.cpp b/Libraries/LibWeb/HTML/DataTransfer.cpp index af184cbcec..ac0e74d592 100644 --- a/Libraries/LibWeb/HTML/DataTransfer.cpp +++ b/Libraries/LibWeb/HTML/DataTransfer.cpp @@ -255,7 +255,7 @@ GC::Ref DataTransfer::files() const Bindings::FilePropertyBag options {}; options.type = item.type_string; - auto file = MUST(FileAPI::File::create(realm, { GC::make_root(blob) }, file_name, move(options))); + auto file = MUST(FileAPI::File::create(realm, { { blob } }, file_name, move(options))); files->add_file(file); } diff --git a/Libraries/LibWeb/HTML/DataTransferItem.cpp b/Libraries/LibWeb/HTML/DataTransferItem.cpp index 59f3175e8a..066379e517 100644 --- a/Libraries/LibWeb/HTML/DataTransferItem.cpp +++ b/Libraries/LibWeb/HTML/DataTransferItem.cpp @@ -146,7 +146,9 @@ GC::Ptr DataTransferItem::get_as_file() const Bindings::FilePropertyBag options {}; options.type = item.type_string; - return MUST(FileAPI::File::create(realm, { GC::make_root(blob) }, file_name, move(options))); + FileAPI::BlobParts file_bits {}; + file_bits.append(blob); + return MUST(FileAPI::File::create(realm, file_bits, file_name, move(options))); } // https://wicg.github.io/entries-api/#dom-datatransferitem-webkitgetasentry diff --git a/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.cpp index 3d5af9bd3e..139b0c611c 100644 --- a/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.cpp +++ b/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.cpp @@ -58,7 +58,7 @@ WebIDL::ExceptionOr DedicatedWorkerGlobalScope::post_message(JS::Value mes } // https://html.spec.whatwg.org/multipage/workers.html#dom-dedicatedworkerglobalscope-postmessage -WebIDL::ExceptionOr DedicatedWorkerGlobalScope::post_message(JS::Value message, Vector> const& transfer) +WebIDL::ExceptionOr DedicatedWorkerGlobalScope::post_message(JS::Value message, GC::RootVector> const& transfer) { // The postMessage(message, transfer) and postMessage(message, options) methods on DedicatedWorkerGlobalScope objects act as if, // when invoked, it immediately invoked the respective postMessage(message, transfer) and postMessage(message, options) diff --git a/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.h b/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.h index 6e7de1fbab..7e88db56d4 100644 --- a/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.h +++ b/Libraries/LibWeb/HTML/DedicatedWorkerGlobalScope.h @@ -25,7 +25,7 @@ public: virtual ~DedicatedWorkerGlobalScope() override; WebIDL::ExceptionOr post_message(JS::Value message, Bindings::StructuredSerializeOptions const&); - WebIDL::ExceptionOr post_message(JS::Value message, Vector> const& transfer); + WebIDL::ExceptionOr post_message(JS::Value message, GC::RootVector> const& transfer); void close(); diff --git a/Libraries/LibWeb/HTML/ElementInternals.cpp b/Libraries/LibWeb/HTML/ElementInternals.cpp index a542793ce3..641c608eab 100644 --- a/Libraries/LibWeb/HTML/ElementInternals.cpp +++ b/Libraries/LibWeb/HTML/ElementInternals.cpp @@ -60,13 +60,13 @@ WebIDL::ExceptionOr ElementInternals::set_form_value(ElementInternalsFormV // 3. Set target element's submission value to value if value is not a FormData object, or to a clone of value's entry list otherwise. auto submission_value = value.visit( - [](GC::Root const& file) -> FormAssociatedElement::FACESubmissionValue { - return GC::Ref { *file }; + [](GC::Ref file) -> FormAssociatedElement::FACESubmissionValue { + return file; }, [](String const& string) -> FormAssociatedElement::FACESubmissionValue { return string; }, - [](GC::Root const& form_data) -> FormAssociatedElement::FACESubmissionValue { + [](GC::Ref form_data) -> FormAssociatedElement::FACESubmissionValue { return form_data->entry_list(); }, [](Empty const& empty) -> FormAssociatedElement::FACESubmissionValue { diff --git a/Libraries/LibWeb/HTML/ElementInternals.h b/Libraries/LibWeb/HTML/ElementInternals.h index ca68e3c921..84e2f0715b 100644 --- a/Libraries/LibWeb/HTML/ElementInternals.h +++ b/Libraries/LibWeb/HTML/ElementInternals.h @@ -27,7 +27,7 @@ public: GC::Ptr shadow_root() const; - using ElementInternalsFormValue = Variant, String, GC::Root, Empty>; + using ElementInternalsFormValue = Variant, String, GC::Ref, Empty>; WebIDL::ExceptionOr set_form_value(ElementInternalsFormValue value, Optional state); WebIDL::ExceptionOr> form() const; diff --git a/Libraries/LibWeb/HTML/EventSource.cpp b/Libraries/LibWeb/HTML/EventSource.cpp index 63ad814330..2aaa2976be 100644 --- a/Libraries/LibWeb/HTML/EventSource.cpp +++ b/Libraries/LibWeb/HTML/EventSource.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -442,7 +444,7 @@ void EventSource::dispatch_the_event() // the event source. // 6. If the event type buffer has a value other than the empty string, change the type of the newly created event to equal // the value of the event type buffer. - Bindings::MessageEventInit init {}; + Bindings::MessageEventInit init; init.data = JS::PrimitiveString::create(vm(), data_buffer); init.last_event_id = last_event_id; diff --git a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp index 00835b4bf1..8114867618 100644 --- a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp +++ b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp @@ -39,7 +39,7 @@ WebIDL::ExceptionOr create_entry(JS::Realm& realm, String co Bindings::FilePropertyBag options {}; options.type = blob->type(); - blob = TRY(FileAPI::File::create(realm, { GC::make_root(*blob) }, "blob"_string, move(options))); + blob = TRY(FileAPI::File::create(realm, { { blob } }, "blob"_string, move(options))); } // 2. If filename is given, then set value to a new File object, representing the same bytes, whose name @@ -49,7 +49,7 @@ WebIDL::ExceptionOr create_entry(JS::Realm& realm, String co options.type = blob->type(); options.last_modified = as(*blob).last_modified(); - blob = TRY(FileAPI::File::create(realm, { GC::make_root(*blob) }, *filename, move(options))); + blob = TRY(FileAPI::File::create(realm, { { blob } }, *filename, move(options))); } return GC::Ref { as(*blob) }; @@ -249,8 +249,7 @@ WebIDL::ExceptionOr>> constr auto form_data = TRY(XHR::FormData::construct_impl(realm, move(entry_list))); // 7. Fire an event named formdata at form using FormDataEvent, with the formData attribute initialized to form data and the bubbles attribute initialized to true. - Bindings::FormDataEventInit init {}; - init.form_data = form_data; + Bindings::FormDataEventInit init { Bindings::EventInit {}, form_data }; auto form_data_event = TRY(FormDataEvent::construct_impl(realm, HTML::EventNames::formdata, init)); form_data_event->set_bubbles(true); form.dispatch_event(form_data_event); diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 8b68f1d2cf..c0a3848b3a 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -288,7 +288,7 @@ JS::ThrowCompletionOr HTMLCanvasElement::ge // NOTE: See the spec for the full table. if (type == "2d"sv) { if (TRY(create_2d_context(options)) == HasOrCreatedContext::Yes) - return GC::make_root(*m_context.get>()); + return m_context.get>(); return Empty {}; } @@ -296,14 +296,14 @@ JS::ThrowCompletionOr HTMLCanvasElement::ge // NOTE: The WebGL spec says "experimental-webgl" is also acceptable and must be equivalent to "webgl". Other engines accept this, so we do too. if (type.is_one_of("webgl"sv, "experimental-webgl"sv)) { if (TRY(create_webgl_context(options)) == HasOrCreatedContext::Yes) - return GC::make_root(*m_context.get>()); + return m_context.get>(); return Empty {}; } if (type == "webgl2"sv) { if (TRY(create_webgl_context(options)) == HasOrCreatedContext::Yes) - return GC::make_root(*m_context.get>()); + return m_context.get>(); return Empty {}; } @@ -331,7 +331,7 @@ Gfx::IntSize HTMLCanvasElement::bitmap_size_for_canvas(size_t minimum_width, siz } // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-todataurl -String HTMLCanvasElement::to_data_url(StringView type, JS::Value js_quality) +String HTMLCanvasElement::to_data_url(StringView type, Optional js_quality) { // It is possible the canvas doesn't have an associated bitmap so create one allocate_painting_surface_if_needed(); @@ -351,7 +351,7 @@ String HTMLCanvasElement::to_data_url(StringView type, JS::Value js_quality) // 3. Let file be a serialization of this canvas element's bitmap as a file, passing type and quality if given. auto bitmap = surface->snapshot_bitmap(); - Optional quality = js_quality.is_number() ? js_quality.as_double() : Optional(); + Optional quality = js_quality.has_value() && js_quality->is_number() ? js_quality->as_double() : Optional(); auto file = serialize_bitmap(bitmap, type, quality); // 4. If file is null, then return "data:,". @@ -369,7 +369,7 @@ String HTMLCanvasElement::to_data_url(StringView type, JS::Value js_quality) } // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob -WebIDL::ExceptionOr HTMLCanvasElement::to_blob(GC::Ref callback, StringView type, JS::Value js_quality) +WebIDL::ExceptionOr HTMLCanvasElement::to_blob(GC::Ref callback, StringView type, Optional js_quality) { // FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException. @@ -378,7 +378,7 @@ WebIDL::ExceptionOr HTMLCanvasElement::to_blob(GC::Ref quality = js_quality.is_number() ? js_quality.as_double() : Optional(); + Optional quality = js_quality.has_value() && js_quality->is_number() ? js_quality->as_double() : Optional(); // 4. Run these steps in parallel: Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(heap(), [this, callback, bitmap_result, type, quality] { diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.h b/Libraries/LibWeb/HTML/HTMLCanvasElement.h index 63d614a12f..6d06d100d3 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.h +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.h @@ -22,7 +22,7 @@ class HTMLCanvasElement final : public HTMLElement { public: static constexpr bool OVERRIDES_FINALIZE = true; - using RenderingContext = Variant, GC::Root, GC::Root, Empty>; + using RenderingContext = Variant, GC::Ref, GC::Ref, Empty>; virtual ~HTMLCanvasElement() override; @@ -43,8 +43,8 @@ public: virtual void attribute_changed(FlyString const& local_name, Optional const& old_value, Optional const& value, Optional const& namespace_) override; - String to_data_url(StringView type, JS::Value quality); - WebIDL::ExceptionOr to_blob(GC::Ref callback, StringView type, JS::Value quality); + String to_data_url(StringView type, Optional quality); + WebIDL::ExceptionOr to_blob(GC::Ref callback, StringView type, Optional quality); RefPtr get_bitmap_from_surface(); void present(); diff --git a/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp b/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp index cb25565c92..4522253664 100644 --- a/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp @@ -272,12 +272,12 @@ void HTMLDetailsElement::update_shadow_tree_slots() if (!shadow_root()) return; - Vector summary_assignment; - Vector descendants_assignment; + GC::ConservativeVector summary_assignment; + GC::ConservativeVector descendants_assignment; auto* summary = first_child_of_type(); if (summary != nullptr) - summary_assignment.append(GC::make_root(static_cast(*summary))); + summary_assignment.append(GC::Ref { static_cast(*summary) }); for_each_in_subtree([&](auto& child) { if (&child == summary) @@ -286,7 +286,7 @@ void HTMLDetailsElement::update_shadow_tree_slots() return TraversalDecision::Continue; child.as_slottable().visit([&](auto& node) { - descendants_assignment.append(GC::make_root(node)); + descendants_assignment.append(node); }); return TraversalDecision::Continue; diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp index f239e60ec0..69001108ee 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -1205,7 +1206,7 @@ WebIDL::ExceptionOr HTMLElement::check_popover_validity(ExpectedToBeShowin WebIDL::ExceptionOr HTMLElement::show_popover_for_bindings(Bindings::ShowPopoverOptions const& options) { // 1. Let source be options["source"] if it exists; otherwise, null. - auto source = options.source.has_value() ? GC::Ptr { options.source->ptr() } : GC::Ptr {}; + auto source = GC::Ptr { options.source }; // 2. Run show popover given this, true, and source. return show_popover(ThrowExceptions::Yes, source); } @@ -1579,8 +1580,7 @@ WebIDL::ExceptionOr HTMLElement::toggle_popover(TogglePopoverOptionsOrForc // 3. Otherwise, if options["force"] exists, set force to options["force"]. force = options.force; // 4. Let source be options["source"] if it exists; otherwise, null. - if (options.source.has_value()) - source = options.source->ptr(); + source = options.source; }); // 5. If this's popover visibility state is showing, and force is null or false, then run the hide popover algorithm given this, true, true, true, false, and null. diff --git a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp index 6c00b66c82..937b16a28f 100644 --- a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp +++ b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp @@ -35,7 +35,7 @@ void HTMLFormControlsCollection::initialize(JS::Realm& realm) } // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmlformcontrolscollection-nameditem -Variant> HTMLFormControlsCollection::named_item_or_radio_node_list(FlyString const& name) const +Variant, GC::Ref> HTMLFormControlsCollection::named_item_or_radio_node_list(FlyString const& name) const { // 1. If name is the empty string, return null and stop the algorithm. if (name.is_empty()) @@ -63,18 +63,18 @@ Variant> HTMLFormControlsCollectio return {}; if (!multiple_matching) - return matching_element; + return GC::Ref { *matching_element }; // 4. Otherwise, create a new RadioNodeList object representing a live view of the HTMLFormControlsCollection object, further filtered so that the only nodes in the // RadioNodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the RadioNodeList object must be sorted in tree // order. Return that RadioNodeList object. - return GC::make_root(RadioNodeList::create(realm(), root(), DOM::LiveNodeList::Scope::Descendants, [name](auto const& node) { + return RadioNodeList::create(realm(), root(), DOM::LiveNodeList::Scope::Descendants, [name](auto const& node) { if (!is(node)) return false; auto const& element = as(node); return element.id() == name || element.name() == name; - })); + }); } JS::Value HTMLFormControlsCollection::named_item_value(FlyString const& name) const diff --git a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h index a2cf756e3c..38981215d9 100644 --- a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h +++ b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h @@ -19,7 +19,7 @@ public: virtual ~HTMLFormControlsCollection() override; - Variant> named_item_or_radio_node_list(FlyString const& name) const; + Variant, GC::Ref> named_item_or_radio_node_list(FlyString const& name) const; protected: virtual void initialize(JS::Realm&) override; diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 69be8c3f36..28d5a47e77 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -642,7 +642,7 @@ void HTMLInputElement::did_select_files(Span selected_files, Multi Bindings::FilePropertyBag options {}; options.type = mime_type.essence(); - auto file = MUST(FileAPI::File::create(realm(), { GC::make_root(blob) }, file_name, move(options))); + auto file = MUST(FileAPI::File::create(realm(), { { blob } }, file_name, move(options))); files->add_file(file); } @@ -2958,22 +2958,22 @@ JS::Object* HTMLInputElement::value_as_date() const } // https://html.spec.whatwg.org/multipage/input.html#dom-input-valueasdate -WebIDL::ExceptionOr HTMLInputElement::set_value_as_date(Optional> const& value) +WebIDL::ExceptionOr HTMLInputElement::set_value_as_date(GC::Ptr value) { // On setting, if the valueAsDate attribute does not apply, as defined for the input element's type attribute's current state, then throw an "InvalidStateError" DOMException; if (!value_as_date_applies()) return WebIDL::InvalidStateError::create(realm(), "valueAsDate: Invalid input type used"_utf16); // otherwise, if the new value is not null and not a Date object throw a TypeError exception; - if (value.has_value() && !is(**value)) + if (value && !is(*value)) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "valueAsDate: input is not a Date"sv }; // otherwise if the new value is null or a Date object representing the NaN time value, then set the value of the element to the empty string; - if (!value.has_value()) { + if (!value) { TRY(set_value({})); return {}; } - auto& date = static_cast(**value); + auto& date = static_cast(*value); if (!isfinite(date.date_value())) { TRY(set_value({})); return {}; diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h index d3af6785af..d22914e778 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -153,7 +153,7 @@ public: SelectedCoordinate selected_coordinate() const { return m_selected_coordinate; } JS::Object* value_as_date() const; - WebIDL::ExceptionOr set_value_as_date(Optional> const&); + WebIDL::ExceptionOr set_value_as_date(GC::Ptr); double value_as_number() const; WebIDL::ExceptionOr set_value_as_number(double value); diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index bf31cef900..93286e4efa 100644 --- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -206,32 +206,14 @@ OptionalMediaProvider HTMLMediaElement::src_object() const { // The srcObject IDL attribute, on getting, must return the element's assigned media provider // object, if any, or null otherwise. - return assigned_media_provider_object().visit( - [](Empty) -> OptionalMediaProvider { - return Empty(); - }, - [](GC::Ref blob) -> OptionalMediaProvider { - return { GC::Root(blob) }; - }, - [](GC::Ref media_source) -> OptionalMediaProvider { - return { GC::Root(media_source) }; - }); + return assigned_media_provider_object(); } // https://html.spec.whatwg.org/multipage/media.html#dom-media-srcobject WebIDL::ExceptionOr HTMLMediaElement::set_src_object(OptionalMediaProvider src_object) { // On setting, it must set the element's assigned media provider object to the new value, - set_assigned_media_provider_object(src_object.visit( - [](Empty) -> MediaProviderObject { - return Empty(); - }, - [](GC::Root const& blob) -> MediaProviderObject { - return GC::Ref(*blob); - }, - [](GC::Root const& media_source) -> MediaProviderObject { - return GC::Ref(*media_source); - })); + set_assigned_media_provider_object(src_object); // and then invoke the element's media element load algorithm. return load_element(); @@ -689,7 +671,7 @@ GC::Ref HTMLMediaElement::add_text_track(Bindings::TextTrackKind kind // text track's TextTrack object. queue_a_media_element_task([this, text_track] { Bindings::TrackEventInit event_init {}; - event_init.track = GC::Root { text_track }; + event_init.track = text_track; auto event = TrackEvent::create(this->realm(), HTML::EventNames::addtrack, move(event_init)); m_text_tracks->dispatch_event(event); @@ -1187,7 +1169,7 @@ void HTMLMediaElement::load_url_resource(URL::URL const& url_record, Function>()), move(failure_callback)); + load_local_resource(blob_entry.object.get>(), move(failure_callback)); return; } } @@ -1676,7 +1658,7 @@ void HTMLMediaElement::on_audio_track_added(Media::Track const& track) // 7. Fire an event named addtrack at this AudioTrackList object, using TrackEvent, with the track attribute initialized to the new AudioTrack object. Bindings::TrackEventInit event_init {}; - event_init.track = GC::make_root(audio_track); + event_init.track = audio_track; auto event = TrackEvent::create(realm, EventNames::addtrack, move(event_init)); m_audio_tracks->dispatch_event(event); @@ -1719,7 +1701,7 @@ void HTMLMediaElement::on_video_track_added(Media::Track const& track) // 7. Fire an event named addtrack at this VideoTrackList object, using TrackEvent, with the track attribute initialized to the new VideoTrack object. Bindings::TrackEventInit event_init {}; - event_init.track = GC::make_root(video_track); + event_init.track = video_track; auto event = TrackEvent::create(realm, HTML::EventNames::addtrack, move(event_init)); m_video_tracks->dispatch_event(event); diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.h index 12db1b8b65..40bc4dc37c 100644 --- a/Libraries/LibWeb/HTML/HTMLMediaElement.h +++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h @@ -35,7 +35,7 @@ enum class MediaSeekMode : u8 { class SourceElementSelector; -using OptionalMediaProvider = Variant, GC::Root>; +using OptionalMediaProvider = Variant, GC::Ref>; class HTMLMediaElement : public HTMLElement { WEB_PLATFORM_OBJECT(HTMLMediaElement, HTMLElement); diff --git a/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp b/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp index e89e5384c9..a30bcb489d 100644 --- a/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp +++ b/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp @@ -122,13 +122,13 @@ WebIDL::ExceptionOr HTMLOptionsCollection::set_value_of_indexed_property(u WebIDL::ExceptionOr HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement element, NullableHTMLElementOrElementIndex before) { auto resolved_element = element.visit( - [](auto& e) -> GC::Root { - return GC::make_root(static_cast(*e)); + [](auto& e) -> GC::Ref { + return static_cast(*e); }); GC::Ptr before_element; - if (before.has>()) - before_element = before.get>().ptr(); + if (before.has>()) + before_element = before.get>().ptr(); // 1. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a "HierarchyRequestError" DOMException. if (resolved_element->is_ancestor_of(root())) diff --git a/Libraries/LibWeb/HTML/HTMLOptionsCollection.h b/Libraries/LibWeb/HTML/HTMLOptionsCollection.h index 769f4203a4..82c45e258b 100644 --- a/Libraries/LibWeb/HTML/HTMLOptionsCollection.h +++ b/Libraries/LibWeb/HTML/HTMLOptionsCollection.h @@ -13,9 +13,9 @@ namespace Web::HTML { -using HTMLOptionOrOptGroupElement = Variant, GC::Root>; -using HTMLElementOrElementIndex = Variant, i32>; -using NullableHTMLElementOrElementIndex = Variant, i32, Empty>; +using HTMLOptionOrOptGroupElement = Variant, GC::Ref>; +using HTMLElementOrElementIndex = Variant, i32>; +using NullableHTMLElementOrElementIndex = Variant, i32, Empty>; class HTMLOptionsCollection final : public DOM::HTMLCollection { WEB_PLATFORM_OBJECT(HTMLOptionsCollection, DOM::HTMLCollection); diff --git a/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index d3e8cbcd40..0bd436e8c0 100644 --- a/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -764,7 +764,7 @@ WebIDL::ExceptionOr HTMLScriptElement::set_src(TrustedTypes::TrustedScript } // https://w3c.github.io/trusted-types/dist/spec/#the-textContent-idl-attribute -Variant, Utf16String, Empty> HTMLScriptElement::text_content() const +Variant, Utf16String, Empty> HTMLScriptElement::text_content() const { // 1. Return the result of running get text content with this. return descendant_text_content(); diff --git a/Libraries/LibWeb/HTML/HTMLScriptElement.h b/Libraries/LibWeb/HTML/HTMLScriptElement.h index 2f77dccc88..86711f2e8e 100644 --- a/Libraries/LibWeb/HTML/HTMLScriptElement.h +++ b/Libraries/LibWeb/HTML/HTMLScriptElement.h @@ -65,7 +65,7 @@ public: TrustedTypes::TrustedScriptURLOrString src() const; WebIDL::ExceptionOr set_src(TrustedTypes::TrustedScriptURLOrString); - Variant, Utf16String, Empty> text_content() const; + Variant, Utf16String, Empty> text_content() const; WebIDL::ExceptionOr set_text_content(TrustedTypes::NullableTrustedScriptOrString); TrustedTypes::TrustedScriptOrString inner_text(); diff --git a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp b/Libraries/LibWeb/HTML/HTMLSlotElement.cpp index 09a10516f2..efdc8d05a9 100644 --- a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLSlotElement.cpp @@ -93,7 +93,7 @@ Vector> HTMLSlotElement::assigned_elements(Bindings::Assi } // https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assign -void HTMLSlotElement::assign(Vector nodes) +void HTMLSlotElement::assign(GC::ConservativeVector nodes) { // 1. For each node of this's manually assigned nodes, set node's manual slot assignment to null. for (auto& node : m_manually_assigned_nodes) { diff --git a/Libraries/LibWeb/HTML/HTMLSlotElement.h b/Libraries/LibWeb/HTML/HTMLSlotElement.h index 61c3c3cee5..29272cc155 100644 --- a/Libraries/LibWeb/HTML/HTMLSlotElement.h +++ b/Libraries/LibWeb/HTML/HTMLSlotElement.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -29,8 +30,8 @@ public: Vector> assigned_nodes(Bindings::AssignedNodesOptions options = {}) const; Vector> assigned_elements(Bindings::AssignedNodesOptions options = {}) const; - using SlottableHandle = Variant, GC::Root>; - void assign(Vector nodes); + using SlottableHandle = Variant, GC::Ref>; + void assign(GC::ConservativeVector nodes); ReadonlySpan manually_assigned_nodes() const { return m_manually_assigned_nodes; } diff --git a/Libraries/LibWeb/HTML/ImageBitmap.h b/Libraries/LibWeb/HTML/ImageBitmap.h index bf86278521..9bf40d09e8 100644 --- a/Libraries/LibWeb/HTML/ImageBitmap.h +++ b/Libraries/LibWeb/HTML/ImageBitmap.h @@ -17,7 +17,7 @@ namespace Web::HTML { -using ImageBitmapSource = FlattenVariant, GC::Root>>; +using ImageBitmapSource = FlattenVariant, GC::Ref>>; // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmapoptions struct ImageBitmapOptions { diff --git a/Libraries/LibWeb/HTML/MessageEvent.cpp b/Libraries/LibWeb/HTML/MessageEvent.cpp index fa6a33cec4..7927de5251 100644 --- a/Libraries/LibWeb/HTML/MessageEvent.cpp +++ b/Libraries/LibWeb/HTML/MessageEvent.cpp @@ -32,13 +32,6 @@ WebIDL::ExceptionOr> MessageEvent::construct_impl(JS::Real return create(realm, event_name, event_init); } -MessageEvent::MessageEventSourceInternal MessageEvent::to_message_event_source_internal(NullableMessageEventSource const& source) -{ - return source.visit( - [](Empty) -> MessageEventSourceInternal { return Empty {}; }, - [](auto const& root) -> MessageEventSourceInternal { return GC::Ref { *root }; }); -} - MessageEvent::MessageEvent(JS::Realm& realm, FlyString const& event_name, Bindings::MessageEventInit const& event_init) : MessageEvent(realm, event_name, event_init, String { event_init.origin }) { @@ -54,13 +47,12 @@ MessageEvent::MessageEvent(JS::Realm& realm, FlyString const& event_name, Bindin , m_data(event_init.data) , m_origin(move(origin)) , m_last_event_id(event_init.last_event_id) - , m_source(to_message_event_source_internal(event_init.source)) + , m_source(event_init.source) { m_ports.ensure_capacity(event_init.ports.size()); for (auto const& port : event_init.ports) { - VERIFY(port); - m_ports.unchecked_append(static_cast(*port)); + m_ports.unchecked_append(port); } } @@ -101,9 +93,7 @@ String MessageEvent::origin() const NullableMessageEventSource MessageEvent::source() const { - return m_source.visit( - [](Empty) -> NullableMessageEventSource { return Empty {}; }, - [](auto const& ref) -> NullableMessageEventSource { return GC::Root { *ref }; }); + return m_source; } GC::Ref MessageEvent::ports() const @@ -120,7 +110,7 @@ GC::Ref MessageEvent::ports() const } // https://html.spec.whatwg.org/multipage/comms.html#dom-messageevent-initmessageevent -void MessageEvent::init_message_event(String const& type, bool bubbles, bool cancelable, JS::Value data, String const& origin, String const& last_event_id, NullableMessageEventSource source, Vector> const& ports) +void MessageEvent::init_message_event(String const& type, bool bubbles, bool cancelable, JS::Value data, String const& origin, String const& last_event_id, NullableMessageEventSource source, GC::RootVector> const& ports) { // The initMessageEvent(type, bubbles, cancelable, data, origin, lastEventId, source, ports) method must initialize the event in a // manner analogous to the similarly-named initEvent() method. @@ -136,13 +126,12 @@ void MessageEvent::init_message_event(String const& type, bool bubbles, bool can m_data = data; m_origin = origin; m_last_event_id = last_event_id; - m_source = to_message_event_source_internal(source); + m_source = source; m_ports_array = nullptr; m_ports.clear(); m_ports.ensure_capacity(ports.size()); for (auto const& port : ports) { - VERIFY(port); m_ports.unchecked_append(static_cast(*port)); } } diff --git a/Libraries/LibWeb/HTML/MessageEvent.h b/Libraries/LibWeb/HTML/MessageEvent.h index 5cdbbcbfd5..380f2c1b6c 100644 --- a/Libraries/LibWeb/HTML/MessageEvent.h +++ b/Libraries/LibWeb/HTML/MessageEvent.h @@ -9,7 +9,7 @@ #pragma once #include -#include +#include #include #include @@ -17,8 +17,8 @@ namespace Web::HTML { // FIXME: Include ServiceWorker // https://html.spec.whatwg.org/multipage/comms.html#messageeventsource -using MessageEventSource = Variant, GC::Root>; -using NullableMessageEventSource = Variant, GC::Root, Empty>; +using MessageEventSource = Variant, GC::Ref>; +using NullableMessageEventSource = Variant, GC::Ref, Empty>; // https://html.spec.whatwg.org/multipage/comms.html#messageevent class WEB_API MessageEvent : public DOM::Event { @@ -26,7 +26,7 @@ class WEB_API MessageEvent : public DOM::Event { GC_DECLARE_ALLOCATOR(MessageEvent); public: - [[nodiscard]] static GC::Ref create(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const& = {}); + [[nodiscard]] static GC::Ref create(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const&); [[nodiscard]] static GC::Ref create(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const&, URL::Origin const&); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const&); @@ -43,14 +43,12 @@ public: virtual Optional extract_an_origin() const override; - void init_message_event(String const& type, bool bubbles, bool cancelable, JS::Value data, String const& origin, String const& last_event_id, NullableMessageEventSource source, Vector> const& ports); + void init_message_event(String const& type, bool bubbles, bool cancelable, JS::Value data, String const& origin, String const& last_event_id, NullableMessageEventSource source, GC::RootVector> const& ports); private: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; - using MessageEventSourceInternal = Variant, GC::Ref>; - static MessageEventSourceInternal to_message_event_source_internal(NullableMessageEventSource const&); MessageEvent(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const& event_init, Variant); JS::Value m_data; @@ -60,7 +58,7 @@ private: Variant m_origin; String m_last_event_id; - MessageEventSourceInternal m_source; + NullableMessageEventSource m_source; Vector> m_ports; mutable GC::Ptr m_ports_array; }; diff --git a/Libraries/LibWeb/HTML/MessagePort.cpp b/Libraries/LibWeb/HTML/MessagePort.cpp index 82409bfc98..b14f6cc86e 100644 --- a/Libraries/LibWeb/HTML/MessagePort.cpp +++ b/Libraries/LibWeb/HTML/MessagePort.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -229,7 +230,7 @@ void MessagePort::entangle_with(MessagePort& remote_port) } // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-messageport-postmessage-options -WebIDL::ExceptionOr MessagePort::post_message(JS::Value message, Vector> const& transfer) +WebIDL::ExceptionOr MessagePort::post_message(JS::Value message, GC::RootVector> const& transfer) { // 1. Let targetPort be the port with which this MessagePort is entangled, if any; otherwise let it be null. GC::Ptr target_port = m_remote_port; @@ -406,7 +407,7 @@ void MessagePort::post_message_task_steps(SerializedTransferRecord& serialize_wi if (deserialize_record_or_error.is_error()) { // If this throws an exception, catch it, fire an event named messageerror at finalTargetPort, using MessageEvent, and then return. auto exception = deserialize_record_or_error.release_error(); - Bindings::MessageEventInit event_init {}; + Bindings::MessageEventInit event_init; message_event_target->dispatch_event(MessageEvent::create(target_realm, HTML::EventNames::messageerror, event_init)); return; } @@ -417,7 +418,7 @@ void MessagePort::post_message_task_steps(SerializedTransferRecord& serialize_wi // 5. Let newPorts be a new frozen array consisting of all MessagePort objects in deserializeRecord.[[TransferredValues]], if any, maintaining their relative order. // FIXME: Use a FrozenArray - Vector> new_ports; + GC::RootVector> new_ports; for (auto const& object : deserialize_record.transferred_values) { if (is(*object)) { new_ports.append(as(*object)); @@ -425,9 +426,7 @@ void MessagePort::post_message_task_steps(SerializedTransferRecord& serialize_wi } // 6. Fire an event named message at finalTargetPort, using MessageEvent, with the data attribute initialized to messageClone and the ports attribute initialized to newPorts. - Bindings::MessageEventInit event_init {}; - event_init.data = message_clone; - event_init.ports = move(new_ports); + Bindings::MessageEventInit event_init { Bindings::EventInit {}, message_clone, String {}, String {}, move(new_ports), Empty {} }; auto event = MessageEvent::create(target_realm, HTML::EventNames::message, event_init); event->set_is_trusted(true); message_event_target->dispatch_event(event); diff --git a/Libraries/LibWeb/HTML/MessagePort.h b/Libraries/LibWeb/HTML/MessagePort.h index f5cc8e9f8a..052440d40b 100644 --- a/Libraries/LibWeb/HTML/MessagePort.h +++ b/Libraries/LibWeb/HTML/MessagePort.h @@ -45,7 +45,7 @@ public: GC::Ptr entangled_port() const { return m_remote_port; } // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-messageport-postmessage - WebIDL::ExceptionOr post_message(JS::Value message, Vector> const& transfer); + WebIDL::ExceptionOr post_message(JS::Value message, GC::RootVector> const& transfer); // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-messageport-postmessage-options WebIDL::ExceptionOr post_message(JS::Value message, Bindings::StructuredSerializeOptions const& options); diff --git a/Libraries/LibWeb/HTML/NavigateEvent.cpp b/Libraries/LibWeb/HTML/NavigateEvent.cpp index 5671cf6924..35cc6c5337 100644 --- a/Libraries/LibWeb/HTML/NavigateEvent.cpp +++ b/Libraries/LibWeb/HTML/NavigateEvent.cpp @@ -98,7 +98,7 @@ WebIDL::ExceptionOr NavigateEvent::intercept(Bindings::NavigationIntercept m_interception_state = InterceptionState::Intercepted; // 6. If options["handler"] exists, then append it to this's navigation handler list. - if (options.handler != nullptr) + if (options.handler) TRY_OR_THROW_OOM(vm, m_navigation_handler_list.try_append(*options.handler)); // 7. If options["focusReset"] exists, then: diff --git a/Libraries/LibWeb/HTML/Navigation.cpp b/Libraries/LibWeb/HTML/Navigation.cpp index b963539aeb..50f92ceb19 100644 --- a/Libraries/LibWeb/HTML/Navigation.cpp +++ b/Libraries/LibWeb/HTML/Navigation.cpp @@ -146,9 +146,7 @@ WebIDL::ExceptionOr Navigation::update_current_entry(Bindings::NavigationU // 5. Fire an event named currententrychange at this using NavigationCurrentEntryChangeEvent, // with its navigationType attribute initialized to null and its from initialized to current. - Bindings::NavigationCurrentEntryChangeEventInit event_init = {}; - event_init.navigation_type = {}; - event_init.from = current; + Bindings::NavigationCurrentEntryChangeEventInit event_init { Bindings::EventInit {}, *current, {} }; dispatch_event(HTML::NavigationCurrentEntryChangeEvent::construct_impl(realm(), HTML::EventNames::currententrychange, event_init)); return {}; @@ -314,7 +312,7 @@ WebIDL::ExceptionOr Navigation::reload(Bindings::Nav // NOTE: It is important to perform this step early, since serialization can invoke web developer code, which in // turn might change various things we check in later steps. if (options.state.has_value()) { - auto serialized_state_or_error = structured_serialize_for_storage(vm, options.state.value()); + auto serialized_state_or_error = structured_serialize_for_storage(vm, *options.state); if (serialized_state_or_error.is_error()) return early_error_result(serialized_state_or_error.release_error()); serialized_state = serialized_state_or_error.release_value(); @@ -989,9 +987,13 @@ bool Navigation::inner_navigate_event_firing_algorithm( // 8. Let document be navigation's relevant global object's associated Document. auto& document = relevant_global_object.associated_document(); + // 19. Set event's abort controller to a new AbortController created in navigation's relevant realm. + // AD-HOC: Set on the NavigateEvent later after construction + auto abort_controller = MUST(DOM::AbortController::construct_impl(realm)); + // Note: We create the Event in this algorithm instead of passing it in, // and have all the following "initialize" steps set up the event init - Bindings::NavigateEventInit event_init = {}; + Bindings::NavigateEventInit event_init { Bindings::EventInit {}, false, destination, {}, {}, false, false, {}, Bindings::NavigationType::Push, abort_controller->signal(), {}, false }; // 9. If document can have its URL rewritten to destination's URL, // and either destination's is same document is true or navigationType is not "traverse", @@ -1041,12 +1043,8 @@ bool Navigation::inner_navigate_event_firing_algorithm( // 18. Initialize event's sourceElement to sourceElement. event_init.source_element = source_element; - // 19. Set event's abort controller to a new AbortController created in navigation's relevant realm. - // AD-HOC: Set on the NavigateEvent later after construction - auto abort_controller = MUST(DOM::AbortController::construct_impl(realm)); - // 20. Initialize event's signal to event's abort controller's signal. - event_init.signal = abort_controller->signal(); + // AD-HOC: Done when event_init is created. // 21. Let currentURL be document's URL. auto current_url = document.url(); @@ -1543,9 +1541,7 @@ void Navigation::update_the_navigation_api_entries_for_a_same_document_navigatio // 10. Fire an event named currententrychange at navigation using NavigationCurrentEntryChangeEvent, // with its navigationType attribute initialized to navigationType and its from initialized to oldCurrentNHE. - Bindings::NavigationCurrentEntryChangeEventInit event_init = {}; - event_init.navigation_type = navigation_type; - event_init.from = old_current_nhe; + Bindings::NavigationCurrentEntryChangeEventInit event_init { Bindings::EventInit {}, *old_current_nhe, navigation_type }; dispatch_event(NavigationCurrentEntryChangeEvent::construct_impl(realm, EventNames::currententrychange, event_init)); // 11. For each disposedNHE of disposedNHEs: diff --git a/Libraries/LibWeb/HTML/NavigationCurrentEntryChangeEvent.cpp b/Libraries/LibWeb/HTML/NavigationCurrentEntryChangeEvent.cpp index a20855aedd..cff5ed057a 100644 --- a/Libraries/LibWeb/HTML/NavigationCurrentEntryChangeEvent.cpp +++ b/Libraries/LibWeb/HTML/NavigationCurrentEntryChangeEvent.cpp @@ -22,7 +22,7 @@ GC::Ref NavigationCurrentEntryChangeEvent::co NavigationCurrentEntryChangeEvent::NavigationCurrentEntryChangeEvent(JS::Realm& realm, FlyString const& event_name, Bindings::NavigationCurrentEntryChangeEventInit const& event_init) : DOM::Event(realm, event_name, event_init) - , m_navigation_type(event_init.navigation_type) + , m_navigation_type(event_init.navigation_type.value_or({})) , m_from(*event_init.from) { } diff --git a/Libraries/LibWeb/HTML/NavigatorBeacon.cpp b/Libraries/LibWeb/HTML/NavigatorBeacon.cpp index 192700d276..f6d3efdad8 100644 --- a/Libraries/LibWeb/HTML/NavigatorBeacon.cpp +++ b/Libraries/LibWeb/HTML/NavigatorBeacon.cpp @@ -48,7 +48,7 @@ WebIDL::ExceptionOr NavigatorBeaconPartial::send_beacon(String const& url, GC::Ptr transmitted_data; if (!data.has()) { // 6.1 Set transmittedData and contentType to the result of extracting data's byte stream with the keepalive flag set. - auto body_with_type = TRY(Fetch::extract_body(realm, data.downcast, GC::Root, GC::Root, GC::Root, GC::Root, String>(), true)); + auto body_with_type = TRY(Fetch::extract_body(realm, data.downcast, GC::Ref, GC::Ref, GC::Ref, GC::Ref, String>(), true)); transmitted_data = body_with_type.body; auto& content_type = body_with_type.type; diff --git a/Libraries/LibWeb/HTML/OffscreenCanvas.cpp b/Libraries/LibWeb/HTML/OffscreenCanvas.cpp index 77bc37557f..d68be8b6d3 100644 --- a/Libraries/LibWeb/HTML/OffscreenCanvas.cpp +++ b/Libraries/LibWeb/HTML/OffscreenCanvas.cpp @@ -214,7 +214,7 @@ JS::ThrowCompletionOr OffscreenCanvas::get_context(Bi // NOTE: See the spec for the full table. if (contextId == Bindings::OffscreenRenderingContextId::_2d) { if (TRY(create_2d_context(options)) == HasOrCreatedContext::Yes) - return GC::make_root(*m_context.get>()); + return *m_context.get>(); return Empty {}; } diff --git a/Libraries/LibWeb/HTML/OffscreenCanvas.h b/Libraries/LibWeb/HTML/OffscreenCanvas.h index c27e292b31..10a24de7aa 100644 --- a/Libraries/LibWeb/HTML/OffscreenCanvas.h +++ b/Libraries/LibWeb/HTML/OffscreenCanvas.h @@ -17,7 +17,7 @@ namespace Web::HTML { // https://html.spec.whatwg.org/multipage/canvas.html#offscreenrenderingcontext // NOTE: This is the Variant created by the IDL wrapper generator, and needs to be updated accordingly. -using OffscreenRenderingContext = Variant, GC::Root, GC::Root, Empty>; +using OffscreenRenderingContext = Variant, GC::Ref, GC::Ref, Empty>; // https://html.spec.whatwg.org/multipage/canvas.html#offscreencanvas class OffscreenCanvas : public DOM::EventTarget diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 1c07b9980d..46b052321b 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -7,6 +7,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -1093,7 +1094,7 @@ static String escape_string(ViewType const& string, AttributeMode attribute_mode } // https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-serialisation-algorithm -String HTMLParser::serialize_html_fragment(DOM::Node const& node, SerializableShadowRoots serializable_shadow_roots, Vector> const& shadow_roots, DOM::FragmentSerializationMode fragment_serialization_mode) +String HTMLParser::serialize_html_fragment(DOM::Node const& node, SerializableShadowRoots serializable_shadow_roots, ReadonlySpan> shadow_roots, DOM::FragmentSerializationMode fragment_serialization_mode) { // NOTE: Steps in this function are jumbled a bit to accommodate the Element.outerHTML API. // When called with FragmentSerializationMode::Outer, we will serialize the element itself, @@ -1228,7 +1229,7 @@ String HTMLParser::serialize_html_fragment(DOM::Node const& node, SerializableSh // - serializableShadowRoots is true and shadow's serializable is true; or // - shadowRoots contains shadow, if ((serializable_shadow_roots == SerializableShadowRoots::Yes && shadow->serializable()) - || shadow_roots.contains([&](auto& entry) { return entry == shadow; })) { + || any_of(shadow_roots, [&](auto& entry) { return entry == shadow; })) { // then: // 1. Append "