proposal-explicit-resource-management icon indicating copy to clipboard operation
proposal-explicit-resource-management copied to clipboard

A subclass that overrides DisposableStack#dispose must also override DisposableStack#[Symbol.dispose]

Open rictic opened this issue 1 year ago • 5 comments

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.

rictic avatar Jun 14 '24 19:06 rictic