Title: [293955] trunk/Source/WebCore
Revision
293955
Author
[email protected]
Date
2022-05-07 22:50:00 -0700 (Sat, 07 May 2022)

Log Message

Add helper functions to queue task on Node with GCReachableRef
https://bugs.webkit.org/show_bug.cgi?id=240204

Reviewed by Chris Dumez.

Added Node::queueTaskKeepingThisNodeAlive, which queues a task to the event loop while keeping "this" Node
and its JS wrapper alive, and Node::queueTaskToDispatchEvent, which queues a task to the event loop to
dispatch an event on "this" Node while keeping it and its JS wrapper alive, and deployed them in elements.

* Modules/model-element/HTMLModelElement.cpp:
(WebCore::HTMLModelElement::setSourceURL): Need to disambiguate which queueTaskToDispatchEvent to use
between Node and ActiveDOMObject.
(WebCore::HTMLModelElement::notifyFinished): Ditto.
* dom/Node.cpp:
(WebCore::Node::queueTaskKeepingThisNodeAlive): Added.
(WebCore::Node::queueTaskToDispatchEvent): Added.
* dom/Node.h:
* html/HTMLDetailsElement.cpp:
(WebCore::HTMLDetailsElement::parseAttribute): Use newly added functions.
* html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::close): Ditto.
(WebCore::HTMLDialogElement::queueCancelTask): Ditto.
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::scheduleSelectEvent): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293954 => 293955)


--- trunk/Source/WebCore/ChangeLog	2022-05-08 04:19:36 UTC (rev 293954)
+++ trunk/Source/WebCore/ChangeLog	2022-05-08 05:50:00 UTC (rev 293955)
@@ -1,3 +1,30 @@
+2022-05-07  Ryosuke Niwa  <[email protected]>
+
+        Add helper functions to queue task on Node with GCReachableRef
+        https://bugs.webkit.org/show_bug.cgi?id=240204
+
+        Reviewed by Chris Dumez.
+
+        Added Node::queueTaskKeepingThisNodeAlive, which queues a task to the event loop while keeping "this" Node
+        and its JS wrapper alive, and Node::queueTaskToDispatchEvent, which queues a task to the event loop to
+        dispatch an event on "this" Node while keeping it and its JS wrapper alive, and deployed them in elements.
+
+        * Modules/model-element/HTMLModelElement.cpp:
+        (WebCore::HTMLModelElement::setSourceURL): Need to disambiguate which queueTaskToDispatchEvent to use
+        between Node and ActiveDOMObject.
+        (WebCore::HTMLModelElement::notifyFinished): Ditto.
+        * dom/Node.cpp:
+        (WebCore::Node::queueTaskKeepingThisNodeAlive): Added.
+        (WebCore::Node::queueTaskToDispatchEvent): Added.
+        * dom/Node.h:
+        * html/HTMLDetailsElement.cpp:
+        (WebCore::HTMLDetailsElement::parseAttribute): Use newly added functions.
+        * html/HTMLDialogElement.cpp:
+        (WebCore::HTMLDialogElement::close): Ditto.
+        (WebCore::HTMLDialogElement::queueCancelTask): Ditto.
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::scheduleSelectEvent): Ditto.
+
 2022-05-07  Cameron McCormack  <[email protected]>
 
         Use an OptionSet iterator to skip directly to GraphicsContextState::Change bits to handle

Modified: trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp (293954 => 293955)


--- trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2022-05-08 04:19:36 UTC (rev 293954)
+++ trunk/Source/WebCore/Modules/model-element/HTMLModelElement.cpp	2022-05-08 05:50:00 UTC (rev 293955)
@@ -141,7 +141,7 @@
     m_shouldCreateModelPlayerUponRendererAttachment = false;
 
     if (m_sourceURL.isEmpty()) {
-        queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
+        ActiveDOMObject::queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
         return;
     }
 
@@ -155,7 +155,7 @@
 
     auto resource = document().cachedResourceLoader().requestModelResource(WTFMove(request));
     if (!resource.has_value()) {
-        queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
+        ActiveDOMObject::queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
         if (!m_readyPromise->isFulfilled())
             m_readyPromise->reject(Exception { NetworkError });
         return;
@@ -217,7 +217,7 @@
     if (resource.loadFailedOrCanceled()) {
         m_data.reset();
 
-        queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
+        ActiveDOMObject::queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
 
         invalidateResourceHandleAndUpdateRenderer();
 
@@ -229,7 +229,7 @@
     m_dataComplete = true;
     m_model = Model::create(m_data.takeAsContiguous().get(), resource.mimeType(), resource.url());
 
-    queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().loadEvent, Event::CanBubble::No, Event::IsCancelable::No));
+    ActiveDOMObject::queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().loadEvent, Event::CanBubble::No, Event::IsCancelable::No));
 
     invalidateResourceHandleAndUpdateRenderer();
 

Modified: trunk/Source/WebCore/dom/Node.cpp (293954 => 293955)


--- trunk/Source/WebCore/dom/Node.cpp	2022-05-08 04:19:36 UTC (rev 293954)
+++ trunk/Source/WebCore/dom/Node.cpp	2022-05-08 05:50:00 UTC (rev 293955)
@@ -42,8 +42,10 @@
 #include "ElementTraversal.h"
 #include "EventDispatcher.h"
 #include "EventHandler.h"
+#include "EventLoop.h"
 #include "EventNames.h"
 #include "FrameView.h"
+#include "GCReachableRef.h"
 #include "HTMLAreaElement.h"
 #include "HTMLBodyElement.h"
 #include "HTMLDialogElement.h"
