mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
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: https://github.com/nodejs/node/issues/35506 Signed-off-by: dobbydobap <varshitha.kolupuri@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64365 Fixes: https://github.com/nodejs/node/issues/35506 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
26 lines
785 B
JavaScript
26 lines
785 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
const cases = [
|
|
{ code: 'throw "boom";', value: 'boom' },
|
|
{ code: 'throw 42;', value: 42 },
|
|
{ code: 'throw 7n;', value: 7n },
|
|
{ code: 'throw true;', value: true },
|
|
{ code: 'throw null;', value: null },
|
|
{ code: 'throw undefined;', value: undefined },
|
|
{ code: 'throw Symbol.for("a");', value: Symbol.for('a') },
|
|
];
|
|
|
|
for (const { code, value } of cases) {
|
|
const worker = new Worker(code, { eval: true });
|
|
worker.on('message', common.mustNotCall());
|
|
worker.on('error', common.mustCall((err) => {
|
|
assert.strictEqual(err, value);
|
|
}));
|
|
worker.on('exit', common.mustCall((exitCode) => {
|
|
assert.strictEqual(exitCode, 1);
|
|
}));
|
|
}
|