Skip to content

Commit 20d978d

Browse files
LiviaMedeirosaduh95
authored andcommitted
lib: make ERM functions into wrappers returning undefined
PR-URL: #58400 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 6939b0c commit 20d978d

File tree

11 files changed

+37
-24
lines changed

11 files changed

+37
-24
lines changed

doc/api/fs.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,8 @@ added:
861861
862862
> Stability: 1 - Experimental
863863
864-
An alias for `filehandle.close()`.
864+
Calls `filehandle.close()` and returns a promise that fulfills when the
865+
filehandle is closed.
865866
866867
### `fsPromises.access(path[, mode])`
867868
@@ -6745,7 +6746,8 @@ added: REPLACEME
67456746
67466747
> Stability: 1 - Experimental
67476748
6748-
An alias for `dir.close()`.
6749+
Calls `dir.close()` and returns a promise that fulfills when the
6750+
dir is closed.
67496751
67506752
#### `dir[Symbol.Dispose]()`
67516753
@@ -6755,7 +6757,7 @@ added: REPLACEME
67556757
67566758
> Stability: 1 - Experimental
67576759
6758-
An alias for `dir.closeSync()`.
6760+
Calls `dir.closeSync()` and returns `undefined`.
67596761
67606762
### Class: `fs.Dirent`
67616763

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ Server.prototype.close = function close() {
581581
};
582582

583583
Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
584-
return promisify(this.close).call(this);
584+
await promisify(this.close).call(this);
585585
});
586586

587587
Server.prototype.closeAllConnections = function closeAllConnections() {

lib/dgram.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ Socket.prototype[SymbolAsyncDispose] = async function() {
800800
if (!this[kStateSymbol].handle) {
801801
return;
802802
}
803-
return FunctionPrototypeCall(promisify(this.close), this);
803+
await FunctionPrototypeCall(promisify(this.close), this);
804804
};
805805

806806

lib/https.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Server.prototype.close = function close() {
117117
};
118118

119119
Server.prototype[SymbolAsyncDispose] = async function() {
120-
return FunctionPrototypeCall(promisify(this.close), this);
120+
await FunctionPrototypeCall(promisify(this.close), this);
121121
};
122122

123123
/**

lib/internal/fs/dir.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ const {
2121
} = require('internal/errors');
2222

2323
const { FSReqCallback } = binding;
24-
const internalUtil = require('internal/util');
24+
const {
25+
assignFunctionName,
26+
promisify,
27+
SymbolAsyncDispose,
28+
SymbolDispose,
29+
} = require('internal/util');
2530
const {
2631
getDirent,
2732
getOptions,
@@ -31,10 +36,6 @@ const {
3136
validateFunction,
3237
validateUint32,
3338
} = require('internal/validators');
34-
const {
35-
SymbolAsyncDispose,
36-
SymbolDispose,
37-
} = internalUtil;
3839

3940
class Dir {
4041
#handle;
@@ -61,9 +62,9 @@ class Dir {
6162
validateUint32(this.#options.bufferSize, 'options.bufferSize', true);
6263

6364
this.#readPromisified = FunctionPrototypeBind(
64-
internalUtil.promisify(this.#readImpl), this, false);
65+
promisify(this.#readImpl), this, false);
6566
this.#closePromisified = FunctionPrototypeBind(
66-
internalUtil.promisify(this.close), this);
67+
promisify(this.close), this);
6768
}
6869

6970
get path() {
@@ -306,12 +307,16 @@ ObjectDefineProperties(Dir.prototype, {
306307
[SymbolDispose]: {
307308
__proto__: null,
308309
...nonEnumerableDescriptor,
309-
value: Dir.prototype.closeSync,
310+
value: assignFunctionName(SymbolDispose, function() {
311+
this.closeSync();
312+
}),
310313
},
311314
[SymbolAsyncDispose]: {
312315
__proto__: null,
313316
...nonEnumerableDescriptor,
314-
value: Dir.prototype.close,
317+
value: assignFunctionName(SymbolAsyncDispose, function() {
318+
this.close();
319+
}),
315320
},
316321
[SymbolAsyncIterator]: {
317322
__proto__: null,

lib/internal/fs/promises.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class FileHandle extends EventEmitter {
272272
};
273273

274274
async [SymbolAsyncDispose]() {
275-
return this.close();
275+
await this.close();
276276
}
277277

278278
/**

lib/internal/http2/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3342,7 +3342,7 @@ class Http2Server extends NETServer {
33423342
}
33433343

33443344
async [SymbolAsyncDispose]() {
3345-
return promisify(super.close).call(this);
3345+
await promisify(super.close).call(this);
33463346
}
33473347
}
33483348

lib/internal/readline/interface.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const {
4747
validateString,
4848
validateUint32,
4949
} = require('internal/validators');
50-
const { SymbolDispose, kEmptyObject } = require('internal/util');
50+
const {
51+
assignFunctionName,
52+
kEmptyObject,
53+
SymbolDispose,
54+
} = require('internal/util');
5155
const {
5256
inspect,
5357
getStringWidth,
@@ -1370,7 +1374,9 @@ class Interface extends InterfaceConstructor {
13701374
return this[kLineObjectStream];
13711375
}
13721376
}
1373-
Interface.prototype[SymbolDispose] = Interface.prototype.close;
1377+
Interface.prototype[SymbolDispose] = assignFunctionName(SymbolDispose, function() {
1378+
this.close();
1379+
});
13741380

13751381
module.exports = {
13761382
Interface,

lib/internal/streams/readable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,13 @@ Readable.prototype[EE.captureRejectionSymbol] = function(err) {
371371
this.destroy(err);
372372
};
373373

374-
Readable.prototype[SymbolAsyncDispose] = function() {
374+
Readable.prototype[SymbolAsyncDispose] = async function() {
375375
let error;
376376
if (!this.destroyed) {
377377
error = this.readableEnded ? null : new AbortError();
378378
this.destroy(error);
379379
}
380-
return new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));
380+
await new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));
381381
};
382382

383383
// Manually shove something into the read() buffer.

lib/internal/streams/writable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,13 +1151,13 @@ Writable.toWeb = function(streamWritable) {
11511151
return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);
11521152
};
11531153

1154-
Writable.prototype[SymbolAsyncDispose] = function() {
1154+
Writable.prototype[SymbolAsyncDispose] = async function() {
11551155
let error;
11561156
if (!this.destroyed) {
11571157
error = this.writableFinished ? null : new AbortError();
11581158
this.destroy(error);
11591159
}
1160-
return new Promise((resolve, reject) =>
1160+
await new Promise((resolve, reject) =>
11611161
eos(this, (err) => (err && err.name !== 'AbortError' ? reject(err) : resolve(null))),
11621162
);
11631163
};

lib/net.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,7 @@ Server.prototype[SymbolAsyncDispose] = async function() {
23952395
if (!this._handle) {
23962396
return;
23972397
}
2398-
return FunctionPrototypeCall(promisify(this.close), this);
2398+
await FunctionPrototypeCall(promisify(this.close), this);
23992399
};
24002400

24012401
Server.prototype._emitCloseIfDrained = function() {

0 commit comments

Comments
 (0)