lib: make ERM functions into wrappers returning undefined · nodejs/node@cc1aaca

11 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -863,7 +863,8 @@ added:

863863
864864

> Stability: 1 - Experimental

865865
866-

An alias for `filehandle.close()`.

866+

Calls `filehandle.close()` and returns a promise that fulfills when the

867+

filehandle is closed.

867868
868869

### `fsPromises.access(path[, mode])`

869870

@@ -6753,7 +6754,8 @@ added: v24.1.0

67536754
67546755

> Stability: 1 - Experimental

67556756
6756-

An alias for `dir.close()`.

6757+

Calls `dir.close()` and returns a promise that fulfills when the

6758+

dir is closed.

67576759
67586760

#### `dir[Symbol.Dispose]()`

67596761

@@ -6763,7 +6765,7 @@ added: v24.1.0

67636765
67646766

> Stability: 1 - Experimental

67656767
6766-

An alias for `dir.closeSync()`.

6768+

Calls `dir.closeSync()` and returns `undefined`.

67676769
67686770

### Class: `fs.Dirent`

67696771
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() {

Original file line numberDiff line numberDiff line change

@@ -802,7 +802,7 @@ Socket.prototype[SymbolAsyncDispose] = async function() {

802802

if (!this[kStateSymbol].handle) {

803803

return;

804804

}

805-

return FunctionPrototypeCall(promisify(this.close), this);

805+

await FunctionPrototypeCall(promisify(this.close), this);

806806

};

807807
808808
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

/**

Original file line numberDiff line numberDiff line change

@@ -23,7 +23,10 @@ const {

2323

} = require('internal/errors');

2424
2525

const { FSReqCallback } = binding;

26-

const internalUtil = require('internal/util');

26+

const {

27+

assignFunctionName,

28+

promisify,

29+

} = require('internal/util');

2730

const {

2831

getDirent,

2932

getOptions,

@@ -59,9 +62,9 @@ class Dir {

5962

validateUint32(this.#options.bufferSize, 'options.bufferSize', true);

6063
6164

this.#readPromisified = FunctionPrototypeBind(

62-

internalUtil.promisify(this.#readImpl), this, false);

65+

promisify(this.#readImpl), this, false);

6366

this.#closePromisified = FunctionPrototypeBind(

64-

internalUtil.promisify(this.close), this);

67+

promisify(this.close), this);

6568

}

6669
6770

get path() {

@@ -304,12 +307,16 @@ ObjectDefineProperties(Dir.prototype, {

304307

[SymbolDispose]: {

305308

__proto__: null,

306309

...nonEnumerableDescriptor,

307-

value: Dir.prototype.closeSync,

310+

value: assignFunctionName(SymbolDispose, function() {

311+

this.closeSync();

312+

}),

308313

},

309314

[SymbolAsyncDispose]: {

310315

__proto__: null,

311316

...nonEnumerableDescriptor,

312-

value: Dir.prototype.close,

317+

value: assignFunctionName(SymbolAsyncDispose, function() {

318+

this.close();

319+

}),

313320

},

314321

[SymbolAsyncIterator]: {

315322

__proto__: null,

Original file line numberDiff line numberDiff line change

@@ -273,7 +273,7 @@ class FileHandle extends EventEmitter {

273273

};

274274
275275

async [SymbolAsyncDispose]() {

276-

return this.close();

276+

await this.close();

277277

}

278278
279279

/**

Original file line numberDiff line numberDiff line change

@@ -3340,7 +3340,7 @@ class Http2Server extends NETServer {

33403340

}

33413341
33423342

async [SymbolAsyncDispose]() {

3343-

return promisify(super.close).call(this);

3343+

await promisify(super.close).call(this);

33443344

}

33453345

}

33463346
Original file line numberDiff line numberDiff line change

@@ -51,7 +51,10 @@ const {

5151

validateString,

5252

validateUint32,

5353

} = require('internal/validators');

54-

const { kEmptyObject } = require('internal/util');

54+

const {

55+

assignFunctionName,

56+

kEmptyObject,

57+

} = require('internal/util');

5558

const {

5659

inspect,

5760

getStringWidth,

@@ -1637,7 +1640,9 @@ class Interface extends InterfaceConstructor {

16371640

return this[kLineObjectStream];

16381641

}

16391642

}

1640-

Interface.prototype[SymbolDispose] = Interface.prototype.close;

1643+

Interface.prototype[SymbolDispose] = assignFunctionName(SymbolDispose, function() {

1644+

this.close();

1645+

});

16411646
16421647

module.exports = {

16431648

Interface,

Original file line numberDiff line numberDiff line change

@@ -369,13 +369,13 @@ Readable.prototype[EE.captureRejectionSymbol] = function(err) {

369369

this.destroy(err);

370370

};

371371
372-

Readable.prototype[SymbolAsyncDispose] = function() {

372+

Readable.prototype[SymbolAsyncDispose] = async function() {

373373

let error;

374374

if (!this.destroyed) {

375375

error = this.readableEnded ? null : new AbortError();

376376

this.destroy(error);

377377

}

378-

return new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));

378+

await new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));

379379

};

380380
381381

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

Original file line numberDiff line numberDiff line change

@@ -1149,13 +1149,13 @@ Writable.toWeb = function(streamWritable) {

11491149

return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);

11501150

};

11511151
1152-

Writable.prototype[SymbolAsyncDispose] = function() {

1152+

Writable.prototype[SymbolAsyncDispose] = async function() {

11531153

let error;

11541154

if (!this.destroyed) {

11551155

error = this.writableFinished ? null : new AbortError();

11561156

this.destroy(error);

11571157

}

1158-

return new Promise((resolve, reject) =>

1158+

await new Promise((resolve, reject) =>

11591159

eos(this, (err) => (err && err.name !== 'AbortError' ? reject(err) : resolve(null))),

11601160

);

11611161

};