Skip to content

Commit

Permalink
CSSRule.type should not return values greater than 15
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=249560
rdar://103531316

Reviewed by Sam Weinig.

"This enumeration is thus frozen in its current state, and no new new values will be added to
reflect additional at-rules; all at-rules beyond the ones listed above will return 0."

https://w3c.github.io/csswg-drafts/cssom/#the-cssrule-interface

* LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-cssom-expected.txt:
* Source/WebCore/css/CSSRule.cpp:
(WebCore::CSSRule::typeForCSSOM const):

Return 0 for unexposed types.
Rename for clarity.

* Source/WebCore/css/CSSRule.h:
(WebCore::CSSRule::type const): Deleted.
* Source/WebCore/css/CSSRule.idl:
* Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration):
* Source/WebCore/css/StyleRuleType.h:
* Source/WebKitLegacy/mac/DOM/DOMCSSRule.mm:
(-[DOMCSSRule type]):

Canonical link: https://commits.webkit.org/258128@main
  • Loading branch information
anttijk committed Dec 20, 2022
1 parent 5192197 commit f34b82d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 10 deletions.
Expand Up @@ -12,7 +12,7 @@ PASS Rule for --syntax-only has expected cssText
PASS Rule for --inherits-only has expected cssText
PASS Rule for --initial-value-only has expected cssText
PASS Rule for --tab tab has expected cssText
FAIL CSSRule.type returns 0 assert_equals: expected 0 but got 21
PASS CSSRule.type returns 0
PASS Rule for --valid returns expected value for CSSPropertyRule.name
PASS Rule for --valid-reverse returns expected value for CSSPropertyRule.name
PASS Rule for --valid-universal returns expected value for CSSPropertyRule.name
Expand Down
11 changes: 11 additions & 0 deletions Source/WebCore/css/CSSRule.cpp
Expand Up @@ -36,6 +36,17 @@ struct SameSizeAsCSSRule : public RefCounted<SameSizeAsCSSRule> {

static_assert(sizeof(CSSRule) == sizeof(SameSizeAsCSSRule), "CSSRule should stay small");

unsigned short CSSRule::typeForCSSOM() const
{
// "This enumeration is thus frozen in its current state, and no new new values will be
// added to reflect additional at-rules; all at-rules beyond the ones listed above will return 0."
// https://drafts.csswg.org/cssom/#the-cssrule-interface
if (styleRuleType() >= firstUnexposedStyleRuleType)
return 0;

return static_cast<unsigned short>(styleRuleType());
}

ExceptionOr<void> CSSRule::setCssText(const String&)
{
return { };
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSRule.h
Expand Up @@ -37,7 +37,7 @@ class CSSRule : public RefCounted<CSSRule> {
public:
virtual ~CSSRule() = default;

unsigned short type() const { return static_cast<unsigned short>(styleRuleType()); }
WEBCORE_EXPORT unsigned short typeForCSSOM() const;

virtual StyleRuleType styleRuleType() const = 0;
virtual String cssText() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/CSSRule.idl
Expand Up @@ -31,7 +31,7 @@
readonly attribute CSSRule? parentRule;
readonly attribute CSSStyleSheet? parentStyleSheet;

readonly attribute unsigned short type;
[ImplementedAs=typeForCSSOM] readonly attribute unsigned short type;

[ImplementedAs=Unknown] const unsigned short UNKNOWN_RULE = 0;
[ImplementedAs=Style] const unsigned short STYLE_RULE = 1;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Expand Up @@ -397,7 +397,7 @@ Ref<MutableStyleProperties> PropertySetCSSStyleDeclaration::copyProperties() con
StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(MutableStyleProperties& propertySet, CSSRule& parentRule)
: PropertySetCSSStyleDeclaration(propertySet)
, m_refCount(1)
, m_parentRuleType(static_cast<StyleRuleType>(parentRule.type()))
, m_parentRuleType(parentRule.styleRuleType())
, m_parentRule(&parentRule)
{
m_propertySet->ref();
Expand Down
10 changes: 6 additions & 4 deletions Source/WebCore/css/StyleRuleType.h
Expand Up @@ -44,13 +44,15 @@ enum class StyleRuleType : uint8_t {
CounterStyle = 11,
Supports = 12,
FontFeatureValues = 14,
// Numbers above 15 are not exposed to the web.
LayerBlock = 16,
LayerStatement = 17,
Container = 18,
FontPaletteValues = 19,
// Those at-rules (@swash, @annotation,...) don't have a specified number in the spec.
LayerStatement,
Container,
FontPaletteValues,
FontFeatureValuesBlock,
Property,
};

static constexpr auto firstUnexposedStyleRuleType = StyleRuleType::LayerBlock;

} // namespace WebCore
Expand Up @@ -196,7 +196,7 @@ gushort webkit_dom_css_rule_get_rule_type(WebKitDOMCSSRule* self)
WebCore::JSMainThreadNullState state;
g_return_val_if_fail(WEBKIT_DOM_IS_CSS_RULE(self), 0);
WebCore::CSSRule* item = WebKit::core(self);
gushort result = item->type();
gushort result = item->typeForCSSOM();
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKitLegacy/mac/DOM/DOMCSSRule.mm
Expand Up @@ -56,7 +56,7 @@ - (void)dealloc
- (unsigned short)type
{
WebCore::JSMainThreadNullState state;
return static_cast<unsigned short>(IMPL->type());
return IMPL->typeForCSSOM();
}

- (NSString *)cssText
Expand Down

0 comments on commit f34b82d

Please sign in to comment.