RESOLVED FIXED 240204
Add helper functions to queue task on Node with GCReachableRef
https://bugs.webkit.org/show_bug.cgi?id=240204
Summary Add helper functions to queue task on Node with GCReachableRef
Ryosuke Niwa
Reported 2022-05-07 01:32:55 PDT
Add helper functions to queue an event look task for Node using GCReachableRef.
Attachments
Patch (9.82 KB, patch)
2022-05-07 01:36 PDT, Ryosuke Niwa
no flags
Patch (9.89 KB, patch)
2022-05-07 01:38 PDT, Ryosuke Niwa
no flags
Patch for landing (10.60 KB, patch)
2022-05-07 21:40 PDT, Ryosuke Niwa
ews-feeder: commit-queue-
Ryosuke Niwa
Comment 1 2022-05-07 01:36:18 PDT
Ryosuke Niwa
Comment 2 2022-05-07 01:38:01 PDT
Chris Dumez
Comment 3 2022-05-07 10:46:45 PDT
Comment on attachment 458996 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=458996&action=review I like the idea but have one concern. > Source/WebCore/dom/Node.cpp:1316 > + document().eventLoop().queueTask(source, [protectedThis = GCReachableRef(*this), task = WTFMove(task)] () { Shouldn't this capture `protectedThis = Ref { *this }` too (like ActiveDOMObject::queueTaskKeepingObjectAlive() does)? The function name says it is keeping the Node alive. Currently, what it does is keeping the JS wrapper alive (which it should definitely do). It is true that if the JS wrapper is alive then the impl object would be alive too. However, we've run into trouble making such assumptions in the past because there may not be a wrapper alive when calling queueTaskKeepingThisNodeAlive() and thus constructing the GCReachableRef. Right now, I think the function name is a little bit of a lie. It keeps this node's wrapper alive, not necessarily this node. > Source/WebCore/dom/Node.cpp:1323 > + queueTaskKeepingThisNodeAlive(source, [protectedThis = Ref { *this }, event = WTFMove(event)]() { Assuming queueTaskKeepingThisNodeAlive() is updated to capture protectedThis, I suggest we only capture |this| here. > Source/WebCore/html/HTMLDetailsElement.cpp:150 > + queueTaskKeepingThisNodeAlive(TaskSource::DOMManipulation, [protectedThis = Ref { *this }] { Seems like we shouldn't need to capture protectedThis when calling a function named queueTaskKeepingThisNodeAlive(), if the function is really keeping the Node alive, capturing |this| should suffice. > Source/WebCore/html/HTMLDialogElement.cpp:116 > + queueTaskKeepingThisNodeAlive(TaskSource::UserInteraction, [protectedThis = Ref { *this }] { ditto.
Ryosuke Niwa
Comment 4 2022-05-07 10:55:33 PDT
(In reply to Chris Dumez from comment #3) > Comment on attachment 458996 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=458996&action=review > > I like the idea but have one concern. > > > Source/WebCore/dom/Node.cpp:1316 > > + document().eventLoop().queueTask(source, [protectedThis = GCReachableRef(*this), task = WTFMove(task)] () { > > Shouldn't this capture `protectedThis = Ref { *this }` too (like > ActiveDOMObject::queueTaskKeepingObjectAlive() does)? The function name says > it is keeping the Node alive. Currently, what it does is keeping the JS > wrapper alive (which it should definitely do). > > It is true that if the JS wrapper is alive then the impl object would be > alive too. However, we've run into trouble making such assumptions in the > past because there may not be a wrapper alive when calling > queueTaskKeepingThisNodeAlive() and thus constructing the GCReachableRef. > > Right now, I think the function name is a little bit of a lie. It keeps this > node's wrapper alive, not necessarily this node. Oh, GCReachableRef<Node> contains RefPtr<Node> so it does BOTH. > > Source/WebCore/dom/Node.cpp:1323 > > + queueTaskKeepingThisNodeAlive(source, [protectedThis = Ref { *this }, event = WTFMove(event)]() { > > Assuming queueTaskKeepingThisNodeAlive() is updated to capture > protectedThis, I suggest we only capture |this| here. Yeah, I debated between the two. If we have a compiler validation of captured variables, also explicitly ref'ing here makes sense. As is, I'm triggering a redundant ref call.
Chris Dumez
Comment 5 2022-05-07 13:06:03 PDT
Comment on attachment 458996 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=458996&action=review I'd prefer if we avoided the unnecessary Ref<> captures personally. >>> Source/WebCore/dom/Node.cpp:1316 >>> + document().eventLoop().queueTask(source, [protectedThis = GCReachableRef(*this), task = WTFMove(task)] () { >> >> Shouldn't this capture `protectedThis = Ref { *this }` too (like ActiveDOMObject::queueTaskKeepingObjectAlive() does)? The function name says it is keeping the Node alive. Currently, what it does is keeping the JS wrapper alive (which it should definitely do). >> >> It is true that if the JS wrapper is alive then the impl object would be alive too. However, we've run into trouble making such assumptions in the past because there may not be a wrapper alive when calling queueTaskKeepingThisNodeAlive() and thus constructing the GCReachableRef. >> >> Right now, I think the function name is a little bit of a lie. It keeps this node's wrapper alive, not necessarily this node. > > Oh, GCReachableRef<Node> contains RefPtr<Node> so it does BOTH. Oh, you're totally right, I missed that when I looked at the class earlier.
Ryosuke Niwa
Comment 6 2022-05-07 21:34:39 PDT
(In reply to Chris Dumez from comment #5) > Comment on attachment 458996 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=458996&action=review > > I'd prefer if we avoided the unnecessary Ref<> captures personally. Okay, let's just capture "this" for now.
Ryosuke Niwa
Comment 7 2022-05-07 21:40:32 PDT
Created attachment 459006 [details] Patch for landing
EWS
Comment 8 2022-05-07 22:51:10 PDT
Committed r293955 (250401@main): <https://commits.webkit.org/250401@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 459006 [details].
Radar WebKit Bug Importer
Comment 9 2022-05-07 22:52:13 PDT
Note You need to log in before you can comment on or make changes to this bug.