worker: use fake MessageEvent for port.onmessage#26082
worker: use fake MessageEvent for port.onmessage#26082addaleax wants to merge 1 commit intonodejs:masterfrom
Conversation
Instead of passing the payload for Workers directly to `.onmessage`, perform something more similar to what the browser API provides, namely create an event object with a `.data` property. This does not make `MessagePort` implement the `EventTarget` API, nor does it implement the full `MessageEvent` API, but it would make such extensions non-breaking changes if we desire them at some point in the future. (This would be a breaking change if Workers were not experimental. Currently, this method is also undocumented and only exists with the idea of enabling some degree of Web compatibility.)
|
/cc @nodejs/workers @surma |
|
I can't comment much on the implementation, but I'm very supportive of the event-ish object for easier web interop and future-proofing the API. Thanks for doing this, @addaleax! |
|
CI: https://ci.nodejs.org/job/node-test-pull-request/20782/ (:heavy_check_mark:) |
|
Landed in 5adda2c |
Instead of passing the payload for Workers directly to `.onmessage`, perform something more similar to what the browser API provides, namely create an event object with a `.data` property. This does not make `MessagePort` implement the `EventTarget` API, nor does it implement the full `MessageEvent` API, but it would make such extensions non-breaking changes if we desire them at some point in the future. (This would be a breaking change if Workers were not experimental. Currently, this method is also undocumented and only exists with the idea of enabling some degree of Web compatibility.) PR-URL: #26082 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Instead of passing the payload for Workers directly to `.onmessage`, perform something more similar to what the browser API provides, namely create an event object with a `.data` property. This does not make `MessagePort` implement the `EventTarget` API, nor does it implement the full `MessageEvent` API, but it would make such extensions non-breaking changes if we desire them at some point in the future. (This would be a breaking change if Workers were not experimental. Currently, this method is also undocumented and only exists with the idea of enabling some degree of Web compatibility.) PR-URL: #26082 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Instead of passing the payload for Workers directly to `.onmessage`, perform something more similar to what the browser API provides, namely create an event object with a `.data` property. This does not make `MessagePort` implement the `EventTarget` API, nor does it implement the full `MessageEvent` API, but it would make such extensions non-breaking changes if we desire them at some point in the future. (This would be a breaking change if Workers were not experimental. Currently, this method is also undocumented and only exists with the idea of enabling some degree of Web compatibility.) PR-URL: #26082 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Notable Changes
* n-api:
* Implement date object (Jarrod Connolly)
#25917
* util:
* Add compact depth mode for `util.inspect()` (Ruben Bridgewater)
#26269
* worker:
* Improve integration with native addons (Anna Henningsen)
#26175
* MessagePort.prototype.onmessage takes arguments closer to the Web
specification now (Anna Henningsen)
#26082
Notable Changes
* n-api:
* Implement date object (Jarrod Connolly)
nodejs#25917
* util:
* Add compact depth mode for `util.inspect()` (Ruben Bridgewater)
nodejs#26269
* worker:
* Improve integration with native addons (Anna Henningsen)
nodejs#26175
* MessagePort.prototype.onmessage takes arguments closer to the Web
specification now (Anna Henningsen)
nodejs#26082
|
hey @addaleax, it seems that this changes the api when calling |
|
Ah I realize that in our code we use |
|
Just to make it clear, this changes the info passed to |
Yes, exactly. |
Instead of passing the payload for Workers directly to
.onmessage,perform something more similar to what the browser API provides,
namely create an event object with a
.dataproperty.This does not make
MessagePortimplement theEventTargetAPI, nordoes it implement the full
MessageEventAPI, but it would makesuch extensions non-breaking changes if we desire them at
some point in the future.
(This would be a breaking change if Workers were not experimental.
Currently, this method is also undocumented and only exists with
the idea of enabling some degree of Web compatibility.)
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes