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
|
> 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])`
|
### `fsPromises.access(path[, mode])`
|
||||||
|
|
||||||
@ -6745,7 +6746,8 @@ added: REPLACEME
|
|||||||
|
|
||||||
> Stability: 1 - Experimental
|
> 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]()`
|
#### `dir[Symbol.Dispose]()`
|
||||||
|
|
||||||
@ -6755,7 +6757,7 @@ added: REPLACEME
|
|||||||
|
|
||||||
> Stability: 1 - Experimental
|
> Stability: 1 - Experimental
|
||||||
|
|
||||||
An alias for `dir.closeSync()`.
|
Calls `dir.closeSync()` and returns `undefined`.
|
||||||
|
|
||||||
### Class: `fs.Dirent`
|
### Class: `fs.Dirent`
|
||||||
|
|
||||||
|
@ -581,7 +581,7 @@ Server.prototype.close = function close() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
|
Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
|
||||||
return promisify(this.close).call(this);
|
await promisify(this.close).call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
Server.prototype.closeAllConnections = function closeAllConnections() {
|
Server.prototype.closeAllConnections = function closeAllConnections() {
|
||||||
|
@ -800,7 +800,7 @@ Socket.prototype[SymbolAsyncDispose] = async function() {
|
|||||||
if (!this[kStateSymbol].handle) {
|
if (!this[kStateSymbol].handle) {
|
||||||
return;
|
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() {
|
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');
|
} = require('internal/errors');
|
||||||
|
|
||||||
const { FSReqCallback } = binding;
|
const { FSReqCallback } = binding;
|
||||||
const internalUtil = require('internal/util');
|
const {
|
||||||
|
assignFunctionName,
|
||||||
|
promisify,
|
||||||
|
SymbolAsyncDispose,
|
||||||
|
SymbolDispose,
|
||||||
|
} = require('internal/util');
|
||||||
const {
|
const {
|
||||||
getDirent,
|
getDirent,
|
||||||
getOptions,
|
getOptions,
|
||||||
@ -31,10 +36,6 @@ const {
|
|||||||
validateFunction,
|
validateFunction,
|
||||||
validateUint32,
|
validateUint32,
|
||||||
} = require('internal/validators');
|
} = require('internal/validators');
|
||||||
const {
|
|
||||||
SymbolAsyncDispose,
|
|
||||||
SymbolDispose,
|
|
||||||
} = internalUtil;
|
|
||||||
|
|
||||||
class Dir {
|
class Dir {
|
||||||
#handle;
|
#handle;
|
||||||
@ -61,9 +62,9 @@ class Dir {
|
|||||||
validateUint32(this.#options.bufferSize, 'options.bufferSize', true);
|
validateUint32(this.#options.bufferSize, 'options.bufferSize', true);
|
||||||
|
|
||||||
this.#readPromisified = FunctionPrototypeBind(
|
this.#readPromisified = FunctionPrototypeBind(
|
||||||
internalUtil.promisify(this.#readImpl), this, false);
|
promisify(this.#readImpl), this, false);
|
||||||
this.#closePromisified = FunctionPrototypeBind(
|
this.#closePromisified = FunctionPrototypeBind(
|
||||||
internalUtil.promisify(this.close), this);
|
promisify(this.close), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
get path() {
|
get path() {
|
||||||
@ -306,12 +307,16 @@ ObjectDefineProperties(Dir.prototype, {
|
|||||||
[SymbolDispose]: {
|
[SymbolDispose]: {
|
||||||
__proto__: null,
|
__proto__: null,
|
||||||
...nonEnumerableDescriptor,
|
...nonEnumerableDescriptor,
|
||||||
value: Dir.prototype.closeSync,
|
value: assignFunctionName(SymbolDispose, function() {
|
||||||
|
this.closeSync();
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
[SymbolAsyncDispose]: {
|
[SymbolAsyncDispose]: {
|
||||||
__proto__: null,
|
__proto__: null,
|
||||||
...nonEnumerableDescriptor,
|
...nonEnumerableDescriptor,
|
||||||
value: Dir.prototype.close,
|
value: assignFunctionName(SymbolAsyncDispose, function() {
|
||||||
|
this.close();
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
[SymbolAsyncIterator]: {
|
[SymbolAsyncIterator]: {
|
||||||
__proto__: null,
|
__proto__: null,
|
||||||
|
@ -272,7 +272,7 @@ class FileHandle extends EventEmitter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async [SymbolAsyncDispose]() {
|
async [SymbolAsyncDispose]() {
|
||||||
return this.close();
|
await this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3342,7 +3342,7 @@ class Http2Server extends NETServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async [SymbolAsyncDispose]() {
|
async [SymbolAsyncDispose]() {
|
||||||
return promisify(super.close).call(this);
|
await promisify(super.close).call(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,11 @@ const {
|
|||||||
validateString,
|
validateString,
|
||||||
validateUint32,
|
validateUint32,
|
||||||
} = require('internal/validators');
|
} = require('internal/validators');
|
||||||
const { SymbolDispose, kEmptyObject } = require('internal/util');
|
const {
|
||||||
|
assignFunctionName,
|
||||||
|
kEmptyObject,
|
||||||
|
SymbolDispose,
|
||||||
|
} = require('internal/util');
|
||||||
const {
|
const {
|
||||||
inspect,
|
inspect,
|
||||||
getStringWidth,
|
getStringWidth,
|
||||||
@ -1370,7 +1374,9 @@ class Interface extends InterfaceConstructor {
|
|||||||
return this[kLineObjectStream];
|
return this[kLineObjectStream];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Interface.prototype[SymbolDispose] = Interface.prototype.close;
|
Interface.prototype[SymbolDispose] = assignFunctionName(SymbolDispose, function() {
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Interface,
|
Interface,
|
||||||
|
@ -371,13 +371,13 @@ Readable.prototype[EE.captureRejectionSymbol] = function(err) {
|
|||||||
this.destroy(err);
|
this.destroy(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
Readable.prototype[SymbolAsyncDispose] = function() {
|
Readable.prototype[SymbolAsyncDispose] = async function() {
|
||||||
let error;
|
let error;
|
||||||
if (!this.destroyed) {
|
if (!this.destroyed) {
|
||||||
error = this.readableEnded ? null : new AbortError();
|
error = this.readableEnded ? null : new AbortError();
|
||||||
this.destroy(error);
|
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.
|
// Manually shove something into the read() buffer.
|
||||||
|
@ -1151,13 +1151,13 @@ Writable.toWeb = function(streamWritable) {
|
|||||||
return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);
|
return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);
|
||||||
};
|
};
|
||||||
|
|
||||||
Writable.prototype[SymbolAsyncDispose] = function() {
|
Writable.prototype[SymbolAsyncDispose] = async function() {
|
||||||
let error;
|
let error;
|
||||||
if (!this.destroyed) {
|
if (!this.destroyed) {
|
||||||
error = this.writableFinished ? null : new AbortError();
|
error = this.writableFinished ? null : new AbortError();
|
||||||
this.destroy(error);
|
this.destroy(error);
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) =>
|
await new Promise((resolve, reject) =>
|
||||||
eos(this, (err) => (err && err.name !== 'AbortError' ? reject(err) : resolve(null))),
|
eos(this, (err) => (err && err.name !== 'AbortError' ? reject(err) : resolve(null))),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2395,7 +2395,7 @@ Server.prototype[SymbolAsyncDispose] = async function() {
|
|||||||
if (!this._handle) {
|
if (!this._handle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return FunctionPrototypeCall(promisify(this.close), this);
|
await FunctionPrototypeCall(promisify(this.close), this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype._emitCloseIfDrained = function() {
|
Server.prototype._emitCloseIfDrained = function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user