Title: [243929] trunk/Source
Revision
243929
Author
rn...@webkit.org
Date
2019-04-05 01:22:39 -0700 (Fri, 05 Apr 2019)

Log Message

Make WeakPtr<Element> possible and deploy it in form associated elements code
https://bugs.webkit.org/show_bug.cgi?id=196626

Reviewed by Antti Koivisto.

Source/WebCore:

Make Element inherit from CanMakeWeakPtr and deploy WeakPtr<*Element> in FormAssociatedElement and HTMLFormElement.

No new tests sine there should be no behavioral change.

* dom/Element.h:
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::FormAssociatedElement):
(WebCore::FormAssociatedElement::insertedIntoAncestor):
(WebCore::FormAssociatedElement::setForm):
(WebCore::FormAssociatedElement::resetFormOwner):
(WebCore::FormAssociatedElement::formAttributeChanged):
* html/FormAssociatedElement.h:
(WebCore::FormAssociatedElement::form const):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::asFormNamedItem):
(WebCore::HTMLElement::asFormAssociatedElement):
* html/HTMLElement.h:
(WebCore::HTMLElement::asFormNamedItem): Deleted.
* html/HTMLFormControlElement.h:
* html/HTMLFormControlsCollection.cpp:
(WebCore::HTMLFormControlsCollection::formImageElements const): Inlined into updateNamedElementCache.
(WebCore::HTMLFormControlsCollection::updateNamedElementCache const):
* html/HTMLFormControlsCollection.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::registerInvalidAssociatedFormControl):
(WebCore::HTMLFormElement::removeInvalidAssociatedFormControlIfNeeded):
(WebCore::HTMLFormElement::registerImgElement):
(WebCore::HTMLFormElement::defaultButton const):
(WebCore::HTMLFormElement::resetDefaultButton):
(WebCore::HTMLFormElement::matchesValidPseudoClass const):
(WebCore::HTMLFormElement::matchesInvalidPseudoClass const):
* html/HTMLFormElement.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::HTMLImageElement):
(WebCore::HTMLImageElement::insertedIntoAncestor):
* html/HTMLImageElement.h:
* html/HTMLInputElement.h:
* html/HTMLMediaElement.h:
* html/HTMLObjectElement.h:
* html/HTMLPictureElement.h:
* html/HTMLSlotElement.h:
* svg/SVGElement.h:

Source/WTF:

Make it possible to call WeakHashSet::remove and WeakHashSet::contains with
a subclass type U of a type T used to define WeakReference<T>.

Also added computesEmpty, which is slightly more efficient than computeSize
when m_set is either empty or when there are non-released weak references in the set.

* wtf/WeakHashSet.h:
(WTF::WeakHashSet::remove):
(WTF::WeakHashSet::contains const):
(WTF::WeakHashSet::computesEmpty const): Added.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (243928 => 243929)


--- trunk/Source/WTF/ChangeLog	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WTF/ChangeLog	2019-04-05 08:22:39 UTC (rev 243929)
@@ -1,3 +1,21 @@
+2019-04-05  Ryosuke Niwa  <rn...@webkit.org>
+
+        Make WeakPtr<Element> possible and deploy it in form associated elements code
+        https://bugs.webkit.org/show_bug.cgi?id=196626
+
+        Reviewed by Antti Koivisto.
+
+        Make it possible to call WeakHashSet::remove and WeakHashSet::contains with
+        a subclass type U of a type T used to define WeakReference<T>.
+
+        Also added computesEmpty, which is slightly more efficient than computeSize
+        when m_set is either empty or when there are non-released weak references in the set.
+
+        * wtf/WeakHashSet.h:
+        (WTF::WeakHashSet::remove):
+        (WTF::WeakHashSet::contains const):
+        (WTF::WeakHashSet::computesEmpty const): Added.
+
 2019-04-04  Yusuke Suzuki  <ysuz...@apple.com>
 
         [WebCore] Put most of derived classes of ScriptWrappable into IsoHeap

Modified: trunk/Source/WTF/wtf/WeakHashSet.h (243928 => 243929)


--- trunk/Source/WTF/wtf/WeakHashSet.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WTF/wtf/WeakHashSet.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -91,17 +91,19 @@
         m_set.add(*makeWeakPtr(value).m_ref);
     }
 
