Skip to content

Commit

Permalink
LibWeb: Make DOMException take error message as a String
Browse files Browse the repository at this point in the history
There was no need to use FlyString for error messages, and it just
caused a bunch of churn since these strings typically only existed
during the lifetime of the error.

(cherry picked from commit 175f3febb8037a440d4ead7347d3266ee3d345e1;
minorly amended to fix conflict in WebSocket.cpp due to serenity
not having the adapter class removal in LadybirdBrowser/ladybird#1671)
  • Loading branch information
awesomekling authored and nico committed Nov 22, 2024
1 parent 9448fe1 commit cb5da25
Show file tree
Hide file tree
Showing 89 changed files with 464 additions and 462 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ static void generate_html_constructor(SourceGenerator& generator, IDL::Construct
// 11. If element is an already constructed marker, then throw an "InvalidStateError" DOMException.
if (element.has<HTML::AlreadyConstructedCustomElementMarker>())
return JS::throw_completion(WebIDL::InvalidStateError::create(realm, "Custom element has already been constructed"_fly_string));
return JS::throw_completion(WebIDL::InvalidStateError::create(realm, "Custom element has already been constructed"_string));
// 12. Perform ? element.[[SetPrototypeOf]](prototype).
auto actual_element = element.get<JS::Handle<DOM::Element>>();
Expand Down
14 changes: 7 additions & 7 deletions Userland/Libraries/LibWeb/Animations/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void Animation::cancel(ShouldInvalidate should_invalidate)
reset_an_animations_pending_tasks();

// 2. Reject the current finished promise with a DOMException named "AbortError".
auto dom_exception = WebIDL::AbortError::create(realm, "Animation was cancelled"_fly_string);
auto dom_exception = WebIDL::AbortError::create(realm, "Animation was cancelled"_string);
WebIDL::reject_promise(realm, current_finished_promise(), dom_exception);

// 3. Set the [[PromiseIsHandled]] internal slot of the current finished promise to true.
Expand Down Expand Up @@ -490,9 +490,9 @@ WebIDL::ExceptionOr<void> Animation::finish()
// effect end is infinity, throw an "InvalidStateError" DOMException and abort these steps.
auto effective_playback_rate = this->effective_playback_rate();
if (effective_playback_rate == 0.0)
return WebIDL::InvalidStateError::create(realm(), "Animation with a playback rate of 0 cannot be finished"_fly_string);
return WebIDL::InvalidStateError::create(realm(), "Animation with a playback rate of 0 cannot be finished"_string);
if (effective_playback_rate > 0.0 && isinf(associated_effect_end()))
return WebIDL::InvalidStateError::create(realm(), "Animation with no end cannot be finished"_fly_string);
return WebIDL::InvalidStateError::create(realm(), "Animation with no end cannot be finished"_string);

// 2. Apply any pending playback rate to animation.
apply_any_pending_playback_rate();
Expand Down Expand Up @@ -594,7 +594,7 @@ WebIDL::ExceptionOr<void> Animation::play_an_animation(AutoRewind auto_rewind)
// -> If associated effect end is positive infinity,
if (isinf(associated_effect_end) && associated_effect_end > 0.0) {
// throw an "InvalidStateError" DOMException and abort these steps.
return WebIDL::InvalidStateError::create(realm(), "Cannot rewind an animation with an infinite effect end"_fly_string);
return WebIDL::InvalidStateError::create(realm(), "Cannot rewind an animation with an infinite effect end"_string);
}
// -> Otherwise,
// Set seek time to animation’s associated effect end.
Expand Down Expand Up @@ -714,7 +714,7 @@ WebIDL::ExceptionOr<void> Animation::pause()
auto associated_effect_end = this->associated_effect_end();
if (isinf(associated_effect_end) && associated_effect_end > 0.0) {
// throw an "InvalidStateError" DOMException and abort these steps.
return WebIDL::InvalidStateError::create(realm(), "Cannot pause an animation with an infinite effect end"_fly_string);
return WebIDL::InvalidStateError::create(realm(), "Cannot pause an animation with an infinite effect end"_string);
}

// Otherwise,
Expand Down Expand Up @@ -840,7 +840,7 @@ WebIDL::ExceptionOr<void> Animation::reverse()
// 1. If there is no timeline associated with animation, or the associated timeline is inactive throw an
// "InvalidStateError" DOMException and abort these steps.
if (!m_timeline || m_timeline->is_inactive())
return WebIDL::InvalidStateError::create(realm, "Cannot reverse an animation with an inactive timeline"_fly_string);
return WebIDL::InvalidStateError::create(realm, "Cannot reverse an animation with an inactive timeline"_string);

// 2. Let original pending playback rate be animation’s pending playback rate.
auto original_pending_playback_rate = m_pending_playback_rate;
Expand Down Expand Up @@ -1208,7 +1208,7 @@ void Animation::reset_an_animations_pending_tasks()
apply_any_pending_playback_rate();

// 5. Reject animation’s current ready promise with a DOMException named "AbortError".
auto dom_exception = WebIDL::AbortError::create(realm, "Animation was cancelled"_fly_string);
auto dom_exception = WebIDL::AbortError::create(realm, "Animation was cancelled"_string);
WebIDL::reject_promise(realm, current_ready_promise(), dom_exception);

// 6. Set the [[PromiseIsHandled]] internal slot of animation’s current ready promise to true.
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,

// 2. If index is greater than length, then throw an IndexSizeError exception.
if (index > length)
return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds."_fly_string);
return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds."_string);

// 3. Set new rule to the results of performing parse a CSS rule on argument rule.
// NOTE: The insert-a-css-rule spec expects `rule` to be a string, but the CSSStyleSheet.insertRule()
Expand All @@ -77,7 +77,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,

// 4. If new rule is a syntax error, throw a SyntaxError exception.
if (!new_rule)
return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule."_fly_string);
return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule."_string);

// FIXME: 5. If new rule cannot be inserted into list at the zero-index position index due to constraints specified by CSS, then throw a HierarchyRequestError exception. [CSS21]

Expand All @@ -100,7 +100,7 @@ WebIDL::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index)

// 2. If index is greater than or equal to length, then throw an IndexSizeError exception.
if (index >= length)
return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds."_fly_string);
return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds."_string);

// 3. Set old rule to the indexth item in list.
CSSRule& old_rule = m_rules[index];
Expand Down
18 changes: 9 additions & 9 deletions Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> CSSStyleSheet::construct_im
// AD-HOC: This isn't explicitly mentioned in the specification, but multiple modern browsers do this.
URL::URL url = sheet->location().has_value() ? sheet_location_url->complete_url(options->base_url.value()) : options->base_url.value();
if (!url.is_valid())
return WebIDL::NotAllowedError::create(realm, "Constructed style sheets must have a valid base URL"_fly_string);
return WebIDL::NotAllowedError::create(realm, "Constructed style sheets must have a valid base URL"_string);

sheet->set_base_url(url);
}
Expand Down Expand Up @@ -135,19 +135,19 @@ WebIDL::ExceptionOr<unsigned> CSSStyleSheet::insert_rule(StringView rule, unsign

// If the disallow modification flag is set, throw a NotAllowedError DOMException.
if (disallow_modification())
return WebIDL::NotAllowedError::create(realm(), "Can't call insert_rule() on non-modifiable stylesheets."_fly_string);
return WebIDL::NotAllowedError::create(realm(), "Can't call insert_rule() on non-modifiable stylesheets."_string);

// 3. Let parsed rule be the return value of invoking parse a rule with rule.
auto context = m_style_sheet_list ? CSS::Parser::ParsingContext { m_style_sheet_list->document() } : CSS::Parser::ParsingContext { realm() };
auto parsed_rule = parse_css_rule(context, rule);

// 4. If parsed rule is a syntax error, return parsed rule.
if (!parsed_rule)
return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule."_fly_string);
return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule."_string);

// 5. If parsed rule is an @import rule, and the constructed flag is set, throw a SyntaxError DOMException.
if (constructed() && parsed_rule->type() == CSSRule::Type::Import)
return WebIDL::SyntaxError::create(realm(), "Can't insert @import rules into a constructed stylesheet."_fly_string);
return WebIDL::SyntaxError::create(realm(), "Can't insert @import rules into a constructed stylesheet."_string);

// 6. Return the result of invoking insert a CSS rule rule in the CSS rules at index.
auto result = m_rules->insert_a_css_rule(parsed_rule, index);
Expand All @@ -172,7 +172,7 @@ WebIDL::ExceptionOr<void> CSSStyleSheet::delete_rule(unsigned index)

// 2. If the disallow modification flag is set, throw a NotAllowedError DOMException.
if (disallow_modification())
return WebIDL::NotAllowedError::create(realm(), "Can't call delete_rule() on non-modifiable stylesheets."_fly_string);
return WebIDL::NotAllowedError::create(realm(), "Can't call delete_rule() on non-modifiable stylesheets."_string);

// 3. Remove a CSS rule in the CSS rules at index.
auto result = m_rules->remove_a_css_rule(index);
Expand All @@ -193,12 +193,12 @@ JS::NonnullGCPtr<JS::Promise> CSSStyleSheet::replace(String text)

// 2. If the constructed flag is not set, or the disallow modification flag is set, reject promise with a NotAllowedError DOMException and return promise.
if (!constructed()) {
promise->reject(WebIDL::NotAllowedError::create(realm(), "Can't call replace() on non-constructed stylesheets"_fly_string));
promise->reject(WebIDL::NotAllowedError::create(realm(), "Can't call replace() on non-constructed stylesheets"_string));
return promise;
}

if (disallow_modification()) {
promise->reject(WebIDL::NotAllowedError::create(realm(), "Can't call replace() on non-modifiable stylesheets"_fly_string));
promise->reject(WebIDL::NotAllowedError::create(realm(), "Can't call replace() on non-modifiable stylesheets"_string));
return promise;
}

Expand Down Expand Up @@ -237,9 +237,9 @@ WebIDL::ExceptionOr<void> CSSStyleSheet::replace_sync(StringView text)
{
// 1. If the constructed flag is not set, or the disallow modification flag is set, throw a NotAllowedError DOMException.
if (!constructed())
return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-constructed stylesheets"_fly_string);
return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-constructed stylesheets"_string);
if (disallow_modification())
return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-modifiable stylesheets"_fly_string);
return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-modifiable stylesheets"_string);

// 2. Let rules be the result of running parse a stylesheet’s contents from text.
auto context = m_style_sheet_list ? CSS::Parser::ParsingContext { m_style_sheet_list->document() } : CSS::Parser::ParsingContext { realm() };
Expand Down
28 changes: 14 additions & 14 deletions Userland/Libraries/LibWeb/CSS/FontFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String fam
auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm, base_url), *string);
sources = parser.parse_as_font_face_src();
if (sources.is_empty())
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid source string"_fly_string));
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid source string"_string));
} else {
auto buffer_source = source.get<JS::Handle<WebIDL::BufferSource>>();
auto maybe_buffer = WebIDL::get_buffer_source_copy(buffer_source->raw_object());
Expand All @@ -106,7 +106,7 @@ JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String fam
}

