-
-
Notifications
You must be signed in to change notification settings - Fork 32k
fs, stream: add initial Symbol.dispose
and Symbol.asyncDispose
support
#48518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8a25397
8dc2ee7
223a2d8
40ba972
e8a014f
48602bb
39b6ace
a6d798d
98285ae
5d0d435
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,11 @@ function copyPrototype(src, dest, prefix) { | |
copyPrototype(original.prototype, primordials, `${name}Prototype`); | ||
}); | ||
|
||
// Define Symbol.Disposed and Symbol.AsyncDispose | ||
// Until these are defined by the environment. | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
primordials.SymbolDispose ??= primordials.SymbolFor('nodejs.dispose'); | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this mean Symbol.keyFor of these symbols won't properly return undefined? |
||
primordials.SymbolAsyncDispose ??= primordials.SymbolFor('nodejs.asyncDispose'); | ||
|
||
// Create copies of intrinsic objects that require a valid `this` to call | ||
// static methods. | ||
// Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ const { | |
ObjectGetOwnPropertyDescriptor, | ||
SafeMap, | ||
StringPrototypeStartsWith, | ||
Symbol, | ||
SymbolDispose, | ||
SymbolAsyncDispose, | ||
globalThis, | ||
} = primordials; | ||
|
||
|
@@ -82,6 +85,8 @@ function prepareExecution(options) { | |
|
||
require('internal/dns/utils').initializeDns(); | ||
|
||
setupSymbolDisposePolyfill(); | ||
|
||
if (isMainThread) { | ||
assert(internalBinding('worker').isMainThread); | ||
// Worker threads will get the manifest in the message handler. | ||
|
@@ -119,6 +124,12 @@ function prepareExecution(options) { | |
} | ||
} | ||
|
||
function setupSymbolDisposePolyfill() { | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Symbol.dispose ??= SymbolDispose; | ||
Symbol.asyncDispose ??= SymbolAsyncDispose; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be a good thing to polyfill them? Wouldn't users assume certain behaviors from the runtime because they exists? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is a way for typescript or bable to recognize these symbols without them being global. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mcollina this is confirmed (with the TS team) to play nice. Users would be able to use them with the polyfill but not the syntactic sugar until v8 ships There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That breaks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
|
||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function setupUserModules(isLoaderWorker = false) { | ||
initializeCJSLoader(); | ||
initializeESMLoader(isLoaderWorker); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { promises: fs } = require('fs'); | ||
|
||
async function doOpen() { | ||
const fh = await fs.open(__filename); | ||
fh.on('close', common.mustCall()); | ||
await fh[Symbol.asyncDispose](); | ||
} | ||
|
||
doOpen().then(common.mustCall()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { Readable } = require('stream'); | ||
const assert = require('assert'); | ||
|
||
{ | ||
const read = new Readable({ | ||
read() {} | ||
}); | ||
read.resume(); | ||
|
||
read.on('end', common.mustNotCall('no end event')); | ||
read.on('close', common.mustCall()); | ||
read.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.name, 'AbortError'); | ||
})); | ||
|
||
read[Symbol.asyncDispose]().then(common.mustCall(() => { | ||
assert.strictEqual(read.errored.name, 'AbortError'); | ||
assert.strictEqual(read.destroyed, true); | ||
})); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.