-    void remove(const T& value)
+    template <typename U>
+    bool remove(const U& value)
     {
-        auto* weakReference = value.weakPtrFactory().m_ref.get();
+        auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get());
         if (!weakReference)
-            return;
-        m_set.remove(weakReference);
+            return false;
+        return m_set.remove(weakReference);
     }
 
-    bool contains(const T& value) const
+    template <typename U>
+    bool contains(const U& value) const
     {
-        auto* weakReference = value.weakPtrFactory().m_ref.get();
+        auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get());
         if (!weakReference)
             return false;
         return m_set.contains(weakReference);
@@ -109,6 +111,17 @@
 
     unsigned capacity() const { return m_set.capacity(); }
 
+    bool computesEmpty() const
+    {
+        if (m_set.isEmpty())
+            return true;
+        for (auto& value : m_set) {
+            if (value->get())
+                return false;
+        }
+        return true;
+    }
+
     unsigned computeSize() const
     {
         const_cast<WeakReferenceSet&>(m_set).removeIf([] (auto& value) { return !value->get(); });

Modified: trunk/Source/WebCore/ChangeLog (243928 => 243929)


--- trunk/Source/WebCore/ChangeLog	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/ChangeLog	2019-04-05 08:22:39 UTC (rev 243929)
@@ -1,3 +1,53 @@
+2019-04-05  Ryosuke Niwa  <rn...@webkit.org>
+
+        Make WeakPtr<Element> possible and deploy it in form associated elements code
+        https://bugs.webkit.org/show_bug.cgi?id=196626
+
+        Reviewed by Antti Koivisto.
+
+        Make Element inherit from CanMakeWeakPtr and deploy WeakPtr<*Element> in FormAssociatedElement and HTMLFormElement.
+
+        No new tests sine there should be no behavioral change.
+
+        * dom/Element.h:
+        * html/FormAssociatedElement.cpp:
+        (WebCore::FormAssociatedElement::FormAssociatedElement):
+        (WebCore::FormAssociatedElement::insertedIntoAncestor):
+        (WebCore::FormAssociatedElement::setForm):
+        (WebCore::FormAssociatedElement::resetFormOwner):
+        (WebCore::FormAssociatedElement::formAttributeChanged):
+        * html/FormAssociatedElement.h:
+        (WebCore::FormAssociatedElement::form const):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::asFormNamedItem):
+        (WebCore::HTMLElement::asFormAssociatedElement):
+        * html/HTMLElement.h:
+        (WebCore::HTMLElement::asFormNamedItem): Deleted.
+        * html/HTMLFormControlElement.h:
+        * html/HTMLFormControlsCollection.cpp:
+        (WebCore::HTMLFormControlsCollection::formImageElements const): Inlined into updateNamedElementCache.
+        (WebCore::HTMLFormControlsCollection::updateNamedElementCache const):
+        * html/HTMLFormControlsCollection.h:
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::registerInvalidAssociatedFormControl):
+        (WebCore::HTMLFormElement::removeInvalidAssociatedFormControlIfNeeded):
+        (WebCore::HTMLFormElement::registerImgElement):
+        (WebCore::HTMLFormElement::defaultButton const):
+        (WebCore::HTMLFormElement::resetDefaultButton):
+        (WebCore::HTMLFormElement::matchesValidPseudoClass const):
+        (WebCore::HTMLFormElement::matchesInvalidPseudoClass const):
+        * html/HTMLFormElement.h:
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::HTMLImageElement):
+        (WebCore::HTMLImageElement::insertedIntoAncestor):
+        * html/HTMLImageElement.h:
+        * html/HTMLInputElement.h:
+        * html/HTMLMediaElement.h:
+        * html/HTMLObjectElement.h:
+        * html/HTMLPictureElement.h:
+        * html/HTMLSlotElement.h:
+        * svg/SVGElement.h:
+
 2019-04-05  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [ATK] Use a smart pointer for AccessibilityObject wrapper and remove GTK specific code

Modified: trunk/Source/WebCore/dom/Element.h (243928 => 243929)


--- trunk/Source/WebCore/dom/Element.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/dom/Element.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -77,7 +77,7 @@
 enum class TouchAction : uint8_t;
 #endif
 
