Skip to content

Commit 89c79b5

Browse files
committed
src: ERR_ILLEGAL_CONSTRUCTOR thrown from c++ had the wrong constructor
1 parent e1ab0d1 commit 89c79b5

8 files changed

+26
-3
lines changed

src/node_errors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
8282
V(ERR_FS_CP_SOCKET, Error) \
8383
V(ERR_FS_CP_FIFO_PIPE, Error) \
8484
V(ERR_FS_CP_UNKNOWN, Error) \
85-
V(ERR_ILLEGAL_CONSTRUCTOR, Error) \
85+
V(ERR_ILLEGAL_CONSTRUCTOR, TypeError) \
8686
V(ERR_INVALID_ADDRESS, Error) \
8787
V(ERR_INVALID_ARG_VALUE, TypeError) \
8888
V(ERR_OSSL_EVP_INVALID_DIGEST, Error) \

test/parallel/test-abortcontroller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ test('AbortSignal is impossible to construct manually', () => {
8181
// Tests that AbortSignal is impossible to construct manually
8282
const ac = new AbortController();
8383
throws(() => new ac.signal.constructor(), {
84+
name: 'TypeError',
8485
code: 'ERR_ILLEGAL_CONSTRUCTOR',
8586
});
8687
});

test/parallel/test-sqlite-statement-sync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ suite('StatementSync() constructor', () => {
1919
t.assert.throws(() => {
2020
new StatementSync();
2121
}, {
22+
name: 'TypeError',
2223
code: 'ERR_ILLEGAL_CONSTRUCTOR',
23-
message: /Illegal constructor/,
24+
message: 'Illegal constructor',
2425
});
2526
});
2627
});

test/parallel/test-timers-promises-scheduler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ async function testCancelableWait2() {
5151
testCancelableWait2().then(common.mustCall());
5252

5353
throws(() => new scheduler.constructor(), {
54+
name: 'TypeError',
5455
code: 'ERR_ILLEGAL_CONSTRUCTOR',
5556
});

test/parallel/test-webcrypto-keygen.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,10 @@ const vectors = {
611611
}
612612

613613
// End user code cannot create CryptoKey directly
614-
assert.throws(() => new CryptoKey(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
614+
assert.throws(() => new CryptoKey(), {
615+
name: 'TypeError',
616+
code: 'ERR_ILLEGAL_CONSTRUCTOR',
617+
});
615618

616619
{
617620
const buffer = Buffer.from('Hello World');

test/parallel/test-webstorage.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ function nextLocalStorage() {
1414
return join(tmpdir.path, `${++cnt}.localstorage`);
1515
}
1616

17+
test('constructor is illegal', async () => {
18+
const cp = await spawnPromisified(process.execPath, [
19+
'--experimental-webstorage',
20+
'--localstorage-file', nextLocalStorage(),
21+
'-e', 'new Storage',
22+
]);
23+
assert.strictEqual(cp.code, 1);
24+
assert.strictEqual(cp.signal, null);
25+
assert.strictEqual(cp.stdout, '');
26+
assert(cp.stderr.includes(`TypeError: Illegal constructor\n`));
27+
assert(cp.stderr.includes(`code: 'ERR_ILLEGAL_CONSTRUCTOR'\n`));
28+
});
29+
1730
test('disabled without --experimental-webstorage', async () => {
1831
for (const api of ['Storage', 'localStorage', 'sessionStorage']) {
1932
const cp = await spawnPromisified(process.execPath, ['-e', api]);

test/parallel/test-whatwg-readablestream.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,14 +1444,17 @@ class Source {
14441444
});
14451445

14461446
assert.throws(() => new ReadableStreamBYOBRequest(), {
1447+
name: 'TypeError',
14471448
code: 'ERR_ILLEGAL_CONSTRUCTOR',
14481449
});
14491450

14501451
assert.throws(() => new ReadableStreamDefaultController(), {
1452+
name: 'TypeError',
14511453
code: 'ERR_ILLEGAL_CONSTRUCTOR',
14521454
});
14531455

14541456
assert.throws(() => new ReadableByteStreamController(), {
1457+
name: 'TypeError',
14551458
code: 'ERR_ILLEGAL_CONSTRUCTOR',
14561459
});
14571460
}

test/parallel/test-whatwg-transformstream.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class Source {
196196
});
197197

198198
assert.throws(() => new TransformStreamDefaultController(), {
199+
name: 'TypeError',
199200
code: 'ERR_ILLEGAL_CONSTRUCTOR',
200201
});
201202
}

0 commit comments

Comments
 (0)