Bug 203960

Summary: Port MessagePort to the HTML5 event loop
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: aakash_jain, ap, dbates, esprehn+autocc, ews-watchlist, ggaren, kangil.han, rniwa, tsavell, webkit-bot-watchers-bugzilla, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=203995
Bug Depends on:    
Bug Blocks: 202843    
Attachments:
Description Flags
Patch rniwa: review+

Description Chris Dumez 2019-11-07 09:09:44 PST
Port MessagePort to the HTML5 event loop.
Comment 1 Chris Dumez 2019-11-07 09:10:25 PST
Created attachment 383055 [details]
Patch
Comment 2 Ryosuke Niwa 2019-11-07 14:04:22 PST
Comment on attachment 383055 [details]
Patch

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

> Source/WebCore/dom/MessagePort.cpp:278
> -            m_eventQueue->enqueueEvent(MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
> +            queueTaskToDispatchEvent(*this, TaskSource::PostedMessage, MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));

Hm... the posted message task source is only used for window post message steps:
https://html.spec.whatwg.org/multipage/web-messaging.html#window-post-message-steps
https://html.spec.whatwg.org/multipage/web-messaging.html#posted-message-task-source

Shouldn't this be port message queue or unshipped port message queue?
https://html.spec.whatwg.org/multipage/web-messaging.html#port-message-queue
Comment 3 Chris Dumez 2019-11-07 14:07:06 PST
Comment on attachment 383055 [details]
Patch

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

>> Source/WebCore/dom/MessagePort.cpp:278
>> +            queueTaskToDispatchEvent(*this, TaskSource::PostedMessage, MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
> 
> Hm... the posted message task source is only used for window post message steps:
> https://html.spec.whatwg.org/multipage/web-messaging.html#window-post-message-steps
> https://html.spec.whatwg.org/multipage/web-messaging.html#posted-message-task-source
> 
> Shouldn't this be port message queue or unshipped port message queue?
> https://html.spec.whatwg.org/multipage/web-messaging.html#port-message-queue

Looks like you're right, the spec says:
"Add a task that runs the following steps to the port message queue of targetPort:"

How do you propose I match the spec though?
Comment 4 Ryosuke Niwa 2019-11-07 14:09:15 PST
(In reply to Chris Dumez from comment #3)
> Comment on attachment 383055 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=383055&action=review
> 
> >> Source/WebCore/dom/MessagePort.cpp:278
> >> +            queueTaskToDispatchEvent(*this, TaskSource::PostedMessage, MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
> > 
> > Hm... the posted message task source is only used for window post message steps:
> > https://html.spec.whatwg.org/multipage/web-messaging.html#window-post-message-steps
> > https://html.spec.whatwg.org/multipage/web-messaging.html#posted-message-task-source
> > 
> > Shouldn't this be port message queue or unshipped port message queue?
> > https://html.spec.whatwg.org/multipage/web-messaging.html#port-message-queue
> 
> Looks like you're right, the spec says:
> "Add a task that runs the following steps to the port message queue of
> targetPort:"
> 
> How do you propose I match the spec though?

I think we just add TaskSource type of PostMessageQueue. Maybe add a comment saying that the spec says each port has its own task source but we coalesce into one. Because HTML5 event loop spec allows whatever task source to be picked, this is okay for our implementation.
Comment 5 Chris Dumez 2019-11-07 15:16:13 PST
Committed r252209: <https://trac.webkit.org/changeset/252209>
Comment 6 Radar WebKit Bug Importer 2019-11-07 15:17:19 PST
<rdar://problem/57000643>
Comment 7 Aakash Jain 2019-11-08 07:07:24 PST
(In reply to Chris Dumez from comment #5)
> Committed r252209: <https://trac.webkit.org/changeset/252209>
This likely caused layout Test fast/workers/worker-close-more.html to fail. Tracked in https://bugs.webkit.org/show_bug.cgi?id=203995
Comment 8 Truitt Savell 2019-11-08 08:10:20 PST
(In reply to Aakash Jain from comment #7)
> (In reply to Chris Dumez from comment #5)
> > Committed r252209: <https://trac.webkit.org/changeset/252209>
> This likely caused layout Test fast/workers/worker-close-more.html to fail.
> Tracked in https://bugs.webkit.org/show_bug.cgi?id=203995

I was able to reproduce this by just running the test. It fails on 252209 but not on 252208