-class Element : public ContainerNode {
+class Element : public ContainerNode , public CanMakeWeakPtr<Element> {
     WTF_MAKE_ISO_ALLOCATED(Element);
 public:
     static Ref<Element> create(const QualifiedName&, Document&);

Modified: trunk/Source/WebCore/html/FormAssociatedElement.cpp (243928 => 243929)


--- trunk/Source/WebCore/html/FormAssociatedElement.cpp	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/FormAssociatedElement.cpp	2019-04-05 08:22:39 UTC (rev 243929)
@@ -52,7 +52,7 @@
 
 FormAssociatedElement::FormAssociatedElement(HTMLFormElement* form)
     : m_form(nullptr)
-    , m_formSetByParser(form)
+    , m_formSetByParser(makeWeakPtr(form))
 {
 }
 
@@ -74,7 +74,7 @@
     if (m_formSetByParser) {
         // The form could have been removed by a script during parsing.
         if (m_formSetByParser->isConnected())
-            setForm(m_formSetByParser);
+            setForm(m_formSetByParser.get());
         m_formSetByParser = nullptr;
     }
 
@@ -146,9 +146,9 @@
     willChangeForm();
     if (m_form)
         m_form->removeFormElement(this);
-    m_form = newForm;
-    if (m_form)
-        m_form->registerFormElement(this);
+    m_form = makeWeakPtr(newForm);
+    if (newForm)
+        newForm->registerFormElement(this);
     didChangeForm();
 }
 
@@ -172,10 +172,11 @@
 
 void FormAssociatedElement::resetFormOwner()
 {
-    RefPtr<HTMLFormElement> originalForm = m_form;
-    setForm(findAssociatedForm(&asHTMLElement(), m_form));
+    RefPtr<HTMLFormElement> originalForm = m_form.get();
+    setForm(findAssociatedForm(&asHTMLElement(), originalForm.get()));
     HTMLElement& element = asHTMLElement();
-    if (m_form && m_form != originalForm && m_form->isConnected())
+    auto* newForm = m_form.get();
+    if (newForm && newForm != originalForm && newForm->isConnected())
         element.document().didAssociateFormControl(element);
 }
 
@@ -184,9 +185,11 @@
     HTMLElement& element = asHTMLElement();
     if (!element.hasAttributeWithoutSynchronization(formAttr)) {
         // The form attribute removed. We need to reset form owner here.
-        RefPtr<HTMLFormElement> originalForm = m_form;
+        RefPtr<HTMLFormElement> originalForm = m_form.get();
+        // FIXME: Why does this not pass originalForm to findClosestFormAncestor?
         setForm(HTMLFormElement::findClosestFormAncestor(element));
-        if (m_form && m_form != originalForm && m_form->isConnected())
+        auto* newForm = m_form.get();
+        if (newForm && newForm != originalForm && newForm->isConnected())
             element.document().didAssociateFormControl(element);
         m_formAttributeTargetObserver = nullptr;
     } else {

Modified: trunk/Source/WebCore/html/FormAssociatedElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/FormAssociatedElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/FormAssociatedElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -25,6 +25,7 @@
 
 #include "FormNamedItem.h"
 #include "Node.h"
+#include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -47,7 +48,7 @@
     void deref() { derefFormAssociatedElement(); }
 
     static HTMLFormElement* findAssociatedForm(const HTMLElement*, HTMLFormElement*);
-    HTMLFormElement* form() const { return m_form; }
+    HTMLFormElement* form() const { return m_form.get(); }
     ValidityState* validity();
 
     virtual bool isFormControlElement() const = 0;
@@ -117,8 +118,8 @@
     bool isFormAssociatedElement() const final { return true; }
 
     std::unique_ptr<FormAttributeTargetObserver> m_formAttributeTargetObserver;
-    HTMLFormElement* m_form;
-    HTMLFormElement* m_formSetByParser;
+    WeakPtr<HTMLFormElement> m_form;
+    WeakPtr<HTMLFormElement> m_formSetByParser;
     String m_customValidationMessage;
 };
 

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2019-04-05 08:22:39 UTC (rev 243929)
@@ -762,6 +762,16 @@
     return HTMLFormElement::findClosestFormAncestor(*this);
 }
 
