summaryrefslogtreecommitdiff
path: root/lib/internal/worker/io.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-02-13 21:26:59 +0100
committerAnna Henningsen <anna@addaleax.net>2019-02-15 23:16:16 +0100
commit5adda2c44748ace543447da8844b9b08965e402b (patch)
tree9d1b5bd62b76f84da8bc5c8cafe24f877004c9dc /lib/internal/worker/io.js
parenta02e3e2d5f1f96f3c408270d45935afdd5d1fffc (diff)
downloadandroid-node-v8-5adda2c44748ace543447da8844b9b08965e402b.tar.gz
android-node-v8-5adda2c44748ace543447da8844b9b08965e402b.tar.bz2
android-node-v8-5adda2c44748ace543447da8844b9b08965e402b.zip
worker: use fake MessageEvent for port.onmessage
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: https://github.com/nodejs/node/pull/26082 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Diffstat (limited to 'lib/internal/worker/io.js')
-rw-r--r--lib/internal/worker/io.js8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js
index 9aa8c19958..a72868916c 100644
--- a/lib/internal/worker/io.js
+++ b/lib/internal/worker/io.js
@@ -61,11 +61,11 @@ MessagePort.prototype.unref = MessagePortPrototype.unref;
// uv_async_t) which can receive information from other threads and emits
// .onmessage events, and a function used for sending data to a MessagePort
// in some other thread.
-MessagePort.prototype[kOnMessageListener] = function onmessage(payload) {
- if (payload.type !== messageTypes.STDIO_WANTS_MORE_DATA)
- debug(`[${threadId}] received message`, payload);
+MessagePort.prototype[kOnMessageListener] = function onmessage(event) {
+ if (event.data && event.data.type !== messageTypes.STDIO_WANTS_MORE_DATA)
+ debug(`[${threadId}] received message`, event);
// Emit the deserialized object to userland.
- this.emit('message', payload);
+ this.emit('message', event.data);
};
// This is for compatibility with the Web's MessagePort API. It makes sense to