diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 6d833bcbd271fb..f43a9610495ac0 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -171,7 +171,6 @@ class Worker extends EventEmitter { this[kPublicPort] = null; const { stdout, stderr } = this[kParentSideStdio]; - this[kParentSideStdio] = null; if (!stdout._readableState.ended) { debug(`[${threadId}] explicitly closes stdout for ${this.threadId}`); @@ -221,20 +220,14 @@ class Worker extends EventEmitter { } get stdin() { - if (this[kParentSideStdio] === null) return null; - return this[kParentSideStdio].stdin; } get stdout() { - if (this[kParentSideStdio] === null) return null; - return this[kParentSideStdio].stdout; } get stderr() { - if (this[kParentSideStdio] === null) return null; - return this[kParentSideStdio].stderr; } } diff --git a/test/parallel/test-worker-safe-getters.js b/test/parallel/test-worker-safe-getters.js index 23c8de7c7b0cfb..69856659a5773b 100644 --- a/test/parallel/test-worker-safe-getters.js +++ b/test/parallel/test-worker-safe-getters.js @@ -12,6 +12,8 @@ if (isMainThread) { stderr: true }); + const { stdin, stdout, stderr } = w; + w.on('exit', common.mustCall((code) => { assert.strictEqual(code, 0); @@ -21,17 +23,11 @@ if (isMainThread) { w.ref(); w.unref(); - // Although not browser specific, probably wise to - // make sure the stream getters don't throw either. - w.stdin; - w.stdout; - w.stderr; - // Sanity check. assert.strictEqual(w.threadId, -1); - assert.strictEqual(w.stdin, null); - assert.strictEqual(w.stdout, null); - assert.strictEqual(w.stderr, null); + assert.strictEqual(w.stdin, stdin); + assert.strictEqual(w.stdout, stdout); + assert.strictEqual(w.stderr, stderr); })); } else { process.exit(0);