Skip to content

Drop CSSSelectorList::next() and port call sites to using modern range loops instead #47131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

cdumez
Copy link
Contributor

@cdumez cdumez commented Jun 24, 2025

ca6229d

Drop CSSSelectorList::next() and port call sites to using modern range loops instead
https://bugs.webkit.org/show_bug.cgi?id=294925

Reviewed by Darin Adler.

Drop CSSSelectorList::next() and port call sites to using modern range loops instead,
to avoid dealing with raw pointers. This also restricts the WTF_ALLOW_UNSAFE_BUFFER_USAGE
to `CSSSelectorList::const_iterator::operator++()`.

* Source/WebCore/css/CSSSelector.cpp:
(WebCore::CSSSelector::visitAllSimpleSelectors const):
* Source/WebCore/css/CSSSelectorList.h:
(WebCore::CSSSelectorList::first const):
(WebCore::CSSSelectorList::indexOfNextSelectorAfter const):
(WebCore::CSSSelectorList::const_iterator::const_iterator):
(WebCore::CSSSelectorList::const_iterator::operator++):
(WebCore::CSSSelectorList::next): Deleted.
* Source/WebCore/css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const):
(WebCore::SelectorChecker::matchSelectorList const):
* Source/WebCore/css/StyleRule.cpp:
(WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):
* Source/WebCore/css/parser/CSSSelectorParser.cpp:
(WebCore::CSSSelectorParser::resolveNestingParent):
* Source/WebCore/css/parser/MutableCSSSelector.cpp:
(WebCore::selectorListMatchesPseudoElement):
* Source/WebCore/dom/SelectorQuery.cpp:
(WebCore::SelectorDataList::SelectorDataList):
* Source/WebCore/inspector/InspectorStyleSheet.cpp:
* Source/WebCore/inspector/agents/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList):
* Source/WebCore/inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::highlightSelector):
* Source/WebCore/style/ElementRuleCollector.cpp:
(WebCore::Style::ElementRuleCollector::scopeRulesMatch):
* Source/WebCore/style/RuleData.cpp:
(WebCore::Style::selectorCanMatchPseudoElement):
(WebCore::Style::determinePropertyAllowlist):
* Source/WebCore/style/RuleFeature.cpp:
(WebCore::Style::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):
(WebCore::Style::RuleFeatureSet::collectFeatures):

Canonical link: https://commits.webkit.org/296627@main

7d817c1

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 🧪 win-tests
✅ 🧪 webkitperl 🧪 ios-wk2 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt 🧪 mac-wk1 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision 🧪 mac-AS-debug-wk2 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ❌ 🛠 playstation
✅ 🛠 tv 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@cdumez cdumez self-assigned this Jun 24, 2025
@cdumez cdumez added the CSS Cascading Style Sheets implementation label Jun 24, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 24, 2025
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label Jun 25, 2025
@cdumez cdumez force-pushed the 294925_drop_CSSSelectorList_next branch from 7cf352a to 48b8d6e Compare June 25, 2025 03:00
@cdumez cdumez marked this pull request as ready for review June 25, 2025 04:55
Copy link
Member

@darinadler darinadler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that I see how these iterators are safer than raw pointers.

const_iterator operator++(int)
{
const_iterator temp = *this;
++(*this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
++(*this);
++*this;

@cdumez
Copy link
Contributor Author

cdumez commented Jun 25, 2025

Not sure that I see how these iterators are safer than raw pointers.

At the moment, not a lot safer, though range loops are more concise and less error-prone. However, it will look into hardening out iterators in the future so it is good to be following consistent patterns across the codebase. Now we have one bottleneck, the iterator operator++() and we could make it bound safe if performance allows.

@cdumez cdumez force-pushed the 294925_drop_CSSSelectorList_next branch from 48b8d6e to 7d817c1 Compare June 25, 2025 17:12
@cdumez cdumez added the merge-queue Applied to send a pull request to merge-queue label Jun 25, 2025
…e loops instead

https://bugs.webkit.org/show_bug.cgi?id=294925

Reviewed by Darin Adler.

Drop CSSSelectorList::next() and port call sites to using modern range loops instead,
to avoid dealing with raw pointers. This also restricts the WTF_ALLOW_UNSAFE_BUFFER_USAGE
to `CSSSelectorList::const_iterator::operator++()`.

* Source/WebCore/css/CSSSelector.cpp:
(WebCore::CSSSelector::visitAllSimpleSelectors const):
* Source/WebCore/css/CSSSelectorList.h:
(WebCore::CSSSelectorList::first const):
(WebCore::CSSSelectorList::indexOfNextSelectorAfter const):
(WebCore::CSSSelectorList::const_iterator::const_iterator):
(WebCore::CSSSelectorList::const_iterator::operator++):
(WebCore::CSSSelectorList::next): Deleted.
* Source/WebCore/css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const):
(WebCore::SelectorChecker::matchSelectorList const):
* Source/WebCore/css/StyleRule.cpp:
(WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount const):
* Source/WebCore/css/parser/CSSSelectorParser.cpp:
(WebCore::CSSSelectorParser::resolveNestingParent):
* Source/WebCore/css/parser/MutableCSSSelector.cpp:
(WebCore::selectorListMatchesPseudoElement):
* Source/WebCore/dom/SelectorQuery.cpp:
(WebCore::SelectorDataList::SelectorDataList):
* Source/WebCore/inspector/InspectorStyleSheet.cpp:
* Source/WebCore/inspector/agents/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList):
* Source/WebCore/inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::highlightSelector):
* Source/WebCore/style/ElementRuleCollector.cpp:
(WebCore::Style::ElementRuleCollector::scopeRulesMatch):
* Source/WebCore/style/RuleData.cpp:
(WebCore::Style::selectorCanMatchPseudoElement):
(WebCore::Style::determinePropertyAllowlist):
* Source/WebCore/style/RuleFeature.cpp:
(WebCore::Style::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):
(WebCore::Style::RuleFeatureSet::collectFeatures):

Canonical link: https://commits.webkit.org/296627@main
@webkit-commit-queue webkit-commit-queue force-pushed the 294925_drop_CSSSelectorList_next branch from 7d817c1 to ca6229d Compare June 25, 2025 18:11
@webkit-commit-queue
Copy link
Collaborator

Committed 296627@main (ca6229d): https://commits.webkit.org/296627@main

Reviewed commits have been landed. Closing PR #47131 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit ca6229d into WebKit:main Jun 25, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Cascading Style Sheets implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants