summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-message-port.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 /test/parallel/test-worker-message-port.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 'test/parallel/test-worker-message-port.js')
-rw-r--r--test/parallel/test-worker-message-port.js5
1 files changed, 3 insertions, 2 deletions
diff --git a/test/parallel/test-worker-message-port.js b/test/parallel/test-worker-message-port.js
index 47a8ddf665..dce9da0b30 100644
--- a/test/parallel/test-worker-message-port.js
+++ b/test/parallel/test-worker-message-port.js
@@ -21,14 +21,15 @@ const { MessageChannel, MessagePort } = require('worker_threads');
const { port1, port2 } = new MessageChannel();
port1.onmessage = common.mustCall((message) => {
- assert.strictEqual(message, 4);
+ assert.strictEqual(message.data, 4);
+ assert.strictEqual(message.target, port1);
port2.close(common.mustCall());
});
port1.postMessage(2);
port2.onmessage = common.mustCall((message) => {
- port2.postMessage(message * 2);
+ port2.postMessage(message.data * 2);
});
}