Uh oh!
There was an error while loading. Please reload this page.
worker: use fake MessageEvent for port.onmessage - #26082
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.)
addaleax
commented
Feb 13, 2019
/cc @nodejs/workers @surma |
Uh oh!
There was an error while loading. Please reload this page.
surma
commented
Feb 14, 2019
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:) |
addaleax
commented
Feb 15, 2019
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
julienw
commented
Mar 22, 2019
hey @addaleax, it seems that this changes the api when calling |
surma
commented
Mar 22, 2019
julienw
commented
Mar 22, 2019
Ah I realize that in our code we use |
UziTech
commented
Mar 26, 2019
Just to make it clear, this changes the info passed to |
addaleax
commented
Mar 26, 2019
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