Skip to content

Commit dcd552d

Browse files
committed
test: cover worker throwing primitive values
A worker that throws a non-Error value (string, number, bigint, boolean, null, undefined) surfaces that value on the parent's 'error' handler. This was reported as a wrapped ERR_UNHANDLED_ERROR and is now correct, but had no regression coverage. Refs: #35506 Signed-off-by: dobbydobap <varshitha.kolupuri@gmail.com>
1 parent 8e1ab55 commit dcd552d

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { Worker } = require('worker_threads');
5+
6+
const cases = [
7+
{ code: 'throw "boom";', value: 'boom' },
8+
{ code: 'throw 42;', value: 42 },
9+
{ code: 'throw 7n;', value: 7n },
10+
{ code: 'throw true;', value: true },
11+
{ code: 'throw null;', value: null },
12+
{ code: 'throw undefined;', value: undefined },
13+
{ code: 'throw Symbol.for("a");', value: Symbol.for('a') },
14+
];
15+
16+
for (const { code, value } of cases) {
17+
const worker = new Worker(code, { eval: true });
18+
worker.on('message', common.mustNotCall());
19+
worker.on('error', common.mustCall((err) => {
20+
assert.strictEqual(err, value);
21+
}));
22+
worker.on('exit', common.mustCall((exitCode) => {
23+
assert.strictEqual(exitCode, 1);
24+
}));
25+
}

0 commit comments

Comments
 (0)