lib: revert to using default derived class constructors

PR-URL: https://github.com/nodejs/node/pull/59650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
René 2025-08-30 15:28:10 +01:00 committed by GitHub
parent 67cb0adbc2
commit 196f5466af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 9 additions and 58 deletions

View File

@ -3,9 +3,7 @@
const inspector = require('inspector'); const inspector = require('inspector');
const { promisify } = require('internal/util'); const { promisify } = require('internal/util');
class Session extends inspector.Session { class Session extends inspector.Session {}
constructor() { super(); } // eslint-disable-line no-useless-constructor
}
Session.prototype.post = promisify(inspector.Session.prototype.post); Session.prototype.post = promisify(inspector.Session.prototype.post);
module.exports = { module.exports = {

View File

@ -960,14 +960,7 @@ function writeFloatBackwards(val, offset = 0) {
return offset; return offset;
} }
class FastBuffer extends Uint8Array { class FastBuffer extends Uint8Array {}
// Using an explicit constructor here is necessary to avoid relying on
// `Array.prototype[Symbol.iterator]`, which can be mutated by users.
// eslint-disable-next-line no-useless-constructor
constructor(bufferOrLength, byteOffset, length) {
super(bufferOrLength, byteOffset, length);
}
}
function addBufferPrototypeMethods(proto) { function addBufferPrototypeMethods(proto) {
proto.readBigUInt64LE = readBigUInt64LE; proto.readBigUInt64LE = readBigUInt64LE;

View File

@ -253,11 +253,6 @@ const {
} }
class AsymmetricKeyObject extends KeyObject { class AsymmetricKeyObject extends KeyObject {
// eslint-disable-next-line no-useless-constructor
constructor(type, handle) {
super(type, handle);
}
get asymmetricKeyType() { get asymmetricKeyType() {
return this[kAsymmetricKeyType] ||= this[kHandle].getAsymmetricKeyType(); return this[kAsymmetricKeyType] ||= this[kHandle].getAsymmetricKeyType();
} }

View File

@ -240,7 +240,6 @@ class Pattern {
class ResultSet extends SafeSet { class ResultSet extends SafeSet {
#root = '.'; #root = '.';
#isExcluded = () => false; #isExcluded = () => false;
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
setup(root, isExcludedFn) { setup(root, isExcludedFn) {
this.#root = root; this.#root = root;

View File

@ -23,8 +23,6 @@ const { validateString } = require('internal/validators');
* This cache is *not* used when custom loaders are registered. * This cache is *not* used when custom loaders are registered.
*/ */
class ResolveCache extends SafeMap { class ResolveCache extends SafeMap {
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
/** /**
* Generates the internal serialized cache key and returns it along the actual cache object. * Generates the internal serialized cache key and returns it along the actual cache object.
* *
@ -93,7 +91,6 @@ class ResolveCache extends SafeMap {
* Cache the results of the `load` step of the module resolution and loading process. * Cache the results of the `load` step of the module resolution and loading process.
*/ */
class LoadCache extends SafeMap { class LoadCache extends SafeMap {
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
get(url, type = kImplicitTypeAttribute) { get(url, type = kImplicitTypeAttribute) {
validateString(url, 'url'); validateString(url, 'url');
validateString(type, 'type'); validateString(type, 'type');

View File

@ -401,55 +401,36 @@ primordials.makeSafe = makeSafe;
// Subclass the constructors because we need to use their prototype // Subclass the constructors because we need to use their prototype
// methods later. // methods later.
// Defining the `constructor` is necessary here to avoid the default
// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`.
primordials.SafeMap = makeSafe( primordials.SafeMap = makeSafe(
Map, Map,
class SafeMap extends Map { class SafeMap extends Map {},
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
},
); );
primordials.SafeWeakMap = makeSafe( primordials.SafeWeakMap = makeSafe(
WeakMap, WeakMap,
class SafeWeakMap extends WeakMap { class SafeWeakMap extends WeakMap {},
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
},
); );
primordials.SafeSet = makeSafe( primordials.SafeSet = makeSafe(
Set, Set,
class SafeSet extends Set { class SafeSet extends Set {},
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
},
); );
primordials.SafeWeakSet = makeSafe( primordials.SafeWeakSet = makeSafe(
WeakSet, WeakSet,
class SafeWeakSet extends WeakSet { class SafeWeakSet extends WeakSet {},
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
},
); );
primordials.SafeFinalizationRegistry = makeSafe( primordials.SafeFinalizationRegistry = makeSafe(
FinalizationRegistry, FinalizationRegistry,
class SafeFinalizationRegistry extends FinalizationRegistry { class SafeFinalizationRegistry extends FinalizationRegistry {},
// eslint-disable-next-line no-useless-constructor
constructor(cleanupCallback) { super(cleanupCallback); }
},
); );
primordials.SafeWeakRef = makeSafe( primordials.SafeWeakRef = makeSafe(
WeakRef, WeakRef,
class SafeWeakRef extends WeakRef { class SafeWeakRef extends WeakRef {},
// eslint-disable-next-line no-useless-constructor
constructor(target) { super(target); }
},
); );
const SafePromise = makeSafe( const SafePromise = makeSafe(
Promise, Promise,
class SafePromise extends Promise { class SafePromise extends Promise {},
// eslint-disable-next-line no-useless-constructor
constructor(executor) { super(executor); }
},
); );
/** /**

View File

@ -359,10 +359,6 @@ ObjectSetPrototypeOf(InterfaceConstructor.prototype, EventEmitter.prototype);
ObjectSetPrototypeOf(InterfaceConstructor, EventEmitter); ObjectSetPrototypeOf(InterfaceConstructor, EventEmitter);
class Interface extends InterfaceConstructor { class Interface extends InterfaceConstructor {
// eslint-disable-next-line no-useless-constructor
constructor(input, output, completer, terminal) {
super(input, output, completer, terminal);
}
get columns() { get columns() {
if (this.output?.columns) return this.output.columns; if (this.output?.columns) return this.output.columns;
return Infinity; return Infinity;

View File

@ -97,10 +97,6 @@ function isRecoverableError(e, code) {
.extend( .extend(
(Parser) => { (Parser) => {
return class extends Parser { return class extends Parser {
// eslint-disable-next-line no-useless-constructor
constructor(options, input, startPos) {
super(options, input, startPos);
}
nextToken() { nextToken() {
super.nextToken(); super.nextToken();
if (this.type === tt.eof) if (this.type === tt.eof)

View File

@ -27,10 +27,6 @@ const {
let addAbortListener; let addAbortListener;
class Interface extends _Interface { class Interface extends _Interface {
// eslint-disable-next-line no-useless-constructor
constructor(input, output, completer, terminal) {
super(input, output, completer, terminal);
}
question(query, options = kEmptyObject) { question(query, options = kEmptyObject) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let cb = resolve; let cb = resolve;