test,worker: posting undefined/null message to message port

Related: https://github.com/nodejs/node/issues/26122

PR-URL: https://github.com/nodejs/node/pull/26123
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
legendecas authored and Rod Vagg committed 2019-02-28 23:35:32 +11:00
1 parent a18b847d18
commit db94ab778f
1 file changed
+10 -3
+10 -3
View File
@@ -7,13 +7,20 @@ const { Worker, parentPort } = require('worker_threads');
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
const w = new Worker(__filename);
const expectation = [ 4, undefined, null ];
const actual = [];
w.on('message', common.mustCall((message) => {
assert.strictEqual(message, 4);
w.terminate();
}));
actual.push(message);
if (actual.length === expectation.length) {
assert.deepStrictEqual(expectation, actual);
w.terminate();
}
}, expectation.length));
w.postMessage(2);
} else {
parentPort.onmessage = common.mustCall((message) => {
parentPort.postMessage(message.data * 2);
parentPort.postMessage(undefined);
parentPort.postMessage(null);
});
}