Skip to content
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

PageshowEventPersistence and NodeListInvalidationType should be enum classes #13739

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions Source/WebCore/dom/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3323,7 +3323,7 @@ void Document::implicitClose()
}

dispatchWindowLoadEvent();
dispatchPageshowEvent(PageshowEventNotPersisted);
dispatchPageshowEvent(PageshowEventPersistence::NotPersisted);

if (f)
f->loader().dispatchOnloadEvents();
Expand Down Expand Up @@ -5127,7 +5127,7 @@ void Document::setCSSTarget(Element* newTarget)

void Document::registerNodeListForInvalidation(LiveNodeList& list)
{
m_nodeListAndCollectionCounts[list.invalidationType()]++;
m_nodeListAndCollectionCounts[static_cast<unsigned>(list.invalidationType())]++;
if (!list.isRootedAtTreeScope())
return;
ASSERT(!list.isRegisteredForInvalidationAtDocument());
Expand All @@ -5137,7 +5137,7 @@ void Document::registerNodeListForInvalidation(LiveNodeList& list)

void Document::unregisterNodeListForInvalidation(LiveNodeList& list)
{
m_nodeListAndCollectionCounts[list.invalidationType()]--;
m_nodeListAndCollectionCounts[static_cast<unsigned>(list.invalidationType())]--;
if (!list.isRegisteredForInvalidationAtDocument())
return;

Expand All @@ -5148,15 +5148,15 @@ void Document::unregisterNodeListForInvalidation(LiveNodeList& list)

void Document::registerCollection(HTMLCollection& collection)
{
m_nodeListAndCollectionCounts[collection.invalidationType()]++;
m_nodeListAndCollectionCounts[static_cast<unsigned>(collection.invalidationType())]++;
if (collection.isRootedAtTreeScope())
m_collectionsInvalidatedAtDocument.add(&collection);
}

void Document::unregisterCollection(HTMLCollection& collection)
{
ASSERT(m_nodeListAndCollectionCounts[collection.invalidationType()]);
m_nodeListAndCollectionCounts[collection.invalidationType()]--;
ASSERT(m_nodeListAndCollectionCounts[static_cast<unsigned>(collection.invalidationType())]);
m_nodeListAndCollectionCounts[static_cast<unsigned>(collection.invalidationType())]--;
if (!collection.isRootedAtTreeScope())
return;

Expand All @@ -5166,14 +5166,14 @@ void Document::unregisterCollection(HTMLCollection& collection)
void Document::collectionCachedIdNameMap(const HTMLCollection& collection)
{
ASSERT_UNUSED(collection, collection.hasNamedElementCache());
m_nodeListAndCollectionCounts[InvalidateOnIdNameAttrChange]++;
m_nodeListAndCollectionCounts[static_cast<unsigned>(NodeListInvalidationType::InvalidateOnIdNameAttrChange)]++;
}

void Document::collectionWillClearIdNameMap(const HTMLCollection& collection)
{
ASSERT_UNUSED(collection, collection.hasNamedElementCache());
ASSERT(m_nodeListAndCollectionCounts[InvalidateOnIdNameAttrChange]);
m_nodeListAndCollectionCounts[InvalidateOnIdNameAttrChange]--;
ASSERT(m_nodeListAndCollectionCounts[static_cast<unsigned>(NodeListInvalidationType::InvalidateOnIdNameAttrChange)]);
m_nodeListAndCollectionCounts[static_cast<unsigned>(NodeListInvalidationType::InvalidateOnIdNameAttrChange)]--;
}

void Document::attachNodeIterator(NodeIterator& iterator)
Expand Down Expand Up @@ -7130,7 +7130,7 @@ void Document::dispatchPageshowEvent(PageshowEventPersistence persisted)
return;
m_lastPageStatus = PageStatus::Shown;
// FIXME: https://bugs.webkit.org/show_bug.cgi?id=36334 Pageshow event needs to fire asynchronously.
dispatchWindowEvent(PageTransitionEvent::create(eventNames().pageshowEvent, persisted == PageshowEventPersisted), this);
dispatchWindowEvent(PageTransitionEvent::create(eventNames().pageshowEvent, persisted == PageshowEventPersistence::Persisted), this);
}

void Document::dispatchPagehideEvent(PageshowEventPersistence persisted)
Expand All @@ -7142,7 +7142,7 @@ void Document::dispatchPagehideEvent(PageshowEventPersistence persisted)
if (m_lastPageStatus == PageStatus::Hidden)
return;
m_lastPageStatus = PageStatus::Hidden;
dispatchWindowEvent(PageTransitionEvent::create(eventNames().pagehideEvent, persisted == PageshowEventPersisted), this);
dispatchWindowEvent(PageTransitionEvent::create(eventNames().pagehideEvent, persisted == PageshowEventPersistence::Persisted), this);
}

void Document::enqueueSecurityPolicyViolationEvent(SecurityPolicyViolationEventInit&& eventInit)
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/dom/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ class Scope;
class Update;
}

