worker: remove redundant function call to setupPortReferencing

There is no need to call `setupPortReferencing` in `setupChild`
as which has been called with the same arguments in the `oninit`
prototype method of `MessagePort`.

PR-URL: https://github.com/nodejs/node/pull/22298
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ouyang Yadong 2018-08-20 13:38:27 +08:00 committed by Anna Henningsen
parent bf5cc3bf1a
commit 3b5c9926e9
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 25 additions and 1 deletions

View File

@ -408,7 +408,6 @@ function setupChild(evalScript) {
if (message.type === messageTypes.LOAD_SCRIPT) {
const { filename, doEval, workerData, publicPort, hasStdin } = message;
publicWorker.parentPort = publicPort;
setupPortReferencing(publicPort, publicPort, 'message');
publicWorker.workerData = workerData;
if (!hasStdin)

View File

@ -0,0 +1,25 @@
// Flags: --experimental-worker
'use strict';
const assert = require('assert');
const common = require('../common');
const { isMainThread, parentPort, Worker } = require('worker_threads');
// This test makes sure that we manipulate the references of
// `parentPort` correctly so that any worker threads will
// automatically exit when there are no any other references.
{
if (isMainThread) {
const worker = new Worker(__filename);
worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}), 1);
worker.on('online', common.mustCall());
} else {
const messageCallback = () => {};
parentPort.on('message', messageCallback);
// The thread won't exit if we don't make the 'message' listener off.
parentPort.off('message', messageCallback);
}
}