proposal-explicit-resource-management
proposal-explicit-resource-management copied to clipboard
A subclass that overrides DisposableStack#dispose must also override DisposableStack#[Symbol.dispose]
Consider code like:
class NotifyingStack extends DisposableStack {
dispose() {
const wasDisposed = this.disposed;
super.dispose();
if (!wasDisposed) {
notify();
}
}
}
By my reading of https://tc39.es/proposal-explicit-resource-management/#sec-disposablestack.prototype-@@dispose this code is buggy, notify won't be called when NotifyingStack.prototype[Symbol.dispose] is called, only when its dispose method is called. Such a subclass would need to also update NotifyingStack.prototype[Symbol.dispose]. This could be a potential footgun in the API.
Likewise AsyncDisposableStack and its disposeAsync, and Symbol.asyncDispose fields.