This is a reland of commit a700450d2a
Reland fixes:
* Include the unsubscription fix in crrev.com/c/5664938
* Move ownership of the context/callback from the Worker to the
PerIsolateData. This means the Worker unconditionally posts
CheckMessageFromWorkerTask, and the main thread decides what to do
with it.
* The worker now always knows its parent isolate, and this is the one
it posts events to. This matches web behaviour.
* Correspondingly, change callback lookup to happen during
CheckMessageFromWorkerTask's execution, rather than at the moment of
posting the CheckMessageFromWorkerTask. This avoids a race between
the main thread subscribing to message events, and the worker
emitting them, by serializing these operations on the main thread.
* We now keep track both of _all_ child workers, and of all child
workers with registered callbacks. This allows keeping the backward
compatible behaviour of not waiting for workers to close, while
allowing the main thread to wait for subscribed workers.
Original change's description:
> [d8] Add support for onmessage from Workers
>
> Add support for Worker.prototype.onmessage, which subscribes the main
> thread Isolate to message events posted by Workers. An isolate's event
> loop will wait until all workers that it has subscribed to have
> terminated (with terminate or close).
>
> Also, onmessage events are supposed to have the message data in a .data
> field on the callback parameter, rather than having the data as the
> parameter itself. So, change the existing Worker onmessage (for posting
> messages _to_ a Worker rather than from it) to send messages like this,
> and update tests to read off the data field from the message they
> receive.
>
> As a cleanup, remove the unused streaming task counter that could also
> make the event loop block.
>
> Change-Id: I205b37131688a237b5bc229dbb2a856dd2390243
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5659938
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Auto-Submit: Leszek Swirski <leszeks@chromium.org>
> Commit-Queue: Leszek Swirski <leszeks@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#94704}
Change-Id: Ieb76e541b9cfc83cb07caa6287050f5c559cbf69
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5666586
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#94747}
This reverts commit a700450d2a.
Reason for revert: Suspected to cause a benchmark hang.
Original change's description:
> [d8] Add support for onmessage from Workers
>
> Add support for Worker.prototype.onmessage, which subscribes the main
> thread Isolate to message events posted by Workers. An isolate's event
> loop will wait until all workers that it has subscribed to have
> terminated (with terminate or close).
>
> Also, onmessage events are supposed to have the message data in a .data
> field on the callback parameter, rather than having the data as the
> parameter itself. So, change the existing Worker onmessage (for posting
> messages _to_ a Worker rather than from it) to send messages like this,
> and update tests to read off the data field from the message they
> receive.
>
> As a cleanup, remove the unused streaming task counter that could also
> make the event loop block.
>
> Change-Id: I205b37131688a237b5bc229dbb2a856dd2390243
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5659938
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Auto-Submit: Leszek Swirski <leszeks@chromium.org>
> Commit-Queue: Leszek Swirski <leszeks@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#94704}
Change-Id: I46df79657bafcc1fd11d8f007d759f730cd26040
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5665572
Owners-Override: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#94727}
Add support for Worker.prototype.onmessage, which subscribes the main
thread Isolate to message events posted by Workers. An isolate's event
loop will wait until all workers that it has subscribed to have
terminated (with terminate or close).
Also, onmessage events are supposed to have the message data in a .data
field on the callback parameter, rather than having the data as the
parameter itself. So, change the existing Worker onmessage (for posting
messages _to_ a Worker rather than from it) to send messages like this,
and update tests to read off the data field from the message they
receive.
As a cleanup, remove the unused streaming task counter that could also
make the event loop block.
Change-Id: I205b37131688a237b5bc229dbb2a856dd2390243
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5659938
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#94704}