[whatwg/webidl] Add a `disposer` keyword for disposal methods (Issue #1459)

### What problem are you trying to solve?

https://github.com/tc39/proposal-explicit-resource-management is stage 3, with [at least V8 starting to ship](https://chromium.googlesource.com/v8/v8/+/ab8548e43686a8bbb194a6003c5e211b76f177f7%5E%21/). Standards should be able to integrate with that with their existing disposer methods.

### What solutions exist today?

Many standards have methods like `.close()`, `.abort()`, and so on.

### How would you solve it?

Add a `disposer` keyword that interfaces can use to alias a method to `Symbol.dispose`, and a similar `async_disposer` for `Symbol.asyncDispose`.

- All parameters must be optional.
- `async_disposer`s must return promises.

For a few examples:

```webidl
[Exposed=(Window,Worker)]
interface WebSocket : EventTarget {
  // ...
  disposer undefined close(optional [Clamp] unsigned short code, optional USVString reason);
  // ...
};

interface mixin ReadableStreamGenericReader {
  readonly attribute Promise<undefined> closed;

  async_disposer Promise<undefined> cancel(optional any reason);
};

[Exposed=(Window,Worker)]
interface IDBTransaction : EventTarget {
  // ...
  undefined commit();
  disposer undefined abort();
  // ...
};
```

### Anything else?

_No response_

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/1459
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/1459@github.com>

Received on Sunday, 22 December 2024 23:35:35 UTC