diff --git a/Libraries/LibWeb/CSS/CSSImageValue.cpp b/Libraries/LibWeb/CSS/CSSImageValue.cpp index 3a9db429de2..d88be19f49f 100644 --- a/Libraries/LibWeb/CSS/CSSImageValue.cpp +++ b/Libraries/LibWeb/CSS/CSSImageValue.cpp @@ -7,6 +7,7 @@ #include "CSSImageValue.h" #include #include +#include namespace Web::CSS { @@ -30,7 +31,7 @@ void CSSImageValue::initialize(JS::Realm& realm) } // https://drafts.css-houdini.org/css-typed-om-1/#stylevalue-serialization -String CSSImageValue::to_string() const +WebIDL::ExceptionOr CSSImageValue::to_string() const { // AD-HOC: The spec doesn't say how to serialize this, as it's intentionally a black box. // We just serialize the source string that was used to construct this. diff --git a/Libraries/LibWeb/CSS/CSSImageValue.h b/Libraries/LibWeb/CSS/CSSImageValue.h index 29e95cd2346..931f4a89b17 100644 --- a/Libraries/LibWeb/CSS/CSSImageValue.h +++ b/Libraries/LibWeb/CSS/CSSImageValue.h @@ -20,7 +20,7 @@ public: virtual ~CSSImageValue() override = default; - virtual String to_string() const override; + virtual WebIDL::ExceptionOr to_string() const override; private: explicit CSSImageValue(JS::Realm&, String constructed_from_string); diff --git a/Libraries/LibWeb/CSS/CSSKeywordValue.cpp b/Libraries/LibWeb/CSS/CSSKeywordValue.cpp index 5d0c0a57413..61152ae1889 100644 --- a/Libraries/LibWeb/CSS/CSSKeywordValue.cpp +++ b/Libraries/LibWeb/CSS/CSSKeywordValue.cpp @@ -55,7 +55,7 @@ WebIDL::ExceptionOr CSSKeywordValue::set_value(FlyString value) } // https://drafts.css-houdini.org/css-typed-om-1/#keywordvalue-serialization -String CSSKeywordValue::to_string() const +WebIDL::ExceptionOr CSSKeywordValue::to_string() const { // To serialize a CSSKeywordValue this: // 1. Return this’s value internal slot. diff --git a/Libraries/LibWeb/CSS/CSSKeywordValue.h b/Libraries/LibWeb/CSS/CSSKeywordValue.h index b8837318f94..93358f4ea68 100644 --- a/Libraries/LibWeb/CSS/CSSKeywordValue.h +++ b/Libraries/LibWeb/CSS/CSSKeywordValue.h @@ -28,7 +28,7 @@ public: FlyString const& value() const { return m_value; } WebIDL::ExceptionOr set_value(FlyString value); - virtual String to_string() const override; + virtual WebIDL::ExceptionOr to_string() const override; private: explicit CSSKeywordValue(JS::Realm&, FlyString value); diff --git a/Libraries/LibWeb/CSS/CSSNumericValue.cpp b/Libraries/LibWeb/CSS/CSSNumericValue.cpp index ac4f2f49ccb..5ab184e2765 100644 --- a/Libraries/LibWeb/CSS/CSSNumericValue.cpp +++ b/Libraries/LibWeb/CSS/CSSNumericValue.cpp @@ -85,7 +85,7 @@ WebIDL::ExceptionOr> CSSNumericValue::to(FlyString const& // 2. Let sum be the result of creating a sum value from this. If sum is failure, throw a TypeError. auto sum = create_a_sum_value(); if (!sum.has_value()) - return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to create a sum from input '{}'", to_string())) }; + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to create a sum from input '{}'", MUST(to_string()))) }; // 3. If sum has more than one item, throw a TypeError. // Otherwise, let item be the result of creating a CSSUnitValue from the sole item in sum, then converting it to @@ -94,11 +94,11 @@ WebIDL::ExceptionOr> CSSNumericValue::to(FlyString const& return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Sum contains more than one item"sv }; auto item = CSSUnitValue::create_from_sum_value_item(realm(), sum->first()); if (!item) - return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to create CSSUnitValue from input '{}'", to_string())) }; + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to create CSSUnitValue from input '{}'", MUST(to_string()))) }; auto converted_item = item->converted_to_unit(unit); if (!converted_item) - return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to convert input '{}' to unit '{}'", to_string(), unit)) }; + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to convert input '{}' to unit '{}'", MUST(to_string()), unit)) }; // 4. Return item. return converted_item.as_nonnull(); diff --git a/Libraries/LibWeb/CSS/CSSNumericValue.h b/Libraries/LibWeb/CSS/CSSNumericValue.h index a01ded379d8..527e612107b 100644 --- a/Libraries/LibWeb/CSS/CSSNumericValue.h +++ b/Libraries/LibWeb/CSS/CSSNumericValue.h @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace Web::CSS { @@ -59,7 +60,7 @@ public: CSSNumericType type_for_bindings() const; NumericType const& type() const { return m_type; } - virtual String to_string() const final override { return to_string({}); } + virtual WebIDL::ExceptionOr to_string() const final override { return to_string({}); } String to_string(SerializationParams const&) const; static WebIDL::ExceptionOr> parse(JS::VM&, String const& css_text); diff --git a/Libraries/LibWeb/CSS/CSSPerspective.cpp b/Libraries/LibWeb/CSS/CSSPerspective.cpp index 3efecbd13c5..73c473e2083 100644 --- a/Libraries/LibWeb/CSS/CSSPerspective.cpp +++ b/Libraries/LibWeb/CSS/CSSPerspective.cpp @@ -89,13 +89,13 @@ WebIDL::ExceptionOr CSSPerspective::to_string() const builder.append("perspective("sv); // 2. Serialize this’s length internal slot, with a minimum of 0px, and append it to s. - auto serialized_length = m_length.visit( - [](GC::Ref const& numeric_value) { + auto serialized_length = TRY(m_length.visit( + [](GC::Ref const& numeric_value) -> WebIDL::ExceptionOr { return numeric_value->to_string({ .minimum = 0 }); }, - [](GC::Ref const& keyword_value) { + [](GC::Ref const& keyword_value) -> WebIDL::ExceptionOr { return keyword_value->to_string(); - }); + })); builder.append(serialized_length); // 3. Append ")" to s, and return s. diff --git a/Libraries/LibWeb/CSS/CSSRotate.cpp b/Libraries/LibWeb/CSS/CSSRotate.cpp index e4f0eaebec4..e31ee913719 100644 --- a/Libraries/LibWeb/CSS/CSSRotate.cpp +++ b/Libraries/LibWeb/CSS/CSSRotate.cpp @@ -104,25 +104,25 @@ WebIDL::ExceptionOr CSSRotate::to_string() const builder.append("rotate3d("sv); // 2. Serialize this’s x internal slot, and append it to s. - builder.append(m_x->to_string()); + builder.append(TRY(m_x->to_string())); // 3. Append ", " to s. builder.append(", "sv); // 4. Serialize this’s y internal slot, and append it to s. - builder.append(m_y->to_string()); + builder.append(TRY(m_y->to_string())); // 5. Append ", " to s. builder.append(", "sv); // 6. Serialize this’s z internal slot, and append it to s. - builder.append(m_z->to_string()); + builder.append(TRY(m_z->to_string())); // 7. Append "," to s. builder.append(", "sv); // 8. Serialize this’s angle internal slot, and append it to s. - builder.append(m_angle->to_string()); + builder.append(TRY(m_angle->to_string())); // 9. Append ")" to s, and return s. builder.append(")"sv); @@ -134,7 +134,7 @@ WebIDL::ExceptionOr CSSRotate::to_string() const builder.append("rotate("sv); // 2. Serialize this’s angle internal slot, and append it to s. - builder.append(m_angle->to_string()); + builder.append(TRY(m_angle->to_string())); // 3. Append ")" to s, and return s. builder.append(")"sv); diff --git a/Libraries/LibWeb/CSS/CSSScale.cpp b/Libraries/LibWeb/CSS/CSSScale.cpp index 21052030d4e..d2f43dc96ce 100644 --- a/Libraries/LibWeb/CSS/CSSScale.cpp +++ b/Libraries/LibWeb/CSS/CSSScale.cpp @@ -89,19 +89,19 @@ WebIDL::ExceptionOr CSSScale::to_string() const builder.append("scale3d("sv); // 2. Serialize this’s x internal slot, and append it to s. - builder.append(m_x->to_string()); + builder.append(TRY(m_x->to_string())); // 3. Append ", " to s. builder.append(", "sv); // 4. Serialize this’s y internal slot, and append it to s. - builder.append(m_y->to_string()); + builder.append(TRY(m_y->to_string())); // 5. Append ", " to s. builder.append(", "sv); // 6. Serialize this’s z internal slot, and append it to s. - builder.append(m_z->to_string()); + builder.append(TRY(m_z->to_string())); // 7. Append ")" to s, and return s. builder.append(")"sv); @@ -114,7 +114,7 @@ WebIDL::ExceptionOr CSSScale::to_string() const builder.append("scale("sv); // 2. Serialize this’s x internal slot, and append it to s. - builder.append(m_x->to_string()); + builder.append(TRY(m_x->to_string())); // 3. If this’s x and y internal slots are equal numeric values, append ")" to s and return s. if (m_x->is_equal_numeric_value(m_y)) { @@ -126,7 +126,7 @@ WebIDL::ExceptionOr CSSScale::to_string() const builder.append(", "sv); // 5. Serialize this’s y internal slot, and append it to s. - builder.append(m_y->to_string()); + builder.append(TRY(m_y->to_string())); // 6. Append ")" to s, and return s. builder.append(")"sv); diff --git a/Libraries/LibWeb/CSS/CSSSkew.cpp b/Libraries/LibWeb/CSS/CSSSkew.cpp index a9b97392aae..28c73991b7a 100644 --- a/Libraries/LibWeb/CSS/CSSSkew.cpp +++ b/Libraries/LibWeb/CSS/CSSSkew.cpp @@ -67,7 +67,7 @@ WebIDL::ExceptionOr CSSSkew::to_string() const builder.append("skew("sv); // 2. Serialize this’s ax internal slot, and append it to s. - builder.append(m_ax->to_string()); + builder.append(TRY(m_ax->to_string())); // 3. If this’s ay internal slot is a CSSUnitValue with a value of 0, then append ")" to s and return s. if (auto* ay_unit_value = as_if(*m_ay); ay_unit_value && ay_unit_value->value() == 0) { @@ -79,7 +79,7 @@ WebIDL::ExceptionOr CSSSkew::to_string() const builder.append(", "sv); // 5. Serialize this’s ay internal slot, and append it to s. - builder.append(m_ay->to_string()); + builder.append(TRY(m_ay->to_string())); // 6. Append ")" to s, and return s. builder.append(")"sv); diff --git a/Libraries/LibWeb/CSS/CSSSkewX.cpp b/Libraries/LibWeb/CSS/CSSSkewX.cpp index 86599142d7c..bcd52447d50 100644 --- a/Libraries/LibWeb/CSS/CSSSkewX.cpp +++ b/Libraries/LibWeb/CSS/CSSSkewX.cpp @@ -62,7 +62,7 @@ WebIDL::ExceptionOr CSSSkewX::to_string() const builder.append("skewX("sv); // 2. Serialize this’s ax internal slot, and append it to s. - builder.append(m_ax->to_string()); + builder.append(TRY(m_ax->to_string())); // 3. Append ")" to s, and return s. builder.append(")"sv); diff --git a/Libraries/LibWeb/CSS/CSSSkewY.cpp b/Libraries/LibWeb/CSS/CSSSkewY.cpp index 363f98565f6..4906ba345ca 100644 --- a/Libraries/LibWeb/CSS/CSSSkewY.cpp +++ b/Libraries/LibWeb/CSS/CSSSkewY.cpp @@ -62,7 +62,7 @@ WebIDL::ExceptionOr CSSSkewY::to_string() const builder.append("skewY("sv); // 2. Serialize this’s ay internal slot, and append it to s. - builder.append(m_ay->to_string()); + builder.append(TRY(m_ay->to_string())); // 3. Append ")" to s, and return s. builder.append(")"sv); diff --git a/Libraries/LibWeb/CSS/CSSStyleValue.cpp b/Libraries/LibWeb/CSS/CSSStyleValue.cpp index e731b89d0f7..666954d5d80 100644 --- a/Libraries/LibWeb/CSS/CSSStyleValue.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleValue.cpp @@ -92,7 +92,7 @@ WebIDL::ExceptionOr, GC::RootVector CSSStyleValue::to_string() const { // if the value was constructed from a USVString if (m_constructed_from_string.has_value()) { @@ -108,7 +108,7 @@ String CSSStyleValue::to_string() const { // the serialization is specified in §6.7 Serialization from CSSOM Values below. } - return {}; + return String {}; } } diff --git a/Libraries/LibWeb/CSS/CSSStyleValue.h b/Libraries/LibWeb/CSS/CSSStyleValue.h index 74ad0d3113a..815cff100d1 100644 --- a/Libraries/LibWeb/CSS/CSSStyleValue.h +++ b/Libraries/LibWeb/CSS/CSSStyleValue.h @@ -25,7 +25,7 @@ public: static WebIDL::ExceptionOr> parse(JS::VM&, String property, String css_text); static WebIDL::ExceptionOr>> parse_all(JS::VM&, String property, String css_text); - virtual String to_string() const; + virtual WebIDL::ExceptionOr to_string() const; protected: explicit CSSStyleValue(JS::Realm&); diff --git a/Libraries/LibWeb/CSS/CSSTranslate.cpp b/Libraries/LibWeb/CSS/CSSTranslate.cpp index b282743c092..962c09da8d5 100644 --- a/Libraries/LibWeb/CSS/CSSTranslate.cpp +++ b/Libraries/LibWeb/CSS/CSSTranslate.cpp @@ -87,19 +87,19 @@ WebIDL::ExceptionOr CSSTranslate::to_string() const builder.append("translate3d("sv); // 2. Serialize this’s x internal slot, and append it to s. - builder.append(m_x->to_string()); + builder.append(TRY(m_x->to_string())); // 3. Append ", " to s. builder.append(", "sv); // 4. Serialize this’s y internal slot, and append it to s. - builder.append(m_y->to_string()); + builder.append(TRY(m_y->to_string())); // 5. Append ", " to s. builder.append(", "sv); // 6. Serialize this’s z internal slot, and append it to s. - builder.append(m_z->to_string()); + builder.append(TRY(m_z->to_string())); // 7. Append ")" to s, and return s. builder.append(")"sv); @@ -111,13 +111,13 @@ WebIDL::ExceptionOr CSSTranslate::to_string() const builder.append("translate("sv); // 2. Serialize this’s x internal slot, and append it to s. - builder.append(m_x->to_string()); + builder.append(TRY(m_x->to_string())); // 3. Append ", " to s. builder.append(", "sv); // 4. Serialize this’s y internal slot, and append it to s. - builder.append(m_y->to_string()); + builder.append(TRY(m_y->to_string())); // 5. Append ")" to s, and return s. builder.append(")"sv); diff --git a/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp b/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp index 996bd6c3931..d3c38a0b9ad 100644 --- a/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp +++ b/Libraries/LibWeb/CSS/CSSUnparsedValue.cpp @@ -116,7 +116,7 @@ WebIDL::ExceptionOr CSSUnparsedValue::set_value_of_new_indexed_property(u3 } // https://drafts.css-houdini.org/css-typed-om-1/#serialize-a-cssunparsedvalue -String CSSUnparsedValue::to_string() const +WebIDL::ExceptionOr CSSUnparsedValue::to_string() const { // To serialize a CSSUnparsedValue this: // 1. Let s initially be the empty string. @@ -126,15 +126,17 @@ String CSSUnparsedValue::to_string() const for (auto const& item : m_tokens) { // FIXME: In order to match the expected test behaviour, this should insert comments, with the same rules as // serialize_a_series_of_component_values(). See https://github.com/w3c/css-houdini-drafts/issues/1148 - item.visit( + TRY(item.visit( // 1. If item is a USVString, append it to s. - [&](String const& string) { + [&](String const& string) -> WebIDL::ExceptionOr { s.append(string); + return {}; }, // 2. Otherwise, item is a CSSVariableReferenceValue. Serialize it, then append the result to s. - [&](GC::Ref const& variable) { - s.append(variable->to_string()); - }); + [&](GC::Ref const& variable) -> WebIDL::ExceptionOr { + s.append(TRY(variable->to_string())); + return {}; + })); } // 3. Return s. diff --git a/Libraries/LibWeb/CSS/CSSUnparsedValue.h b/Libraries/LibWeb/CSS/CSSUnparsedValue.h index 6cd283fedaa..32e5b2ea7be 100644 --- a/Libraries/LibWeb/CSS/CSSUnparsedValue.h +++ b/Libraries/LibWeb/CSS/CSSUnparsedValue.h @@ -30,7 +30,7 @@ public: virtual WebIDL::ExceptionOr set_value_of_existing_indexed_property(u32, JS::Value) override; virtual WebIDL::ExceptionOr set_value_of_new_indexed_property(u32, JS::Value) override; - virtual String to_string() const override; + virtual WebIDL::ExceptionOr to_string() const override; private: explicit CSSUnparsedValue(JS::Realm&, Vector); diff --git a/Libraries/LibWeb/CSS/CSSVariableReferenceValue.cpp b/Libraries/LibWeb/CSS/CSSVariableReferenceValue.cpp index f87de0b7583..da62614c7b1 100644 --- a/Libraries/LibWeb/CSS/CSSVariableReferenceValue.cpp +++ b/Libraries/LibWeb/CSS/CSSVariableReferenceValue.cpp @@ -89,7 +89,7 @@ WebIDL::ExceptionOr CSSVariableReferenceValue::set_fallback(GC::Ptr CSSVariableReferenceValue::to_string() const { // To serialize a CSSVariableReferenceValue this: // 1. Let s initially be "var(". @@ -103,7 +103,7 @@ String CSSVariableReferenceValue::to_string() const if (m_fallback) { // AD-HOC: Tested behaviour requires we append "," without the space. https://github.com/w3c/css-houdini-drafts/issues/1148 s.append(","sv); - s.append(m_fallback->to_string()); + s.append(TRY(m_fallback->to_string())); } // 4. Append ")" to s and return s. diff --git a/Libraries/LibWeb/CSS/CSSVariableReferenceValue.h b/Libraries/LibWeb/CSS/CSSVariableReferenceValue.h index 5a430cb1cc9..30f52c4b576 100644 --- a/Libraries/LibWeb/CSS/CSSVariableReferenceValue.h +++ b/Libraries/LibWeb/CSS/CSSVariableReferenceValue.h @@ -27,7 +27,7 @@ public: GC::Ptr fallback() const; WebIDL::ExceptionOr set_fallback(GC::Ptr); - String to_string() const; + WebIDL::ExceptionOr to_string() const; private: CSSVariableReferenceValue(JS::Realm&, FlyString variable, GC::Ptr fallback);