enum PageshowEventPersistence { PageshowEventNotPersisted, PageshowEventPersisted };
enum class PageshowEventPersistence : bool { NotPersisted, Persisted };

enum NodeListInvalidationType {
enum class NodeListInvalidationType : uint8_t {
DoNotInvalidateOnAttributeChanges,
InvalidateOnClassAttrChange,
InvalidateOnIdNameAttrChange,
Expand All @@ -314,7 +314,7 @@ enum NodeListInvalidationType {
InvalidateOnHRefAttrChange,
InvalidateOnAnyAttrChange,
};
const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
const uint8_t numNodeListInvalidationTypes = static_cast<uint8_t>(NodeListInvalidationType::InvalidateOnAnyAttrChange) + 1;

enum class EventHandlerRemoval { One, All };
using EventTargetSet = HashCountedSet<Node*>;
Expand Down
16 changes: 8 additions & 8 deletions Source/WebCore/dom/LiveNodeListInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ namespace WebCore {
ALWAYS_INLINE bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType type, const QualifiedName& attrName)
{
switch (type) {
case InvalidateOnClassAttrChange:
case NodeListInvalidationType::InvalidateOnClassAttrChange:
return attrName == HTMLNames::classAttr;
case InvalidateOnNameAttrChange:
case NodeListInvalidationType::InvalidateOnNameAttrChange:
return attrName == HTMLNames::nameAttr;
case InvalidateOnIdNameAttrChange:
case NodeListInvalidationType::InvalidateOnIdNameAttrChange:
return attrName == HTMLNames::idAttr || attrName == HTMLNames::nameAttr;
case InvalidateOnForTypeAttrChange:
case NodeListInvalidationType::InvalidateOnForTypeAttrChange:
return attrName == HTMLNames::forAttr || attrName == HTMLNames::typeAttr;
case InvalidateForFormControls:
case NodeListInvalidationType::InvalidateForFormControls:
return attrName == HTMLNames::nameAttr || attrName == HTMLNames::idAttr || attrName == HTMLNames::forAttr
|| attrName == HTMLNames::formAttr || attrName == HTMLNames::typeAttr;
case InvalidateOnHRefAttrChange:
case NodeListInvalidationType::InvalidateOnHRefAttrChange:
return attrName == HTMLNames::hrefAttr;
case DoNotInvalidateOnAttributeChanges:
case NodeListInvalidationType::DoNotInvalidateOnAttributeChanges:
return false;
case InvalidateOnAnyAttrChange:
case NodeListInvalidationType::InvalidateOnAnyAttrChange:
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/NameNodeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace HTMLNames;
WTF_MAKE_ISO_ALLOCATED_IMPL(NameNodeList);

NameNodeList::NameNodeList(ContainerNode& rootNode, const AtomString& name)
: CachedLiveNodeList(rootNode, InvalidateOnNameAttrChange)
: CachedLiveNodeList(rootNode, NodeListInvalidationType::InvalidateOnNameAttrChange)
, m_name(name)
{
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ inline bool Document::shouldInvalidateNodeListAndCollectionCaches() const

inline bool Document::shouldInvalidateNodeListAndCollectionCachesForAttribute(const QualifiedName& attrName) const
{
return shouldInvalidateNodeListCachesForAttr<DoNotInvalidateOnAttributeChanges + 1>(m_nodeListAndCollectionCounts, attrName);
return shouldInvalidateNodeListCachesForAttr<static_cast<uint8_t>(NodeListInvalidationType::DoNotInvalidateOnAttributeChanges) + 1>(m_nodeListAndCollectionCounts, attrName);
}

template <typename InvalidationFunction>
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/history/CachedPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void firePageShowEvent(Page& page)
// This takes care of firing the visibilitychange event and making sure the document is reported as visible.
document->setVisibilityHiddenDueToDismissal(false);

document->dispatchPageshowEvent(PageshowEventPersisted);
document->dispatchPageshowEvent(PageshowEventPersistence::Persisted);
}
}

Expand Down
18 changes: 9 additions & 9 deletions Source/WebCore/html/HTMLCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,32 @@ static NodeListInvalidationType invalidationTypeExcludingIdAndNameAttributes(Col
case CollectionType::SelectOptions:
case CollectionType::MapAreas:
case CollectionType::DocEmpty:
return DoNotInvalidateOnAttributeChanges;
return NodeListInvalidationType::DoNotInvalidateOnAttributeChanges;
case CollectionType::SelectedOptions:
case CollectionType::DataListOptions:
// FIXME: We can do better some day.
return InvalidateOnAnyAttrChange;
return NodeListInvalidationType::InvalidateOnAnyAttrChange;
case CollectionType::ByClass:
return InvalidateOnClassAttrChange;
return NodeListInvalidationType::InvalidateOnClassAttrChange;
case CollectionType::DocAnchors:
return InvalidateOnNameAttrChange;
return NodeListInvalidationType::InvalidateOnNameAttrChange;
case CollectionType::DocLinks:
return InvalidateOnHRefAttrChange;
return NodeListInvalidationType::InvalidateOnHRefAttrChange;
case CollectionType::WindowNamedItems:
case CollectionType::DocumentNamedItems:
case CollectionType::DocumentAllNamedItems:
return InvalidateOnIdNameAttrChange;
return NodeListInvalidationType::InvalidateOnIdNameAttrChange;
case CollectionType::FieldSetElements:
case CollectionType::FormControls:
return InvalidateForFormControls;
return NodeListInvalidationType::InvalidateForFormControls;
}
ASSERT_NOT_REACHED();
return DoNotInvalidateOnAttributeChanges;
return NodeListInvalidationType::DoNotInvalidateOnAttributeChanges;
}

HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type)
: m_collectionType(static_cast<unsigned>(type))
, m_invalidationType(invalidationTypeExcludingIdAndNameAttributes(type))
, m_invalidationType(static_cast<unsigned>(invalidationTypeExcludingIdAndNameAttributes(type)))
, m_rootType(rootTypeFromCollectionType(type))
, m_ownerNode(ownerNode)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/LabelsNodeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace HTMLNames;
WTF_MAKE_ISO_ALLOCATED_IMPL(LabelsNodeList);

LabelsNodeList::LabelsNodeList(HTMLElement& element)
: CachedLiveNodeList(element, InvalidateOnForTypeAttrChange)
: CachedLiveNodeList(element, NodeListInvalidationType::InvalidateOnForTypeAttrChange)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/RadioNodeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using namespace HTMLNames;
WTF_MAKE_ISO_ALLOCATED_IMPL(RadioNodeList);

RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomString& name)
: CachedLiveNodeList(rootNode, InvalidateForFormControls)
: CachedLiveNodeList(rootNode, NodeListInvalidationType::InvalidateForFormControls)
, m_name(name)
, m_isRootedAtTreeScope(is<HTMLFormElement>(rootNode))
{
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/FrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3520,7 +3520,7 @@ void FrameLoader::dispatchUnloadEvents(UnloadEventPolicy unloadEventPolicy)
if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) {
if (unloadEventPolicy == UnloadEventPolicy::UnloadAndPageHide) {
m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide;
m_frame.document()->dispatchPagehideEvent(m_frame.document()->backForwardCacheState() == Document::AboutToEnterBackForwardCache ? PageshowEventPersisted : PageshowEventNotPersisted);
m_frame.document()->dispatchPagehideEvent(m_frame.document()->backForwardCacheState() == Document::AboutToEnterBackForwardCache ? PageshowEventPersistence::Persisted : PageshowEventPersistence::NotPersisted);
}

// This takes care of firing the visibilitychange event and making sure the document is reported as hidden.
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/LocalDOMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void LocalDOMWindow::dispatchAllPendingUnloadEvents()
continue;

if (RefPtr document = window->document())
document->dispatchPagehideEvent(PageshowEventNotPersisted);
document->dispatchPagehideEvent(PageshowEventPersistence::NotPersisted);
window->dispatchEvent(Event::create(eventNames.unloadEvent, Event::CanBubble::No, Event::IsCancelable::No), window->document());

window->enableSuddenTermination();
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/page/ios/FrameIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ static inline NodeQualifier ancestorRespondingToClickEventsNodeQualifier(Securit
return;

Page::forEachDocumentFromMainFrame(*this, [](Document& document) {
document.dispatchPagehideEvent(PageshowEventPersisted);
document.dispatchPagehideEvent(PageshowEventPersistence::Persisted);
});
}

Expand All @@ -658,7 +658,7 @@ static inline NodeQualifier ancestorRespondingToClickEventsNodeQualifier(Securit
return;

Page::forEachDocumentFromMainFrame(*this, [](Document& document) {
document.dispatchPageshowEvent(PageshowEventPersisted);
document.dispatchPageshowEvent(PageshowEventPersistence::Persisted);
});
}

Expand Down