Skip to content

Commit 9a139b3

Browse files
dobbydobapaduh95
authored andcommitted
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> PR-URL: #64365Fixes: #35506 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent d3cada5 commit 9a139b3

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+
constcommon=require('../common');
3+
constassert=require('assert');
4+
const{ Worker }=require('worker_threads');
5+
6+
constcases=[
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 }ofcases){
17+
constworker=newWorker(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)