-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: no throw on property access/postMessage after termination
PR-URL: #25871 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const { Worker, isMainThread } = require('worker_threads'); | ||
|
||
if (isMainThread) { | ||
const w = new Worker(__filename, { | ||
stdin: true, | ||
stdout: true, | ||
stderr: true | ||
}); | ||
|
||
w.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0); | ||
|
||
// `postMessage` should not throw after termination | ||
// (this mimics the browser behavior). | ||
w.postMessage('foobar'); | ||
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); | ||
})); | ||
} else { | ||
process.exit(0); | ||
} |