[whatwg/webidl] Handle exceptions when calling callbacks by default (Issue #1423)

### What is the issue with the Web IDL Standard?

Splitting from https://github.com/whatwg/html/issues/958#issuecomment-226309871.

After https://github.com/whatwg/html/pull/10404 lands, HTML will have a solid foundation for reporting exceptions.

It turns out that most cases, when spec writers use Web IDL to [construct](https://webidl.spec.whatwg.org/#construct-a-callback-function) or [invoke](https://webidl.spec.whatwg.org/#invoke-a-callback-function) callback functions, or to [call a user object's operation](https://webidl.spec.whatwg.org/#call-a-user-objects-operation), they want errors to be reported to the global error handler; they don't want them to propagate out. Such reporting is a safer default.

We should add a new [optional named parameter](https://infra.spec.whatwg.org/#algorithm-params) _rethrowExceptions_ (default false) to these definitions.  When it is false, we introduce the following new behavior: any exceptions thrown by web developer code get caught and routed to HTML's new "report the exception". ("Web developer code" is roughly everything between the "prepare" and "cleanup" steps, including both argument conversion and the actual code invocation.)

Which global do we propagate to? @jeremyroman's research in https://github.com/whatwg/html/pull/10404 settled on the JavaScript function object's realm's global object.

---

Before merging this change, however, we need to have PRs ready for all call sites of construct/invoke/call a user object's operation, to prepare them for the new default. In most cases this will be deleting some spec code that try/catches the exception and reports it. So, this will be a multi-spec project.

We can use these links to find all callers:

- [Invoke](https://dontcallmedom.github.io/webdex/i.html#invoke%40%40webidl%25%25dfn)
- [Call a user object's operation](https://dontcallmedom.github.io/webdex/c.html#call%20a%20user%20object%E2%80%99s%20operation%40%40webidl%25%25dfn)
- [Construct](https://dontcallmedom.github.io/webdex/c.html#construct%40%40webidl%25%25dfn)

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

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

Received on Thursday, 25 July 2024 07:33:25 UTC