Bug 227915

Summary: Port dialog close event to modern event handling code
Product: WebKit Reporter: Tim Nguyen (:ntim) <ntim>
Component: DOMAssignee: Tim Nguyen (:ntim) <ntim>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, changseok, emilio, esprehn+autocc, ews-watchlist, gyuyoung.kim, rniwa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 227493    
Bug Blocks: 202843, 84635, 228846    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Tim Nguyen (:ntim) 2021-07-13 12:50:26 PDT
Use queueTaskToDispatchEvent()
Comment 1 Radar WebKit Bug Importer 2021-07-13 12:51:02 PDT
<rdar://problem/80533217>
Comment 2 Tim Nguyen (:ntim) 2021-07-19 01:02:18 PDT
Created attachment 433774 [details]
Patch
Comment 3 Emilio Cobos Álvarez (:emilio) 2021-07-19 01:32:19 PDT
Comment on attachment 433774 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433774&action=review

> Source/WebCore/html/HTMLDialogElement.h:55
> +    const char* activeDOMObjectName() const final { return "HTMLMarqueeElement"; }

Copy-pasta from marquee?
Comment 4 Tim Nguyen (:ntim) 2021-07-19 02:30:22 PDT
Created attachment 433779 [details]
Patch
Comment 5 Tim Nguyen (:ntim) 2021-07-19 02:31:11 PDT
(In reply to Emilio Cobos Álvarez (:emilio) from comment #3)
> Comment on attachment 433774 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=433774&action=review
> 
> > Source/WebCore/html/HTMLDialogElement.h:55
> > +    const char* activeDOMObjectName() const final { return "HTMLMarqueeElement"; }
> 
> Copy-pasta from marquee?

Good catch, thanks! I originally did change it, but looks like I accidentally undid the change.
Comment 6 Chris Dumez 2021-07-19 08:29:08 PDT
Comment on attachment 433779 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433779&action=review

> Source/WebCore/html/HTMLDialogElement.cpp:100
> +    queueTaskToDispatchEvent(*this, TaskSource::UserInteraction, Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));

I think we should just call:
```
document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = makeRef(*this)] {
    protectedThis->dispatchEvent(Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));
});
```

> Source/WebCore/html/HTMLDialogElement.h:33
> +class HTMLDialogElement final : public HTMLElement, public ActiveDOMObject {

Subclasses of Node usually do not subclass ActiveDOMObject. ActiveDOMObject is used to manage the lifetime of the JS wrapper but Node has its own wrapper lifetime management in JSNodeCustom.cpp (wrapper stays alive as long as the node is connected + some other conditions).
Comment 7 Ryosuke Niwa 2021-07-19 10:42:13 PDT
Comment on attachment 433779 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433779&action=review

>> Source/WebCore/html/HTMLDialogElement.cpp:100
>> +    queueTaskToDispatchEvent(*this, TaskSource::UserInteraction, Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));
> 
> I think we should just call:
> ```
> document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = makeRef(*this)] {
>     protectedThis->dispatchEvent(Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));
> });
> ```

We need to use GCReachableRef instead since the JS wrapper will be collected by JS if we just use Ref.
Comment 8 Tim Nguyen (:ntim) 2021-07-19 13:26:45 PDT
Created attachment 433818 [details]
Patch
Comment 9 Chris Dumez 2021-07-19 13:30:16 PDT
Comment on attachment 433818 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433818&action=review

r=me with nit. Please make sure the bots are happy before landing.

> Source/WebCore/html/HTMLDialogElement.cpp:93
> +    document().eventLoop().queueTask(TaskSource::UserInteraction, [protectedThis = GCReachableRef<HTMLDialogElement>(*this)] {

With C++17, you can probably write: `protectedThis = GCReachableRef { *this }`
Comment 10 Tim Nguyen (:ntim) 2021-07-19 13:35:29 PDT
Created attachment 433819 [details]
Patch
Comment 11 EWS 2021-07-19 15:01:10 PDT
Committed r280049 (239784@main): <https://commits.webkit.org/239784@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 433819 [details].