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:
parent
6939b0c624
commit
20d978de9a
@ -861,7 +861,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])`
|
||||
|
||||
@ -6745,7 +6746,8 @@ added: REPLACEME
|
||||
|
||||
> 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]()`
|
||||
|
||||
@ -6755,7 +6757,7 @@ added: REPLACEME
|
||||
|
||||
> Stability: 1 - Experimental
|
||||
|
||||
An alias for `dir.closeSync()`.
|
||||
Calls `dir.closeSync()` and returns `undefined`.
|
||||
|
||||
### Class: `fs.Dirent`
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -800,7 +800,7 @@ Socket.prototype[SymbolAsyncDispose] = async function() {
|
||||
if (!this[kStateSymbol].handle) {
|
||||
return;
|
||||
}
|
||||
return FunctionPrototypeCall(promisify(this.close), this);
|
||||
await FunctionPrototypeCall(promisify(this.close), this);
|
||||
};
|
||||
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,12 @@ const {
|
||||
} = require('internal/errors');
|
||||
|
||||
const { FSReqCallback } = binding;
|
||||
const internalUtil = require('internal/util');
|
||||
const {
|
||||
assignFunctionName,
|
||||
promisify,
|
||||
SymbolAsyncDispose,
|
||||
SymbolDispose,
|
||||
} = require('internal/util');
|
||||
const {
|
||||
getDirent,
|
||||
getOptions,
|
||||
@ -31,10 +36,6 @@ const {
|
||||
validateFunction,
|
||||
validateUint32,
|
||||
} = require('internal/validators');
|
||||
const {
|
||||
SymbolAsyncDispose,
|
||||
SymbolDispose,
|
||||
} = internalUtil;
|
||||
|
||||
class Dir {
|
||||
#handle;
|
||||
@ -61,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() {
|
||||
@ -306,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,
|
||||
|
@ -272,7 +272,7 @@ class FileHandle extends EventEmitter {
|
||||
};
|
||||
|
||||
async [SymbolAsyncDispose]() {
|
||||
return this.close();
|
||||
await this.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3342,7 +3342,7 @@ class Http2Server extends NETServer {
|
||||
}
|
||||
|
||||
async [SymbolAsyncDispose]() {
|
||||
return promisify(super.close).call(this);
|
||||
await promisify(super.close).call(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,11 @@ const {
|
||||
validateString,
|
||||
validateUint32,
|
||||
} = require('internal/validators');
|
||||
const { SymbolDispose, kEmptyObject } = require('internal/util');
|
||||
const {
|
||||
assignFunctionName,
|
||||
kEmptyObject,
|
||||
SymbolDispose,
|
||||
} = require('internal/util');
|
||||
const {
|
||||
inspect,
|
||||
getStringWidth,
|
||||
@ -1370,7 +1374,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,
|
||||
|
@ -371,13 +371,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.
|
||||
|
@ -1151,13 +1151,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))),
|
||||
);
|
||||
};
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user