lib: make ERM functions into wrappers returning undefined

PR-URL: https://github.com/nodejs/node/pull/58400
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Livia Medeiros 2025-05-25 21:44:43 +08:00 committed by GitHub
parent c3b580d9f0
commit 6c9a7cd61e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 34 additions and 20 deletions

View file

@ -863,7 +863,8 @@ added:
> Stability: 1 - Experimental
An alias for `filehandle.close()`.
Calls `filehandle.close()` and returns a promise that fulfills when the
filehandle is closed.
### `fsPromises.access(path[, mode])`
@ -6757,7 +6758,8 @@ added: v24.1.0
> Stability: 1 - Experimental
An alias for `dir.close()`.
Calls `dir.close()` and returns a promise that fulfills when the
dir is closed.
#### `dir[Symbol.Dispose]()`
@ -6767,7 +6769,7 @@ added: v24.1.0
> Stability: 1 - Experimental
An alias for `dir.closeSync()`.
Calls `dir.closeSync()` and returns `undefined`.
### Class: `fs.Dirent`

View file

@ -581,7 +581,7 @@ Server.prototype.close = function close() {
};
Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
return promisify(this.close).call(this);
await promisify(this.close).call(this);
});
Server.prototype.closeAllConnections = function closeAllConnections() {

View file

@ -802,7 +802,7 @@ Socket.prototype[SymbolAsyncDispose] = async function() {
if (!this[kStateSymbol].handle) {
return;
}
return FunctionPrototypeCall(promisify(this.close), this);
await FunctionPrototypeCall(promisify(this.close), this);
};

View file

@ -117,7 +117,7 @@ Server.prototype.close = function close() {
};
Server.prototype[SymbolAsyncDispose] = async function() {
return FunctionPrototypeCall(promisify(this.close), this);
await FunctionPrototypeCall(promisify(this.close), this);
};
/**

View file

@ -23,7 +23,10 @@ const {
} = require('internal/errors');
const { FSReqCallback } = binding;
const internalUtil = require('internal/util');
const {
assignFunctionName,
promisify,
} = require('internal/util');
const {
getDirent,
getOptions,
@ -59,9 +62,9 @@ class Dir {
validateUint32(this.#options.bufferSize, 'options.bufferSize', true);
this.#readPromisified = FunctionPrototypeBind(
internalUtil.promisify(this.#readImpl), this, false);
promisify(this.#readImpl), this, false);
this.#closePromisified = FunctionPrototypeBind(
internalUtil.promisify(this.close), this);
promisify(this.close), this);
}
get path() {
@ -304,12 +307,16 @@ ObjectDefineProperties(Dir.prototype, {
[SymbolDispose]: {
__proto__: null,
...nonEnumerableDescriptor,
value: Dir.prototype.closeSync,
value: assignFunctionName(SymbolDispose, function() {
this.closeSync();
}),
},
[SymbolAsyncDispose]: {
__proto__: null,
...nonEnumerableDescriptor,
value: Dir.prototype.close,
value: assignFunctionName(SymbolAsyncDispose, function() {
this.close();
}),
},
[SymbolAsyncIterator]: {
__proto__: null,

View file

@ -273,7 +273,7 @@ class FileHandle extends EventEmitter {
};
async [SymbolAsyncDispose]() {
return this.close();
await this.close();
}
/**

View file

@ -3340,7 +3340,7 @@ class Http2Server extends NETServer {
}
async [SymbolAsyncDispose]() {
return promisify(super.close).call(this);
await promisify(super.close).call(this);
}
}

View file

@ -51,7 +51,10 @@ const {
validateString,
validateUint32,
} = require('internal/validators');
const { kEmptyObject } = require('internal/util');
const {
assignFunctionName,
kEmptyObject,
} = require('internal/util');
const {
inspect,
getStringWidth,
@ -1637,7 +1640,9 @@ class Interface extends InterfaceConstructor {
return this[kLineObjectStream];
}
}
Interface.prototype[SymbolDispose] = Interface.prototype.close;
Interface.prototype[SymbolDispose] = assignFunctionName(SymbolDispose, function() {
this.close();
});
module.exports = {
Interface,

View file

@ -369,13 +369,13 @@ Readable.prototype[EE.captureRejectionSymbol] = function(err) {
this.destroy(err);
};
Readable.prototype[SymbolAsyncDispose] = function() {
Readable.prototype[SymbolAsyncDispose] = async function() {
let error;
if (!this.destroyed) {
error = this.readableEnded ? null : new AbortError();
this.destroy(error);
}
return new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));
await new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));
};
// Manually shove something into the read() buffer.

View file

@ -1149,13 +1149,13 @@ Writable.toWeb = function(streamWritable) {
return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);
};
Writable.prototype[SymbolAsyncDispose] = function() {
Writable.prototype[SymbolAsyncDispose] = async function() {
let error;
if (!this.destroyed) {
error = this.writableFinished ? null : new AbortError();
this.destroy(error);
}
return new Promise((resolve, reject) =>
await new Promise((resolve, reject) =>
eos(this, (err) => (err && err.name !== 'AbortError' ? reject(err) : resolve(null))),
);
};

View file

@ -2395,7 +2395,7 @@ Server.prototype[SymbolAsyncDispose] = async function() {
if (!this._handle) {
return;
}
return FunctionPrototypeCall(promisify(this.close), this);
await FunctionPrototypeCall(promisify(this.close), this);
};
Server.prototype._emitCloseIfDrained = function() {