if (buffer.is_empty() && sources.is_empty())
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid font source"_fly_string));
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid font source"_string));

auto font = realm.heap().allocate<FontFace>(realm, realm, promise, move(sources), move(buffer), move(family), descriptors);

Expand Down Expand Up @@ -216,7 +216,7 @@ WebIDL::ExceptionOr<void> FontFace::set_family(String const& string)
{
auto property = parse_property_string<CSS::PropertyID::FontFamily>(realm(), string);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.family setter: Invalid font descriptor"_fly_string);
return WebIDL::SyntaxError::create(realm(), "FontFace.family setter: Invalid font descriptor"_string);

if (m_is_css_connected) {
// FIXME: Propagate to the CSSFontFaceRule and update the font-family property
Expand All @@ -232,7 +232,7 @@ WebIDL::ExceptionOr<void> FontFace::set_style(String const& string)
{
auto property = parse_property_string<CSS::PropertyID::FontStyle>(realm(), string);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.style setter: Invalid font descriptor"_fly_string);
return WebIDL::SyntaxError::create(realm(), "FontFace.style setter: Invalid font descriptor"_string);

if (m_is_css_connected) {
// FIXME: Propagate to the CSSFontFaceRule and update the font-style property
Expand All @@ -248,7 +248,7 @@ WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string)
{
auto property = parse_property_string<CSS::PropertyID::FontWeight>(realm(), string);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.weight setter: Invalid font descriptor"_fly_string);
return WebIDL::SyntaxError::create(realm(), "FontFace.weight setter: Invalid font descriptor"_string);

if (m_is_css_connected) {
// FIXME: Propagate to the CSSFontFaceRule and update the font-weight property
Expand All @@ -265,7 +265,7 @@ WebIDL::ExceptionOr<void> FontFace::set_stretch(String const& string)
// NOTE: font-stretch is now an alias for font-width
auto property = parse_property_string<CSS::PropertyID::FontWidth>(realm(), string);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_fly_string);
return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_string);

if (m_is_css_connected) {
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
Expand All @@ -281,43 +281,43 @@ WebIDL::ExceptionOr<void> FontFace::set_unicode_range(String const&)
{
// FIXME: This *should* work, but the <urange> production is hard to parse
// from just a value string in our implementation
return WebIDL::NotSupportedError::create(realm(), "unicode range is not yet implemented"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "unicode range is not yet implemented"_string);
}

// https://drafts.csswg.org/css-font-loading/#dom-fontface-featuresettings
WebIDL::ExceptionOr<void> FontFace::set_feature_settings(String const&)
{
return WebIDL::NotSupportedError::create(realm(), "feature settings is not yet implemented"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "feature settings is not yet implemented"_string);
}

// https://drafts.csswg.org/css-font-loading/#dom-fontface-variationsettings
WebIDL::ExceptionOr<void> FontFace::set_variation_settings(String const&)
{
return WebIDL::NotSupportedError::create(realm(), "variation settings is not yet implemented"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "variation settings is not yet implemented"_string);
}

// https://drafts.csswg.org/css-font-loading/#dom-fontface-display
WebIDL::ExceptionOr<void> FontFace::set_display(String const&)
{
return WebIDL::NotSupportedError::create(realm(), "display is not yet implemented"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "display is not yet implemented"_string);
}

// https://drafts.csswg.org/css-font-loading/#dom-fontface-ascentoverride
WebIDL::ExceptionOr<void> FontFace::set_ascent_override(String const&)
{
return WebIDL::NotSupportedError::create(realm(), "ascent override is not yet implemented"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "ascent override is not yet implemented"_string);
}

// https://drafts.csswg.org/css-font-loading/#dom-fontface-descentoverride
WebIDL::ExceptionOr<void> FontFace::set_descent_override(String const&)
{
return WebIDL::NotSupportedError::create(realm(), "descent override is not yet implemented"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "descent override is not yet implemented"_string);
}

// https://drafts.csswg.org/css-font-loading/#dom-fontface-linegapoverride
WebIDL::ExceptionOr<void> FontFace::set_line_gap_override(String const&)
{
return WebIDL::NotSupportedError::create(realm(), "line gap override is not yet implemented"_fly_string);
return WebIDL::NotSupportedError::create(realm(), "line gap override is not yet implemented"_string);
}

// https://drafts.csswg.org/css-font-loading/#dom-fontface-load
Expand Down Expand Up @@ -362,7 +362,7 @@ void FontFace::load_font_source()
// 1. If the attempt to load fails, reject font face’s [[FontStatusPromise]] with a DOMException whose name
// is "NetworkError" and set font face’s status attribute to "error".
font->m_status = Bindings::FontFaceLoadStatus::Error;
WebIDL::reject_promise(font->realm(), font->m_font_status_promise, WebIDL::NetworkError::create(font->realm(), "Failed to load font"_fly_string));
WebIDL::reject_promise(font->realm(), font->m_font_status_promise, WebIDL::NetworkError::create(font->realm(), "Failed to load font"_string));

// FIXME: For each FontFaceSet font face is in:
}));
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ FontFaceSet::add(JS::Handle<FontFace> face)

// 2. If font is CSS-connected, throw an InvalidModificationError exception and exit this algorithm immediately.
if (face->is_css_connected()) {
return WebIDL::InvalidModificationError::create(realm(), "Cannot add a CSS-connected FontFace to a FontFaceSet"_fly_string);
return WebIDL::InvalidModificationError::create(realm(), "Cannot add a CSS-connected FontFace to a FontFaceSet"_string);
}

// 3. Add the font argument to the FontFaceSet’s set entries.
Expand Down Expand Up @@ -170,7 +170,7 @@ WebIDL::CallbackType* FontFaceSet::onloadingerror()
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> FontFaceSet::load(String const&, String const&)
{
// FIXME: Do the steps
auto promise = WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "FontFaceSet::load is not yet implemented"_fly_string));
auto promise = WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "FontFaceSet::load is not yet implemented"_string));
return verify_cast<JS::Promise>(*promise->promise());
}

Expand Down
Loading

0 comments on commit cb5da25

Please sign in to comment.