Skip to content

Commit

Permalink
Skip repeated sanitizeValue call
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269618
rdar://123118619

Reviewed by Ryosuke Niwa.

Based on Ryosuke's patch, we clean up Element::parserSetAttributes and avoid repeated sanitizeValue calls.
When we are creating HTMLInputElement from parser, we do not need to update type and value in attributeChanged.
They are already initialized correctly in parserSetAttributes.

* Source/WebCore/dom/Element.cpp:
(WebCore::Element::parserSetAttributes):
(WebCore::Element::parserDidSetAttributes): Deleted.
* Source/WebCore/dom/Element.h:
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parserInitializeInputType):
(WebCore::HTMLInputElement::attributeChanged):
(WebCore::HTMLInputElement::initializeInputType): Deleted.
(WebCore::HTMLInputElement::parserDidSetAttributes): Deleted.
* Source/WebCore/html/HTMLInputElement.h:

Canonical link: https://commits.webkit.org/274904@main
  • Loading branch information
Constellation committed Feb 17, 2024
1 parent 6303dc5 commit bda7fd8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
13 changes: 6 additions & 7 deletions Source/WebCore/dom/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include "HTMLDialogElement.h"
#include "HTMLDocument.h"
#include "HTMLHtmlElement.h"
#include "HTMLInputElement.h"
#include "HTMLLabelElement.h"
#include "HTMLNameCollection.h"
#include "HTMLObjectElement.h"
Expand Down Expand Up @@ -2546,18 +2547,16 @@ void Element::parserSetAttributes(std::span<const Attribute> attributes)
m_elementData = sharedObjectPool->cachedShareableElementDataWithAttributes(attributes);
else
m_elementData = ShareableElementData::createWithAttributes(attributes);

}

parserDidSetAttributes();
if (auto* inputElement = dynamicDowncast<HTMLInputElement>(*this)) {
DelayedUpdateValidityScope delayedUpdateValidityScope(*inputElement);
inputElement->parserInitializeInputType();
}

// Use attributes instead of m_elementData because attributeChanged might modify m_elementData.
for (const auto& attribute : attributes)
notifyAttributeChanged(attribute.name(), nullAtom(), attribute.value(), AttributeModificationReason::Directly);
}

void Element::parserDidSetAttributes()
{
notifyAttributeChanged(attribute.name(), nullAtom(), attribute.value(), AttributeModificationReason::Parser);
}

void Element::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/dom/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class Element : public ContainerNode {
// For exposing to DOM only.
WEBCORE_EXPORT NamedNodeMap& attributes() const;

enum class AttributeModificationReason : bool { Directly, ByCloning };
enum class AttributeModificationReason : uint8_t { Directly, ByCloning, Parser };
// This function is called whenever an attribute is added, changed or removed.
// Do not call this function directly. notifyAttributeChanged() should be used instead
// in order to update state dependent on attribute changes.
Expand Down Expand Up @@ -778,7 +778,6 @@ class Element : public ContainerNode {
void removedFromAncestor(RemovalType, ContainerNode&) override;
void childrenChanged(const ChildChange&) override;
void removeAllEventListeners() override;
virtual void parserDidSetAttributes();

void setTabIndexExplicitly(std::optional<int>);

Expand Down
14 changes: 5 additions & 9 deletions Source/WebCore/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ void HTMLInputElement::collectPresentationalHintsForAttribute(const QualifiedNam
}
}

inline void HTMLInputElement::initializeInputType()
void HTMLInputElement::parserInitializeInputType()
{
ASSERT(m_parsingInProgress);
ASSERT(!m_inputType);
Expand Down Expand Up @@ -785,9 +785,13 @@ void HTMLInputElement::attributeChanged(const QualifiedName& name, const AtomStr

switch (name.nodeName()) {
case AttributeNames::typeAttr:
if (attributeModificationReason == AttributeModificationReason::Parser)
return; // parserSetAttributes have taken care of this
updateType(newValue);
break;
case AttributeNames::valueAttr:
if (attributeModificationReason == AttributeModificationReason::Parser)
return; // parserSetAttributes have taken care of this
// Changes to the value attribute may change whether or not this element has a default value.
// If this field is autocomplete=off that might affect the return value of needsSuspensionCallback.
if (m_autocomplete == Off) {
Expand Down Expand Up @@ -912,14 +916,6 @@ bool HTMLInputElement::supportsReadOnly() const
return m_inputType->supportsReadOnly();
}

void HTMLInputElement::parserDidSetAttributes()
{
DelayedUpdateValidityScope delayedUpdateValidityScope(*this);

ASSERT(m_parsingInProgress);
initializeInputType();
}

void HTMLInputElement::finishParsingChildren()
{
m_parsingInProgress = false;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/HTMLInputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ class HTMLInputElement : public HTMLTextFormControlElement {
bool isSwitchVisuallyOn() const;
float switchAnimationPressedProgress() const;

void parserInitializeInputType();

protected:
HTMLInputElement(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser);

Expand Down Expand Up @@ -389,7 +391,6 @@ class HTMLInputElement : public HTMLTextFormControlElement {
void attributeChanged(const QualifiedName&, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason = AttributeModificationReason::Directly) final;
bool hasPresentationalHintsForAttribute(const QualifiedName&) const final;
void collectPresentationalHintsForAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) final;
void parserDidSetAttributes() final;

void copyNonAttributePropertiesFromElement(const Element&) final;

Expand Down Expand Up @@ -432,7 +433,6 @@ class HTMLInputElement : public HTMLTextFormControlElement {
bool computeWillValidate() const final;
void requiredStateChanged() final;

void initializeInputType();
void updateType(const AtomString& typeAttributeValue);
void runPostTypeUpdateTasks();

Expand Down

0 comments on commit bda7fd8

Please sign in to comment.