diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index 79a81877889a6..62be62dada8d2 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -30,8 +30,8 @@ class CSSStyleDeclaration : public Bindings::PlatformObject { virtual WebIDL::ExceptionOr set_property(PropertyID, StringView css_text, StringView priority = ""sv) = 0; virtual WebIDL::ExceptionOr remove_property(PropertyID) = 0; - WebIDL::ExceptionOr set_property(StringView property_name, StringView css_text, StringView priority); - WebIDL::ExceptionOr remove_property(StringView property_name); + virtual WebIDL::ExceptionOr set_property(StringView property_name, StringView css_text, StringView priority); + virtual WebIDL::ExceptionOr remove_property(StringView property_name); String get_property_value(StringView property) const; StringView get_property_priority(StringView property) const; diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 80e6c04a3f97b..da2b5991fbfc4 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -569,18 +569,42 @@ Optional ResolvedCSSStyleDeclaration::property(PropertyID propert }; } +static WebIDL::ExceptionOr cannot_modify_computed_properties_error(JS::Realm& realm) +{ + return WebIDL::NoModificationAllowedError::create(realm, "Cannot modify properties in result of getComputedStyle()"_fly_string); +} + // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty WebIDL::ExceptionOr ResolvedCSSStyleDeclaration::set_property(PropertyID, StringView, StringView) { // 1. If the computed flag is set, then throw a NoModificationAllowedError exception. - return WebIDL::NoModificationAllowedError::create(realm(), "Cannot modify properties in result of getComputedStyle()"_fly_string); + return cannot_modify_computed_properties_error(realm()); +} + +// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty +WebIDL::ExceptionOr ResolvedCSSStyleDeclaration::set_property(StringView, StringView, StringView) +{ + // 1. If the computed flag is set, then throw a NoModificationAllowedError exception. + return cannot_modify_computed_properties_error(realm()); +} + +static WebIDL::ExceptionOr cannot_remove_computed_properties_error(JS::Realm& realm) +{ + return WebIDL::NoModificationAllowedError::create(realm, "Cannot remove properties from result of getComputedStyle()"_fly_string); } // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty WebIDL::ExceptionOr ResolvedCSSStyleDeclaration::remove_property(PropertyID) { // 1. If the computed flag is set, then throw a NoModificationAllowedError exception. - return WebIDL::NoModificationAllowedError::create(realm(), "Cannot remove properties from result of getComputedStyle()"_fly_string); + return cannot_remove_computed_properties_error(realm()); +} + +// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty +WebIDL::ExceptionOr ResolvedCSSStyleDeclaration::remove_property(StringView) +{ + // 1. If the computed flag is set, then throw a NoModificationAllowedError exception. + return cannot_remove_computed_properties_error(realm()); } String ResolvedCSSStyleDeclaration::serialized() const diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h index 422f82d1a3e8a..7dfd76bd98969 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h @@ -24,7 +24,9 @@ class ResolvedCSSStyleDeclaration final : public CSSStyleDeclaration { virtual Optional property(PropertyID) const override; virtual WebIDL::ExceptionOr set_property(PropertyID, StringView css_text, StringView priority) override; + virtual WebIDL::ExceptionOr set_property(StringView property_name, StringView css_text, StringView priority) override; virtual WebIDL::ExceptionOr remove_property(PropertyID) override; + virtual WebIDL::ExceptionOr remove_property(StringView property_name) override; virtual String serialized() const override; virtual WebIDL::ExceptionOr set_css_text(StringView) override;