-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-worker-error-serdes.js
More file actions
36 lines (32 loc) · 1.2 KB
/
test-worker-error-serdes.js
File metadata and controls
36 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const common = require('../common');
const assert = require('assert');
const { isNativeError } = require('util/types');
const { Worker } = require('worker_threads');
{
const w = new Worker('throw new Error()', { eval: true });
w.on('error', common.mustCall((error) => {
assert(isNativeError(error));
assert.strictEqual(error.constructor, Error);
assert.strictEqual(Object.getPrototypeOf(error), Error.prototype);
}));
}
{
const w = new Worker('throw new RangeError()', { eval: true });
w.on('error', common.mustCall((error) => {
assert(isNativeError(error));
assert.strictEqual(error.constructor, RangeError);
assert.strictEqual(Object.getPrototypeOf(error), RangeError.prototype);
}));
}
{
const w = new Worker('throw new Error(undefined, { cause: new TypeError() })', { eval: true });
w.on('error', common.mustCall((error) => {
assert(isNativeError(error));
assert.strictEqual(error.constructor, Error);
assert.strictEqual(Object.getPrototypeOf(error), Error.prototype);
assert(isNativeError(error.cause));
assert.strictEqual(error.cause.constructor, TypeError);
assert.strictEqual(Object.getPrototypeOf(error.cause), TypeError.prototype);
}));
}