Bug 221357 - Avoid an ancestor walk in HTMLFormControlElement::computeWillValidate()
Summary: Avoid an ancestor walk in HTMLFormControlElement::computeWillValidate()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-03 13:28 PST by Simon Fraser (smfr)
Modified: 2021-02-03 21:22 PST (History)
11 users (show)

See Also:


Attachments
Patch (8.63 KB, patch)
2021-02-03 13:29 PST, Simon Fraser (smfr)
no flags Details | Formatted Diff | Diff
Patch (8.42 KB, patch)
2021-02-03 17:56 PST, Simon Fraser (smfr)
no flags Details | Formatted Diff | Diff
Patch (8.22 KB, patch)
2021-02-03 20:54 PST, Simon Fraser (smfr)
rniwa: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2021-02-03 13:28:19 PST
Avoid an ancestor walk in HTMLFormControlElement::computeWillValidate()
Comment 1 Simon Fraser (smfr) 2021-02-03 13:29:35 PST
Created attachment 419180 [details]
Patch
Comment 2 Ryosuke Niwa 2021-02-03 14:01:20 PST
Comment on attachment 419180 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=419180&action=review

This is fine but another approach is to create a new node flag like we do for SelfOrAncestorHasDirAuto and set this bit whenever an ancestor has datalist.

> Source/WebCore/dom/Document.h:1331
> +    void addDisabledFieldsetElement() { ++m_disabledFieldsetElementsCount; }

Can we avoid changing the unrelated code?

> Source/WebCore/dom/Document.h:1334
> +    bool hasDataListElements() const { return m_dataListElementCount; }

We should have this in TreeScope instead.
Otherwise, we're gonna have a bad time inside a ShadowRoot.

> Source/WebCore/dom/Element.cpp:2220
> +    auto* page = document().page();
> +    if (page) {

Please define page inside if.

> Source/WebCore/html/HTMLDataListElement.cpp:61
> +    if (parentOfInsertedTree.isInTreeScope())

This isn't right. We're checking that the inserted ancestor's new parent is in a tree scope.
It doesn't mean it's in the document.

Make the change above to move the function to TreeScope and this will be correct
but it's better to check insertionType.treeScopeChanged instead even in that case.

> Source/WebCore/html/HTMLDataListElement.cpp:70
> +    if (oldParentOfRemovedTree.isInTreeScope())
> +        document().decrementDataListElementCount();

Ditto.

> Source/WebCore/html/HTMLDataListElement.cpp:76
> +void HTMLDataListElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
> +{

This function override won't be needed once we made all the changes I suggest above.
Comment 3 Simon Fraser (smfr) 2021-02-03 17:56:19 PST
Created attachment 419212 [details]
Patch
Comment 4 Ryosuke Niwa 2021-02-03 18:37:21 PST
Comment on attachment 419212 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=419212&action=review

> Source/WebCore/ChangeLog:13
> +        * dom/Document.h:
> +        (WebCore::Document::addDisabledFieldsetElement):

Update these change log entries?

> Source/WebCore/html/HTMLDataListElement.cpp:64
> +    if (insertionType.treeScopeChanged)
> +        treeScope().incrementDataListElementCount();

We can do this before calling HTMLElement::insertedIntoAncestor.

> Source/WebCore/page/PointerLockController.cpp:106
> -void PointerLockController::elementRemoved(Element& element)
> +void PointerLockController::elementWasRemoved(Element& element)

Or maybe didRemoveElement?
Comment 5 Simon Fraser (smfr) 2021-02-03 20:54:30 PST
Created attachment 419225 [details]
Patch
Comment 6 Simon Fraser (smfr) 2021-02-03 21:21:32 PST
https://trac.webkit.org/changeset/272358/webkit
Comment 7 Radar WebKit Bug Importer 2021-02-03 21:22:13 PST
<rdar://problem/73964453>