From ad03a4a0effa6ffeff0c1be838f9e61d615b3a82 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Fri, 16 May 2025 15:57:22 -0700 Subject: [PATCH] src: make c++ `ERR_ILLEGAL_CONSTRUCTOR` inherit `TypeError` --- src/node_errors.h | 2 +- test/parallel/test-abortcontroller.js | 1 + test/parallel/test-sqlite-statement-sync.js | 3 ++- test/parallel/test-timers-promises-scheduler.js | 1 + test/parallel/test-webcrypto-keygen.js | 5 ++++- test/parallel/test-webstorage.js | 13 +++++++++++++ test/parallel/test-whatwg-readablestream.js | 3 +++ test/parallel/test-whatwg-transformstream.js | 1 + 8 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/node_errors.h b/src/node_errors.h index 4d7132a9954505..d61400e12b459d 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -82,7 +82,7 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details); V(ERR_FS_CP_SOCKET, Error) \ V(ERR_FS_CP_FIFO_PIPE, Error) \ V(ERR_FS_CP_UNKNOWN, Error) \ - V(ERR_ILLEGAL_CONSTRUCTOR, Error) \ + V(ERR_ILLEGAL_CONSTRUCTOR, TypeError) \ V(ERR_INVALID_ADDRESS, Error) \ V(ERR_INVALID_ARG_VALUE, TypeError) \ V(ERR_OSSL_EVP_INVALID_DIGEST, Error) \ diff --git a/test/parallel/test-abortcontroller.js b/test/parallel/test-abortcontroller.js index 87781f849ffb52..28f07469f19c74 100644 --- a/test/parallel/test-abortcontroller.js +++ b/test/parallel/test-abortcontroller.js @@ -81,6 +81,7 @@ test('AbortSignal is impossible to construct manually', () => { // Tests that AbortSignal is impossible to construct manually const ac = new AbortController(); throws(() => new ac.signal.constructor(), { + name: 'TypeError', code: 'ERR_ILLEGAL_CONSTRUCTOR', }); }); diff --git a/test/parallel/test-sqlite-statement-sync.js b/test/parallel/test-sqlite-statement-sync.js index 858a1486601763..ef10dbf0c15a0c 100644 --- a/test/parallel/test-sqlite-statement-sync.js +++ b/test/parallel/test-sqlite-statement-sync.js @@ -19,8 +19,9 @@ suite('StatementSync() constructor', () => { t.assert.throws(() => { new StatementSync(); }, { + name: 'TypeError', code: 'ERR_ILLEGAL_CONSTRUCTOR', - message: /Illegal constructor/, + message: 'Illegal constructor', }); }); }); diff --git a/test/parallel/test-timers-promises-scheduler.js b/test/parallel/test-timers-promises-scheduler.js index 4eda43586f6c1d..7c6cda336958ab 100644 --- a/test/parallel/test-timers-promises-scheduler.js +++ b/test/parallel/test-timers-promises-scheduler.js @@ -51,5 +51,6 @@ async function testCancelableWait2() { testCancelableWait2().then(common.mustCall()); throws(() => new scheduler.constructor(), { + name: 'TypeError', code: 'ERR_ILLEGAL_CONSTRUCTOR', }); diff --git a/test/parallel/test-webcrypto-keygen.js b/test/parallel/test-webcrypto-keygen.js index a60463bdb5f139..edfd8a79b7d6bd 100644 --- a/test/parallel/test-webcrypto-keygen.js +++ b/test/parallel/test-webcrypto-keygen.js @@ -611,7 +611,10 @@ const vectors = { } // End user code cannot create CryptoKey directly -assert.throws(() => new CryptoKey(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' }); +assert.throws(() => new CryptoKey(), { + name: 'TypeError', + code: 'ERR_ILLEGAL_CONSTRUCTOR', +}); { const buffer = Buffer.from('Hello World'); diff --git a/test/parallel/test-webstorage.js b/test/parallel/test-webstorage.js index 9f9070df430f10..56abf2cd5219bd 100644 --- a/test/parallel/test-webstorage.js +++ b/test/parallel/test-webstorage.js @@ -14,6 +14,19 @@ function nextLocalStorage() { return join(tmpdir.path, `${++cnt}.localstorage`); } +test('constructor is illegal', async () => { + const cp = await spawnPromisified(process.execPath, [ + '--experimental-webstorage', + '--localstorage-file', nextLocalStorage(), + '-e', 'new Storage', + ]); + assert.strictEqual(cp.code, 1); + assert.strictEqual(cp.signal, null); + assert.strictEqual(cp.stdout, ''); + assert(cp.stderr.includes(`TypeError: Illegal constructor\n`)); + assert(cp.stderr.includes(`code: 'ERR_ILLEGAL_CONSTRUCTOR'\n`)); +}); + test('disabled without --experimental-webstorage', async () => { for (const api of ['Storage', 'localStorage', 'sessionStorage']) { const cp = await spawnPromisified(process.execPath, ['-e', api]); diff --git a/test/parallel/test-whatwg-readablestream.js b/test/parallel/test-whatwg-readablestream.js index 9af751ddd02958..f38d26e39e31cf 100644 --- a/test/parallel/test-whatwg-readablestream.js +++ b/test/parallel/test-whatwg-readablestream.js @@ -1444,14 +1444,17 @@ class Source { }); assert.throws(() => new ReadableStreamBYOBRequest(), { + name: 'TypeError', code: 'ERR_ILLEGAL_CONSTRUCTOR', }); assert.throws(() => new ReadableStreamDefaultController(), { + name: 'TypeError', code: 'ERR_ILLEGAL_CONSTRUCTOR', }); assert.throws(() => new ReadableByteStreamController(), { + name: 'TypeError', code: 'ERR_ILLEGAL_CONSTRUCTOR', }); } diff --git a/test/parallel/test-whatwg-transformstream.js b/test/parallel/test-whatwg-transformstream.js index 2ec2c21c66819f..9a95d133efe676 100644 --- a/test/parallel/test-whatwg-transformstream.js +++ b/test/parallel/test-whatwg-transformstream.js @@ -196,6 +196,7 @@ class Source { }); assert.throws(() => new TransformStreamDefaultController(), { + name: 'TypeError', code: 'ERR_ILLEGAL_CONSTRUCTOR', }); }