tc39 / proposal-is-error

ECMAScript Proposal, specs, and reference implementation for Error.isError
https://tc39.es/proposal-is-error/
MIT License
62 stars 2 forks source link

HTML integration #9

Closed ljharb closed 1 week ago

ljharb commented 2 months ago

A PR will be needed, ideally before stage 2.7 (although this would otherwise be a concern to be addressed within 2.7) to ensure that DOM exceptions are considered to be Errors.

Some potential implementation strategies:

  1. add the ErrorData internal slot to DOM exceptions, and accept the implicit observable change when used with Object.prototype.toString and a deleted Symbol.toStringTag
  2. add a new host hook, that the web can use to indicate which of its errors are Errors
    1. optionally, check the host hook in Object.prototype.toString so that host errors are indistinguishable from true Error subclasses
ljharb commented 2 months ago

(see #6)

annevk commented 2 months ago

The main place that needs changes is https://webidl.spec.whatwg.org/#js-exceptions, not HTML.

There might be some implications for HTML's StructuredSerializeInternal and friends as they currently branch on [[ErrorData]]. Perhaps that would allow us to redo https://github.com/whatwg/webidl/pull/732 in some way whereby Web IDL no longer relies on HTML for that? Unclear.

I do kinda like 1 as it brings Error and DOMException even closer together.

cc @domenic

domenic commented 2 months ago

1 seems nicer to me, assuming implementations are willing to deal with the compat implications. Which seem like they should be minuscule, but, you never know.

ljharb commented 2 months ago

I definitely agree that 1 seems nicer if we can swing it.

I’ll attempt a PR for that approach, and we can discuss further from there.

ljharb commented 1 month ago

Filed https://github.com/whatwg/webidl/pull/1421 as a starting point. I expect it'll need a lot of suggestions, so please review it!

ljharb commented 1 week ago

The PR has been "directionally" approved, with only editorial changes needed, so I'm going to close this.