summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-message-port-transfer-target.js
blob: 638591023fb3b1af9497d15153fabc44a8dd86b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'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');
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();