Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-abortcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-sqlite-statement-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ suite('StatementSync() constructor', () => {
t.assert.throws(() => {
new StatementSync();
}, {
name: 'TypeError',
code: 'ERR_ILLEGAL_CONSTRUCTOR',
message: /Illegal constructor/,
message: 'Illegal constructor',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to test the message

Suggested change
message: 'Illegal constructor',

});
});
});
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-timers-promises-scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ async function testCancelableWait2() {
testCancelableWait2().then(common.mustCall());

throws(() => new scheduler.constructor(), {
name: 'TypeError',
code: 'ERR_ILLEGAL_CONSTRUCTOR',
});
5 changes: 4 additions & 1 deletion test/parallel/test-webcrypto-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-webstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`));
Comment on lines +26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use assert.match so in case of failure we get a more informative error message?

Suggested change
assert(cp.stderr.includes(`TypeError: Illegal constructor\n`));
assert(cp.stderr.includes(`code: 'ERR_ILLEGAL_CONSTRUCTOR'\n`));
assert.match(cp.stderr, /TypeError: Illegal constructor\n(.*\n)*\s*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]);
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-whatwg-readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-whatwg-transformstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Source {
});

assert.throws(() => new TransformStreamDefaultController(), {
name: 'TypeError',
code: 'ERR_ILLEGAL_CONSTRUCTOR',
});
}
Expand Down
Loading