+FormNamedItem* HTMLElement::asFormNamedItem()
+{
+    return nullptr;
+}
+
+FormAssociatedElement* HTMLElement::asFormAssociatedElement()
+{
+    return nullptr;
+}
+
 static inline bool elementAffectsDirectionality(const Node& node)
 {
     if (!is<HTMLElement>(node))

Modified: trunk/Source/WebCore/html/HTMLElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -32,6 +32,7 @@
 namespace WebCore {
 
 class DocumentFragment;
+class FormAssociatedElement;
 class FormNamedItem;
 class HTMLCollection;
 class HTMLFormElement;
@@ -88,7 +89,8 @@
     bool willRespondToMouseClickEvents() override;
 
     virtual bool isLabelable() const { return false; }
-    virtual FormNamedItem* asFormNamedItem() { return 0; }
+    virtual FormNamedItem* asFormNamedItem();
+    virtual FormAssociatedElement* asFormAssociatedElement();
 
     bool hasTagName(const HTMLQualifiedName& name) const { return hasLocalName(name.localName()); }
 

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -175,7 +175,8 @@
 
     HTMLElement& asHTMLElement() final { return *this; }
     const HTMLFormControlElement& asHTMLElement() const final { return *this; }
-    HTMLFormControlElement* asFormNamedItem() final { return this; }
+    FormNamedItem* asFormNamedItem() final { return this; }
+    FormAssociatedElement* asFormAssociatedElement() final { return this; }
 
     bool needsMouseFocusableQuirk() const;
 

Modified: trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLFormControlsCollection.cpp	2019-04-05 08:22:39 UTC (rev 243929)
@@ -75,11 +75,6 @@
     return ownerNode().copyAssociatedElementsVector();
 }
 
-const Vector<HTMLImageElement*>& HTMLFormControlsCollection::formImageElements() const
-{
-    return ownerNode().imageElements();
-}
-
 static unsigned findFormAssociatedElement(const Vector<FormAssociatedElement*>& elements, const Element& element)
 {
     for (unsigned i = 0; i < elements.size(); ++i) {
@@ -145,7 +140,9 @@
         }
     }
 
-    for (auto* elementPtr : formImageElements()) {
+    for (auto& elementPtr : ownerNode().imageElements()) {
+        if (!elementPtr)
+            continue;
         HTMLImageElement& element = *elementPtr;
         const AtomicString& id = element.getIdAttribute();
         if (!id.isEmpty() && !foundInputElements.contains(id.impl()))

Modified: trunk/Source/WebCore/html/HTMLFormControlsCollection.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLFormControlsCollection.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLFormControlsCollection.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -56,7 +56,6 @@
 
     const Vector<FormAssociatedElement*>& unsafeFormControlElements() const;
     Vector<Ref<FormAssociatedElement>> copyFormControlElementsVector() const;
-    const Vector<HTMLImageElement*>& formImageElements() const;
 
     mutable Element* m_cachedElement;
     mutable unsigned m_cachedElementOffsetInArray;

Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLFormElement.cpp	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp	2019-04-05 08:22:39 UTC (rev 243929)
@@ -566,15 +566,15 @@
     ASSERT_WITH_MESSAGE(!is<HTMLFieldSetElement>(formControlElement), "FieldSet are never candidates for constraint validation.");
     ASSERT(static_cast<const Element&>(formControlElement).matchesInvalidPseudoClass());
 
-    if (m_invalidAssociatedFormControls.isEmpty())
+    if (m_invalidAssociatedFormControls.computesEmpty())
         invalidateStyleForSubtree();
-    m_invalidAssociatedFormControls.add(&formControlElement);
+    m_invalidAssociatedFormControls.add(const_cast<HTMLFormControlElement&>(formControlElement));
 }
 
 void HTMLFormElement::removeInvalidAssociatedFormControlIfNeeded(const HTMLFormControlElement& formControlElement)
 {
-    if (m_invalidAssociatedFormControls.remove(&formControlElement)) {
-        if (m_invalidAssociatedFormControls.isEmpty())
+    if (m_invalidAssociatedFormControls.remove(formControlElement)) {
+        if (m_invalidAssociatedFormControls.computesEmpty())
             invalidateStyleForSubtree();
     }
 }
@@ -587,7 +587,7 @@
 void HTMLFormElement::registerImgElement(HTMLImageElement* e)
 {
     ASSERT(m_imageElements.find(e) == notFound);
-    m_imageElements.append(e);
+    m_imageElements.append(makeWeakPtr(e));
 }
 
 void HTMLFormElement::removeImgElement(HTMLImageElement* e)
@@ -681,18 +681,18 @@
 
 HTMLFormControlElement* HTMLFormElement::defaultButton() const
 {
-    if (!m_defaultButton) {
-        for (auto& associatedElement : m_associatedElements) {
-            if (!is<HTMLFormControlElement>(*associatedElement))
-                continue;
-            HTMLFormControlElement& control = downcast<HTMLFormControlElement>(*associatedElement);
-            if (control.isSuccessfulSubmitButton()) {
-                m_defaultButton = &control;
-                break;
-            }
+    if (m_defaultButton)
+        return m_defaultButton.get();
+    for (auto& associatedElement : m_associatedElements) {
+        if (!is<HTMLFormControlElement>(*associatedElement))
+            continue;
+        HTMLFormControlElement& control = downcast<HTMLFormControlElement>(*associatedElement);
+        if (control.isSuccessfulSubmitButton()) {
+            m_defaultButton = makeWeakPtr(control);
+            return &control;
         }
     }
-    return m_defaultButton;
+    return nullptr;
 }
 
 void HTMLFormElement::resetDefaultButton()
@@ -706,8 +706,7 @@
 
     ScriptDisallowedScope::InMainThread scriptDisallowedScope;
 
-    auto* oldDefault = m_defaultButton;
-    m_defaultButton = nullptr;
+    auto oldDefault = WTFMove(m_defaultButton);
     defaultButton();
     if (m_defaultButton != oldDefault) {
         if (oldDefault)
@@ -810,12 +809,12 @@
 
 bool HTMLFormElement::matchesValidPseudoClass() const
 {
-    return m_invalidAssociatedFormControls.isEmpty();
+    return m_invalidAssociatedFormControls.computesEmpty();
 }
 
 bool HTMLFormElement::matchesInvalidPseudoClass() const
 {
-    return !m_invalidAssociatedFormControls.isEmpty();
+    return !matchesValidPseudoClass();
 }
 
 // FIXME: Use Ref<HTMLElement> for the function result since there are no non-HTML elements returned here.

Modified: trunk/Source/WebCore/html/HTMLFormElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLFormElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLFormElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -28,6 +28,7 @@
 #include "HTMLElement.h"
 #include "RadioButtonGroups.h"
 #include <memory>
+#include <wtf/WeakHashSet.h>
 
 #if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE)
 #include "Autocapitalize.h"
@@ -119,7 +120,7 @@
 
     WEBCORE_EXPORT const Vector<FormAssociatedElement*>& unsafeAssociatedElements() const;
     Vector<Ref<FormAssociatedElement>> copyAssociatedElementsVector() const;
-    const Vector<HTMLImageElement*>& imageElements() const { return m_imageElements; }
+    const Vector<WeakPtr<HTMLImageElement>>& imageElements() const { return m_imageElements; }
 
     StringPairVector textFieldValues() const;
 
@@ -172,13 +173,13 @@
     std::unique_ptr<PastNamesMap> m_pastNamesMap;
 
     RadioButtonGroups m_radioButtonGroups;
-    mutable HTMLFormControlElement* m_defaultButton { nullptr };
+    mutable WeakPtr<HTMLFormControlElement> m_defaultButton;
 
     unsigned m_associatedElementsBeforeIndex { 0 };
     unsigned m_associatedElementsAfterIndex { 0 };
     Vector<FormAssociatedElement*> m_associatedElements;
-    Vector<HTMLImageElement*> m_imageElements;
-    HashSet<const HTMLFormControlElement*> m_invalidAssociatedFormControls;
+    Vector<WeakPtr<HTMLImageElement>> m_imageElements;
+    WeakHashSet<HTMLFormControlElement> m_invalidAssociatedFormControls;
 
     bool m_wasUserSubmitted { false };
     bool m_isSubmittingOrPreparingForSubmission { false };

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2019-04-05 08:22:39 UTC (rev 243929)
@@ -71,7 +71,7 @@
     : HTMLElement(tagName, document)
     , m_imageLoader(*this)
     , m_form(nullptr)
-    , m_formSetByParser(form)
+    , m_formSetByParser(makeWeakPtr(form))
     , m_compositeOperator(CompositeSourceOver)
     , m_imageDevicePixelRatio(1.0f)
 #if ENABLE(SERVICE_CONTROLS)
@@ -330,8 +330,7 @@
 Node::InsertedIntoAncestorResult HTMLImageElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree)
 {
     if (m_formSetByParser) {
-        m_form = m_formSetByParser;
-        m_formSetByParser = nullptr;
+        m_form = WTFMove(m_formSetByParser);
         m_form->registerImgElement(this);
     }
 
@@ -341,9 +340,10 @@
     }
 
     if (!m_form) {
-        m_form = HTMLFormElement::findClosestFormAncestor(*this);
-        if (m_form)
-            m_form->registerImgElement(this);
+        if (auto* newForm = HTMLFormElement::findClosestFormAncestor(*this)) {
+            m_form = makeWeakPtr(newForm);
+            newForm->registerImgElement(this);
+        }
     }
 
     // Insert needs to complete first, before we start updating the loader. Loader dispatches events which could result

Modified: trunk/Source/WebCore/html/HTMLImageElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLImageElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLImageElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -173,8 +173,8 @@
 #endif
 
     HTMLImageLoader m_imageLoader;
-    HTMLFormElement* m_form;
-    HTMLFormElement* m_formSetByParser;
+    WeakPtr<HTMLFormElement> m_form;
+    WeakPtr<HTMLFormElement> m_formSetByParser;
 
     CompositeOperator m_compositeOperator;
     AtomicString m_bestFitImageURL;

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -54,7 +54,7 @@
     RefPtr<HTMLInputElement> checkedRadioButton;
 };
 
-class HTMLInputElement : public HTMLTextFormControlElement, public CanMakeWeakPtr<HTMLInputElement> {
+class HTMLInputElement : public HTMLTextFormControlElement {
     WTF_MAKE_ISO_ALLOCATED(HTMLInputElement);
 public:
     static Ref<HTMLInputElement> create(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser);

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -126,7 +126,6 @@
     : public HTMLElement
     , public ActiveDOMObject
     , public MediaControllerInterface
-    , public CanMakeWeakPtr<HTMLMediaElement>
     , public PlatformMediaSessionClient
     , private MediaCanStartListener
     , private MediaPlayerClient

Modified: trunk/Source/WebCore/html/HTMLObjectElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLObjectElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLObjectElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -91,6 +91,7 @@
     void derefFormAssociatedElement() final { deref(); }
 
     FormNamedItem* asFormNamedItem() final { return this; }
+    FormAssociatedElement* asFormAssociatedElement() final { return this; }
     HTMLObjectElement& asHTMLElement() final { return *this; }
     const HTMLObjectElement& asHTMLElement() const final { return *this; }
 

Modified: trunk/Source/WebCore/html/HTMLPictureElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLPictureElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLPictureElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-class HTMLPictureElement final : public HTMLElement, public CanMakeWeakPtr<HTMLPictureElement> {
+class HTMLPictureElement final : public HTMLElement {
     WTF_MAKE_ISO_ALLOCATED(HTMLPictureElement);
 public:
     static Ref<HTMLPictureElement> create(const QualifiedName&, Document&);

Modified: trunk/Source/WebCore/html/HTMLSlotElement.h (243928 => 243929)


--- trunk/Source/WebCore/html/HTMLSlotElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/html/HTMLSlotElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-class HTMLSlotElement final : public HTMLElement, public CanMakeWeakPtr<HTMLSlotElement> {
+class HTMLSlotElement final : public HTMLElement {
     WTF_MAKE_ISO_ALLOCATED(HTMLSlotElement);
 public:
     static Ref<HTMLSlotElement> create(const QualifiedName&, Document&);

Modified: trunk/Source/WebCore/svg/SVGElement.h (243928 => 243929)


--- trunk/Source/WebCore/svg/SVGElement.h	2019-04-05 07:35:24 UTC (rev 243928)
+++ trunk/Source/WebCore/svg/SVGElement.h	2019-04-05 08:22:39 UTC (rev 243929)
@@ -47,7 +47,7 @@
 
 void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, CSSPropertyID>* propertyNameToIdMap, const QualifiedName& attrName);
 
-class SVGElement : public StyledElement, public SVGLangSpace, public SVGPropertyOwner, public CanMakeWeakPtr<SVGElement> {
+class SVGElement : public StyledElement, public SVGLangSpace, public SVGPropertyOwner {
     WTF_MAKE_ISO_ALLOCATED(SVGElement);
 public:
     bool isOutermostSVGSVGElement() const;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to