Title: [280829] releases/WebKitGTK/webkit-2.32/Source/WebCore
Revision
280829
Author
[email protected]
Date
2021-08-10 02:19:23 -0700 (Tue, 10 Aug 2021)

Log Message

Merge r273935 - "precustomized" state of custom elements can become HTMLUnknownElement
https://bugs.webkit.org/show_bug.cgi?id=221652

Reviewed by Darin Adler.

The bug was caused by createJSHTMLWrapper in JSHTMLElementWrapperFactory.cpp relying on
!isCustomElementUpgradeCandidate() to create HTMLUnknownElement as JS wrapper of the element.

This is problematic after r266269 since that change re-purposes CustomElementState::Failed
on a custom element as "precustomized" state instead of introducing another enum value in
CustomElementState as RareDataBitFields has no more bits available.

This patch fixes the problem by introducing a new NodeFlag::IsUnknownElement and using that
to check whether JSHTMLUnknownElement should be created for a given element or not. Note that
HTMLElement had a virtual function, isHTMLUnknownElement, to check this condition but invoking
a virtual function proved to incur too much runtime cost.

* dom/Node.h:
(WebCore::Node::isUnknownElement const): Added.
(WebCore::Node::isHTMLUnknownElement const): Added.
(WebCore::Node::isSVGUnknownElement const): Added.
(WebCore::Node::isMathMLUnknownElement const): Added.
(WebCore::Node::NodeFlag): Added NodeFlag::IsUnknownElement.
* dom/make_names.pl:
(printWrapperFactoryCppFile): Treat the element as HTMLUnknownElement only if isUnknownElement
returns true instead of isCustomElementUpgradeCandidate returning false.
* html/HTMLElement.h:
(WebCore::HTMLElement::isHTMLUnknownElement const): Deleted.
* html/HTMLUnknownElement.h:
* mathml/MathMLElement.cpp:
(WebCore::MathMLElement::MathMLElement): Added ConstructionType as an argument.
* mathml/MathMLElement.h:
* mathml/MathMLUnknownElement.h:
(WebCore::MathMLUnknownElement::MathMLUnknownElement): Set NodeFlag::IsUnknownElement.
* svg/SVGElement.cpp:
(WebCore::SVGElement::SVGElement): Added ConstructionType as an argument.
* svg/SVGElement.h:
* svg/SVGUnknownElement.h:
(WebCore::SVGUnknownElement::SVGUnknownElement): Set NodeFlag::IsUnknownElement.

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog	2021-08-10 09:19:23 UTC (rev 280829)
@@ -1,3 +1,45 @@
+2021-03-04  Ryosuke Niwa  <[email protected]>
+
+        "precustomized" state of custom elements can become HTMLUnknownElement
+        https://bugs.webkit.org/show_bug.cgi?id=221652
+
+        Reviewed by Darin Adler.
+
+        The bug was caused by createJSHTMLWrapper in JSHTMLElementWrapperFactory.cpp relying on
+        !isCustomElementUpgradeCandidate() to create HTMLUnknownElement as JS wrapper of the element.
+
+        This is problematic after r266269 since that change re-purposes CustomElementState::Failed
+        on a custom element as "precustomized" state instead of introducing another enum value in
+        CustomElementState as RareDataBitFields has no more bits available.
+
+        This patch fixes the problem by introducing a new NodeFlag::IsUnknownElement and using that
+        to check whether JSHTMLUnknownElement should be created for a given element or not. Note that
+        HTMLElement had a virtual function, isHTMLUnknownElement, to check this condition but invoking
+        a virtual function proved to incur too much runtime cost.
+
+        * dom/Node.h:
+        (WebCore::Node::isUnknownElement const): Added.
+        (WebCore::Node::isHTMLUnknownElement const): Added.
+        (WebCore::Node::isSVGUnknownElement const): Added.
+        (WebCore::Node::isMathMLUnknownElement const): Added.
+        (WebCore::Node::NodeFlag): Added NodeFlag::IsUnknownElement.
+        * dom/make_names.pl:
+        (printWrapperFactoryCppFile): Treat the element as HTMLUnknownElement only if isUnknownElement
+        returns true instead of isCustomElementUpgradeCandidate returning false.
+        * html/HTMLElement.h:
+        (WebCore::HTMLElement::isHTMLUnknownElement const): Deleted.
+        * html/HTMLUnknownElement.h:
+        * mathml/MathMLElement.cpp:
+        (WebCore::MathMLElement::MathMLElement): Added ConstructionType as an argument.
+        * mathml/MathMLElement.h:
+        * mathml/MathMLUnknownElement.h:
+        (WebCore::MathMLUnknownElement::MathMLUnknownElement): Set NodeFlag::IsUnknownElement.
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::SVGElement): Added ConstructionType as an argument.
+        * svg/SVGElement.h:
+        * svg/SVGUnknownElement.h:
+        (WebCore::SVGUnknownElement::SVGUnknownElement): Set NodeFlag::IsUnknownElement.
+
 2021-03-01  Chris Dumez  <[email protected]>
 
         Protect AudioWorkletGlobalScope::registerProcessor() against re-entry

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/Node.h (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/Node.h	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/Node.h	2021-08-10 09:19:23 UTC (rev 280829)
@@ -193,6 +193,11 @@
     bool isSVGElement() const { return hasNodeFlag(NodeFlag::IsSVGElement); }
     bool isMathMLElement() const { return hasNodeFlag(NodeFlag::IsMathMLElement); }
 
+    bool isUnknownElement() const { return hasNodeFlag(NodeFlag::IsUnknownElement); }
+    bool isHTMLUnknownElement() const { return isHTMLElement() && isUnknownElement(); }
+    bool isSVGUnknownElement() const { return isSVGElement() && isUnknownElement(); }
+    bool isMathMLUnknownElement() const { return isMathMLElement() && isUnknownElement(); }
+
     bool isPseudoElement() const { return pseudoId() != PseudoId::None; }
     bool isBeforePseudoElement() const { return pseudoId() == PseudoId::Before; }
     bool isAfterPseudoElement() const { return pseudoId() == PseudoId::After; }
@@ -535,8 +540,8 @@
         IsShadowRoot = 1 << 9,
         IsConnected = 1 << 10,
         IsInShadowTree = 1 << 11,
-        HasEventTargetData = 1 << 12,
-        // UnusedFlag = 1 << 13,
+        IsUnknownElement = 1 << 12,
+        HasEventTargetData = 1 << 13,
 
         // These bits are used by derived classes, pulled up here so they can
         // be stored in the same memory word as the Node bits above.

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/make_names.pl (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/make_names.pl	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/make_names.pl	2021-08-10 09:19:23 UTC (rev 280829)
@@ -1277,12 +1277,19 @@
 
     if ($parameters{customElementInterfaceName}) {
         print F <<END
-    if (element->isCustomElementUpgradeCandidate())
+    if (!element->isUnknownElement())
         return createWrapper<$parameters{customElementInterfaceName}>(globalObject, WTFMove(element));
 END
 ;
     }
 
+    if ("$parameters{namespace}Element" eq $parameters{fallbackJSInterfaceName}) {
+        print F <<END
+    ASSERT(element->is$parameters{fallbackJSInterfaceName}());
+END
+;
+    }
+
     print F <<END
     return createWrapper<$parameters{fallbackJSInterfaceName}>(globalObject, WTFMove(element));
 }

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/html/HTMLElement.h (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/html/HTMLElement.h	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/html/HTMLElement.h	2021-08-10 09:19:23 UTC (rev 280829)
@@ -86,7 +86,6 @@
     bool hasDirectionAuto() const;
     TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
 
-    virtual bool isHTMLUnknownElement() const { return false; }
     virtual bool isTextControlInnerTextElement() const { return false; }
 
     bool willRespondToMouseMoveEvents() override;

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/html/HTMLUnknownElement.h (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/html/HTMLUnknownElement.h	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/html/HTMLUnknownElement.h	2021-08-10 09:19:23 UTC (rev 280829)
@@ -43,11 +43,9 @@
 
 private:
     HTMLUnknownElement(const QualifiedName& tagName, Document& document)
-        : HTMLElement(tagName, document, CreateHTMLElement)
+        : HTMLElement(tagName, document, CreateHTMLElement | NodeFlag::IsUnknownElement)
     {
     }
-
-    bool isHTMLUnknownElement() const final { return true; }
 };
 
 } // namespace WebCore

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLElement.cpp (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLElement.cpp	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLElement.cpp	2021-08-10 09:19:23 UTC (rev 280829)
@@ -50,8 +50,8 @@
 
 using namespace MathMLNames;
 
-MathMLElement::MathMLElement(const QualifiedName& tagName, Document& document)
-    : StyledElement(tagName, document, CreateMathMLElement)
+MathMLElement::MathMLElement(const QualifiedName& tagName, Document& document, ConstructionType constructionType)
+    : StyledElement(tagName, document, constructionType)
 {
 }
 

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLElement.h (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLElement.h	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLElement.h	2021-08-10 09:19:23 UTC (rev 280829)
@@ -90,7 +90,7 @@
     virtual void updateSelectedChild() { }
 
 protected:
-    MathMLElement(const QualifiedName& tagName, Document&);
+    MathMLElement(const QualifiedName& tagName, Document&, ConstructionType = CreateMathMLElement);
 
     void parseAttribute(const QualifiedName&, const AtomString&) override;
     bool childShouldCreateRenderer(const Node&) const override;

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLUnknownElement.h (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLUnknownElement.h	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/mathml/MathMLUnknownElement.h	2021-08-10 09:19:23 UTC (rev 280829)
@@ -41,7 +41,7 @@
 
 private:
     MathMLUnknownElement(const QualifiedName& tagName, Document& document)
-        : MathMLElement(tagName, document)
+        : MathMLElement(tagName, document, CreateMathMLElement | NodeFlag::IsUnknownElement)
     {
     }
 

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGElement.cpp (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGElement.cpp	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGElement.cpp	2021-08-10 09:19:23 UTC (rev 280829)
@@ -155,8 +155,8 @@
     return map;
 }
 
-SVGElement::SVGElement(const QualifiedName& tagName, Document& document)
-    : StyledElement(tagName, document, CreateSVGElement)
+SVGElement::SVGElement(const QualifiedName& tagName, Document& document, ConstructionType constructionType)
+    : StyledElement(tagName, document, constructionType)
     , m_propertyAnimatorFactory(makeUnique<SVGPropertyAnimatorFactory>())
 {
     static std::once_flag onceFlag;

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGElement.h (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGElement.h	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGElement.h	2021-08-10 09:19:23 UTC (rev 280829)
@@ -147,7 +147,7 @@
     SVGAnimatedString& classNameAnimated() { return m_className; }
 
 protected:
-    SVGElement(const QualifiedName&, Document&);
+    SVGElement(const QualifiedName&, Document&, ConstructionType = CreateSVGElement);
     virtual ~SVGElement();
 
     bool rendererIsNeeded(const RenderStyle&) override;

Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGUnknownElement.h (280828 => 280829)


--- releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGUnknownElement.h	2021-08-10 08:57:20 UTC (rev 280828)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/svg/SVGUnknownElement.h	2021-08-10 09:19:23 UTC (rev 280829)
@@ -45,7 +45,7 @@
 
 private:
     SVGUnknownElement(const QualifiedName& tagName, Document& document)
-        : SVGElement(tagName, document)
+        : SVGElement(tagName, document, CreateSVGElement | NodeFlag::IsUnknownElement)
     {
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to