diff options
author | Timothy Gu <timothygu99@gmail.com> | 2018-06-24 23:10:37 -0400 |
---|---|---|
committer | Timothy Gu <timothygu99@gmail.com> | 2018-07-03 22:54:03 -0400 |
commit | f374d6aaf9a2a171c9cd100a4ca2d26a68f72cb8 (patch) | |
tree | de1cf48cf4a77bf4da01fbe04edf8d98356868c4 /test/parallel/test-worker-message-port-transfer-target.js | |
parent | 5f3bdb016a99d102ebafe86424e7761228ef7f70 (diff) | |
download | android-node-v8-f374d6aaf9a2a171c9cd100a4ca2d26a68f72cb8.tar.gz android-node-v8-f374d6aaf9a2a171c9cd100a4ca2d26a68f72cb8.tar.bz2 android-node-v8-f374d6aaf9a2a171c9cd100a4ca2d26a68f72cb8.zip |
messaging: fix edge cases with transferring ports
Currently, transferring the port on which postMessage is called causes a
segmentation fault, and transferring the target port causes a subsequent
port.onmessage setting to throw, or a deadlock if onmessage is set
before the postMessage. Fix both of these behaviors and align the
methods more closely with the normative definitions in the HTML
Standard.
Also, per spec postMessage must not throw just because the ports are
disentangled. Implement that behavior.
PR-URL: https://github.com/nodejs/node/pull/21540
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-worker-message-port-transfer-target.js')
-rw-r--r-- | test/parallel/test-worker-message-port-transfer-target.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/parallel/test-worker-message-port-transfer-target.js b/test/parallel/test-worker-message-port-transfer-target.js new file mode 100644 index 0000000000..8e6354d826 --- /dev/null +++ b/test/parallel/test-worker-message-port-transfer-target.js @@ -0,0 +1,24 @@ +// Flags: --experimental-worker +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { MessageChannel } = require('worker_threads'); + +const { port1, port2 } = new MessageChannel(); + +const arrayBuf = new ArrayBuffer(10); + +common.expectWarning('Warning', + 'The target port was posted to itself, and the ' + + 'communication channel was lost', + common.noWarnCode); +port2.onmessage = common.mustNotCall(); +port2.postMessage(null, [port1, arrayBuf]); + +// arrayBuf must be transferred, despite the fact that port2 never received the +// message. +assert.strictEqual(arrayBuf.byteLength, 0); + +setTimeout(common.mustNotCall('The communication channel is still open'), + common.platformTimeout(1000)).unref(); |