Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use ERR_ILLEGAL_CONSTRUCTOR #39556

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 2 additions & 3 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
ObjectDefineProperty,
Symbol,
SymbolToStringTag,
TypeError,
} = primordials;

const {
Expand All @@ -25,6 +24,7 @@ const {
const { inspect } = require('internal/util/inspect');
const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_THIS,
}
} = require('internal/errors');
Expand All @@ -49,8 +49,7 @@ function validateAbortSignal(obj) {

class AbortSignal extends EventTarget {
constructor() {
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('Illegal constructor');
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

get aborted() {
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const {
codes: {
ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS,
ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE,
ERR_CRYPTO_INVALID_JWK,
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
ERR_OPERATION_FAILED,
ERR_CRYPTO_INVALID_JWK,
}
} = require('internal/errors');

Expand Down Expand Up @@ -631,7 +631,7 @@ function isKeyObject(obj) {
// would be fantastic if we could find a way of making those interop.
class CryptoKey extends JSTransferable {
constructor() {
throw new ERR_OPERATION_FAILED('Illegal constructor');
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

[kInspect](depth, options) {
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
ObjectSetPrototypeOf,
SafeMap,
Symbol,
TypeError,
} = primordials;

const {
Expand All @@ -22,6 +21,7 @@ const { inspect } = require('util');

const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE,
Expand Down Expand Up @@ -130,8 +130,7 @@ class Histogram extends JSTransferable {

class RecordableHistogram extends Histogram {
constructor() {
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('illegal constructor');
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

record(val) {
Expand Down
10 changes: 7 additions & 3 deletions lib/internal/perf/event_loop_delay.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict';
const {
Symbol,
TypeError,
} = primordials;

const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
}
} = require('internal/errors');

const {
ELDHistogram: _ELDHistogram,
} = internalBinding('performance');
Expand All @@ -23,8 +28,7 @@ const kEnabled = Symbol('kEnabled');
class ELDHistogram extends Histogram {
constructor(i) {
if (!(i instanceof _ELDHistogram)) {
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('illegal constructor');
throw new ERR_ILLEGAL_CONSTRUCTOR();
}
super(i);
this[kEnabled] = false;
Expand Down
10 changes: 7 additions & 3 deletions lib/internal/perf/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ const {
ObjectDefineProperty,
ObjectDefineProperties,
ObjectSetPrototypeOf,
TypeError,
} = primordials;

const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
}
} = require('internal/errors');

const {
EventTarget,
} = require('internal/event_target');
Expand Down Expand Up @@ -35,8 +40,7 @@ const {

class Performance extends EventTarget {
constructor() {
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('Illegal constructor');
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

[kInspect](depth, options) {
Expand Down
10 changes: 7 additions & 3 deletions lib/internal/perf/performance_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
const {
ObjectSetPrototypeOf,
Symbol,
TypeError,
} = primordials;

const {
codes: {
ERR_ILLEGAL_CONSTRUCTOR,
}
} = require('internal/errors');

const {
customInspectSymbol: kInspect,
} = require('internal/util');
Expand All @@ -25,8 +30,7 @@ function isPerformanceEntry(obj) {

class PerformanceEntry {
constructor() {
// eslint-disable-next-line no-restricted-syntax
throw new TypeError('illegal constructor');
throw new ERR_ILLEGAL_CONSTRUCTOR();
}

get name() { return this[kName]; }
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-abortcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ const { ok, strictEqual, throws } = require('assert');
{
// Tests that AbortSignal is impossible to construct manually
const ac = new AbortController();
throws(
() => new ac.signal.constructor(),
/^TypeError: Illegal constructor$/
);
throws(() => new ac.signal.constructor(), {
code: 'ERR_ILLEGAL_CONSTRUCTOR',
});
}
{
// Symbol.toStringTag
Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-perf-hooks-histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,5 @@ const { inspect } = require('util');
{
// Tests that RecordableHistogram is impossible to construct manually
const h = createHistogram();
assert.throws(
() => new h.constructor(),
/^TypeError: illegal constructor$/
);
assert.throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
}
4 changes: 1 addition & 3 deletions test/parallel/test-webcrypto-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,7 @@ const vectors = {
})().then(common.mustCall());

// End user code cannot create CryptoKey directly
assert.throws(() => new CryptoKey(), {
code: 'ERR_OPERATION_FAILED'
});
assert.throws(() => new CryptoKey(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });

{
const buffer = Buffer.from('Hello World');
Expand Down