diff options
author | Christopher Jeffrey <chjjeffrey@gmail.com> | 2019-02-01 06:27:04 -0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-09 17:27:05 +0100 |
commit | 2fc759b9b847f5a4beebe7a0ac1616530a919c50 (patch) | |
tree | 5382ff133b217be280b51c2e609f675308cb5689 /test | |
parent | e0a3d741352001d3254adc290763b1bdcbad3ad3 (diff) | |
download | android-node-v8-2fc759b9b847f5a4beebe7a0ac1616530a919c50.tar.gz android-node-v8-2fc759b9b847f5a4beebe7a0ac1616530a919c50.tar.bz2 android-node-v8-2fc759b9b847f5a4beebe7a0ac1616530a919c50.zip |
worker: no throw on property access/postMessage after termination
PR-URL: https://github.com/nodejs/node/pull/25871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-worker-safe-getters.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/parallel/test-worker-safe-getters.js b/test/parallel/test-worker-safe-getters.js new file mode 100644 index 0000000000..23c8de7c7b --- /dev/null +++ b/test/parallel/test-worker-safe-getters.js @@ -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); +} |