mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-05 14:42:50 +02:00
LibWeb: Return error on modification of a computed CSS style declaration
Previously, calling `setProperty` or `removeProperty` from JS on a CSSStyleDeclaration returned from `getComputedStyle()` would return null. We now return a NoModificationAllowedError instead, which aligns our implementation with the specification. (cherry picked from commit ea68bdef26260762dec02413cce0d79caef6f4a4)
This commit is contained in:
committed by
Nico Weber
parent
ef20e0bd73
commit
adebc2a214
@@ -583,18 +583,42 @@ Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID propert
|
||||
};
|
||||
}
|
||||
|
||||
static WebIDL::ExceptionOr<void> cannot_modify_computed_property_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<void> 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_property_error(realm());
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty
|
||||
WebIDL::ExceptionOr<void> ResolvedCSSStyleDeclaration::set_property(StringView, StringView, StringView)
|
||||
{
|
||||
// 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
|
||||
return cannot_modify_computed_property_error(realm());
|
||||
}
|
||||
|
||||
static WebIDL::ExceptionOr<String> cannot_remove_computed_property_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<String> 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_property_error(realm());
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty
|
||||
WebIDL::ExceptionOr<String> ResolvedCSSStyleDeclaration::remove_property(StringView)
|
||||
{
|
||||
// 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
|
||||
return cannot_remove_computed_property_error(realm());
|
||||
}
|
||||
|
||||
String ResolvedCSSStyleDeclaration::serialized() const
|
||||
|
||||
Reference in New Issue
Block a user