Re: [whatwg/webidl] Normative: Add DOMException cause (PR #1179)

> I think Web IDL generally doesn't try hard to distinguish between explicit undefined and nonexistence (e.g. dictionaries treat explicit undefined as nonexistent), and I believe nobody complained with it.

Whether property absence & property access evaluating to undefined are semantically equivalent or distinct is a characteristic of an API contract, not of properties/objects inherently, and I’d figure the decision is typically informed by the value space that needs to be expressed. In the Error `cause` contract (and a few other places in ECMA-262), property absence is used to express a +1 language value space: “all ES values or none”. It’s the least painful mechanism the language has for expressing this `empty` notion: a “third null” (cursed lol — not-a-value `NaV`?) couldn’t do the same because when reified as a (public) ES value, it’s “an ES value” and you’re back at square one. The next best thing is pretty gross: a second property (`causeIsEmpty: true`) for the extra information bit.

Given Web IDL dictionaries don’t need to express this meta value space, it makes sense that they make both cases equivalent (it seems not far off from "0" / 0 / -0 being semantically equivalent when the dictionary member type is `unsigned long`: smaller value space = more conversion & conflation desirable). The contract in this case though is that of a non-Web IDL API though from a user POV, the API of the (at least hypothetical) “super class” (and its other subclasses, notably?). I’m not sure the question of whether the semantic distinction _should have_ been made ought to determine what’s done here. Perhaps the empty/undefined distinction might never help anybody debug anything, but I’m pretty sure `cause`-always-present will create some. People will end up using this check regardless and writing tests for whether some catch logic behaves right for each native/platform Error subclass would be unusual.

While I don’t have a strong opinion on whether the distinction was worth making, I haven’t understood why it’d be so off-the-table to — in intuitive, not literal terms — “just pass it to `super()`”. Is it a pain for implementators?

---

Aside re: _“Web IDL Web IDL generally doesn't try hard to distinguish between explicit undefined and nonexistence,”_  I’ve often wished it would try even _less_ hard :)

![Chromium console showing history.pushState(1) throwing due to arity — the undefined/absence distinction — while history.pushState(1, undefined) succeeds](https://user-images.githubusercontent.com/6257356/189460681-294efc65-a6dc-4ce5-88c3-c8031bd929f3.png)



-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1179#issuecomment-1242568486

You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/pull/1179/c1242568486@github.com>

Received on Saturday, 10 September 2022 00:11:03 UTC