@@ -1309,6 +1311,20 @@
     return options.composed ? shadowIncludingRoot() : rootNode();
 }
 
+void Node::queueTaskKeepingThisNodeAlive(TaskSource source, Function<void ()>&& task)
+{
+    document().eventLoop().queueTask(source, [protectedThis = GCReachableRef(*this), task = WTFMove(task)] () {
+        task();
+    });
+}
+
+void Node::queueTaskToDispatchEvent(TaskSource source, Ref<Event>&& event)
+{
+    queueTaskKeepingThisNodeAlive(source, [protectedThis = Ref { *this }, event = WTFMove(event)]() {
+        protectedThis->dispatchEvent(event);
+    });
+}
+
 Node::InsertedIntoAncestorResult Node::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree)
 {
     if (insertionType.connectedToDocument)

Modified: trunk/Source/WebCore/dom/Node.h (293954 => 293955)


--- trunk/Source/WebCore/dom/Node.h	2022-05-08 04:19:36 UTC (rev 293954)
+++ trunk/Source/WebCore/dom/Node.h	2022-05-08 05:50:00 UTC (rev 293955)
@@ -29,6 +29,7 @@
 #include "LayoutRect.h"
 #include "RenderStyleConstants.h"
 #include "StyleValidity.h"
+#include "TaskSource.h"
 #include "TreeScope.h"
 #include <wtf/CompactPointerTuple.h>
 #include <wtf/CompactUniquePtrTuple.h>
@@ -267,6 +268,9 @@
     
     void* opaqueRoot() const;
 
+    void queueTaskKeepingThisNodeAlive(TaskSource, Function<void ()>&&);
+    void queueTaskToDispatchEvent(TaskSource, Ref<Event>&&);
+
     // Use when it's guaranteed to that shadowHost is null.
     ContainerNode* parentNodeGuaranteedHostFree() const;
     // Returns the parent node, but null if the parent node is a ShadowRoot.

Modified: trunk/Source/WebCore/html/HTMLDetailsElement.cpp (293954 => 293955)


--- trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2022-05-08 04:19:36 UTC (rev 293954)
+++ trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2022-05-08 05:50:00 UTC (rev 293955)
@@ -28,7 +28,6 @@
 #include "ElementRareData.h"
 #include "EventLoop.h"
 #include "EventNames.h"
-#include "GCReachableRef.h"
 #include "HTMLSlotElement.h"
 #include "HTMLSummaryElement.h"
 #include "LocalizedStrings.h"
@@ -148,9 +147,9 @@
             if (m_isToggleEventTaskQueued)
                 return;
 
-            document().eventLoop().queueTask(TaskSource::DOMManipulation, [protectedThis = GCReachableRef { *this }] {
-                protectedThis->dispatchEvent(Event::create(eventNames().toggleEvent, Event::CanBubble::No, Event::IsCancelable::No));
-                protectedThis->m_isToggleEventTaskQueued = false;
+            queueTaskKeepingThisNodeAlive(TaskSource::DOMManipulation, [this] {
+                dispatchEvent(Event::create(eventNames().toggleEvent, Event::CanBubble::No, Event::IsCancelable::No));
+                m_isToggleEventTaskQueued = false;
             });
             m_isToggleEventTaskQueued = true;
         }

Modified: trunk/Source/WebCore/html/HTMLDialogElement.cpp (293954 => 293955)


--- trunk/Source/WebCore/html/HTMLDialogElement.cpp	2022-05-08 04:19:36 UTC (rev 293954)
+++ trunk/Source/WebCore/html/HTMLDialogElement.cpp	2022-05-08 05:50:00 UTC (rev 293955)
@@ -30,7 +30,6 @@
 #include "EventLoop.h"
 #include "EventNames.h"
 #include "FocusOptions.h"
-#include "GCReachableRef.h"
 #include "HTMLNames.h"
 #include "RenderElement.h"
 #include "ScopedEventQueue.h"
@@ -109,18 +108,16 @@
         element->focus(options);
     }
 
-    document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = GCReachableRef { *this }] {
-        protectedThis->dispatchEvent(Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));
-    });
+    queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));
 }
 
 void HTMLDialogElement::queueCancelTask()
 {
-    document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = GCReachableRef { *this }] {
+    queueTaskKeepingThisNodeAlive(TaskSource::UserInteraction, [this] {
         auto cancelEvent = Event::create(eventNames().cancelEvent, Event::CanBubble::No, Event::IsCancelable::Yes);
-        protectedThis->dispatchEvent(cancelEvent);
+        dispatchEvent(cancelEvent);
         if (!cancelEvent->defaultPrevented())
-            protectedThis->close(nullString());
+            close(nullString());
     });
 }
 

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (293954 => 293955)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-05-08 04:19:36 UTC (rev 293954)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-05-08 05:50:00 UTC (rev 293955)
@@ -38,7 +38,6 @@
 #include "EventNames.h"
 #include "Frame.h"
 #include "FrameSelection.h"
-#include "GCReachableRef.h"
 #include "HTMLBRElement.h"
 #include "HTMLFormElement.h"
 #include "HTMLInputElement.h"
@@ -546,9 +545,7 @@
 
 void HTMLTextFormControlElement::scheduleSelectEvent()
 {
-    document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = GCReachableRef { *this }] {
-        protectedThis->dispatchEvent(Event::create(eventNames().selectEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
-    });
+    queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(eventNames().selectEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
 } 
 
 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const AtomString& value)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to