-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normative: Add DOMException cause #1179
base: main
Are you sure you want to change the base?
Conversation
567cfc9
to
1391e74
Compare
de885da
to
6c38523
Compare
6c38523
to
01f2c6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some editorial suggestions. This also aligns the IDL with the style we used for addEventListener()
. Essentially downplaying the role of the legacy argument type which also simplifies the resulting algorithm a bit.
@annevk Thank you for the suggestions! Updated. |
23a767d
to
9eb6302
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good with a suggested nit.
However I had another doubt about the general shape here. Which is, should we really be installing an own data property? That's what Error
does, but we've already decided to depart from Error
for name
and message
, making those getters instead.
I lean slightly toward consistency with DOMException
's existing properties over consistency with Error
, given how in the past I tried to encourage consistency with Error
and failed (see #378).
But this brings us to my next point, which is, it seems like it's time to ask for implementer support for this change. So let's try pinging: @yuki3, @EdgarChen, @petervanderbeken, and @shvaikalesh and see what they say, both on the general proposal and on whether we should do a data property or a readonly attribute (getter) for cause
.
This looks fine to me, but I'd also like it to be consistent with the other DOMException properties (with a getter). I also think the serialization should include this value. |
+1 to make it an accessor property to be consistent. It's great to have an IDL attribute just like 'name', 'message', and 'code'. |
As far as implementor support is concerned, I will implement support in Cloudflare Workers also. |
1e7d80c
to
d0b7e96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good with small issues.
As people seem to be more comfortable with being consistent with IDL attributes on the Also, I've updated the steps to include the |
I'm confused - Making it an accessor on the prototype breaks this highly intentional design decision in ecma262. It's meant to be an own property that is completely absent by default. |
I was in favor of the accessor for consistency with Also tho I sincerely hope nobody ends up needing to spot the distinction between |
Yeah, I think that's a decision we just won't support on the web platform. It seems fine to not support undefined causes as distinct from absent causes. I gave this feedback back when the proposal was in TC39 and it was rejected. But for IDL and the web platform generally we'll use the web-platform-standard idioms of accessors on the prototype and undefined by default. |
Google reps were perfectly able to prevent advancing the language proposal - it seems pretty unfortunate to just callously choose to ignore the result of a standards process just because you don’t like the result. |
We're not ignoring the result of the standards process. The standards process you're discussing was about Error. We have our own standards process on the web platform for DOMException. |
… which inherits from Error, and thus creates user confusion when it deviates from it. |
We discussed this today on the WinterCG call. Most of the attendees did not have strong opinions one way or the other with regard to Specifically from the Cloudflare Workers point of view, because we are aligned with WebIDL, it is easier for us to implement |
@saschanaz nope, i think |
Thanks for the quick answer! That was my impression too.
Sounds like it, but does it / should it practically matter? I think Web IDL generally doesn't try hard to distinguish between explicit |
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 would typically be determined by the value space that needs to be expressed. In the Error Given Web IDL dictionaries don’t need to express this meta value space, it makes sense that they make both cases equivalent and that no one would complain about it; it’s not preventing them from expressing any Web IDL values/not-a-values. I think it seems not far off from "0" / 0 / -0 being semantically equivalent when the dictionary member type is The contract in this case though is that of a non-Web IDL API from a user POV, the API of the (hypothetical, but seemingly intended) “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 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 Aside re: “Web IDL generally doesn't try hard to distinguish between explicit undefined and nonexistence,” I’ve often wished it would try even less hard :) |
Somewhat off-topic, but please file an issue on that against whatwg/html? Seems worth fixing one way or another. |
Possibly notable: console.log("cause" in new WebAssembly.CompileError("xxx", {}));
console.log("cause" in new WebAssembly.CompileError("xxx", { cause: 1 })); already prints |
https://webassembly.github.io/spec/js-api/#error-objects
(WebAssembly being partially defined in Web IDL, but not actually being implemented in terms of Web IDL apparently has a couple of other twists to it.) |
Conceptually, no, unfortunately the reality is a bit different. For those of us who implement The key issue here for me is that For example, try {
doSomething();
} catch (err) {
// It's now completely ambiguous what 'cause' in err means.
// I either have to...
if (err instanceof DOMException) {
// 'cause' in err is meaningless.
} else {
// 'cause' in err has semantic value
}
// or always assume 'cause' in error is meaningless.
} This difference does not just apply to non-browser runtimes. Browser developers will face this same issue. As the other runtimes also implement this, the fact that DOMException does it differently means that developers in general will not be able to rely on it. Now, that said it's absolutely true that JavaScript allows you to throw literally anything so it can be argued that the mechanism is already unreliable, but since const ex = new DOMException();
ex instanceof Error; // true |
Alternatively, if |
The boat has already sailed with message and name. |
And it's too late for Additional thought: Having |
And I think saying that making Also, if we manage to get rid of optional (#905) the natural thing here would be that |
This comment was marked as off-topic.
This comment was marked as off-topic.
This PR looks good to me as is. I don’t see it as important for JS developers to be able to distinguish between undefined and missing cause—how frequently do you want to check whether there is a cause at all? I think it would be good if this PR could land so that web error classes have the significant benefit of this cause feature. This utility is much greater than the edge case being discussed above. For some context for people coming from TC39: it is extremely useful for web specs to stick to WebIDL conventions. Previous attempts to deviate from this pattern (eg streams) were found to be highly complex without developer benefit and were later reverted. I just don’t see why JS developers should care about this case, so I don’t see why it makes sense to invoke priority of constituencies. This is neutral for JS developers, and helpful for implementers. (It is also helpful for spec writers, but they are lower down on the totem pole.) |
# Conflicts: # index.bs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks sensible enough; perhaps https://webidl.spec.whatwg.org/#es-creating-throwing-exceptions should be amended as well.
Using an own property seems like it would make specification and implementation more complicated and bugs more likely for little gain.
What is holding this up at this point?
The gain is spec alignment and matching the design philosophy of the feature, which reduces the likelihood of bugs. If web IDL is getting in the way of that, perhaps that should be addressed? |
And the loss is violating the principle that is applied to all other web platform attributes (as mentioned in #1179 (comment)), which is used for feature detection for example. I think there's no golden answer here, and I'd rather follow the web platform principle as this is a web platform interface. |
Gecko will support this (#1179 (comment)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit
index.bs
Outdated
@@ -14679,6 +14694,7 @@ Their [=serialization steps=], given <var>value</var> and <var>serialized</var>, | |||
<ol> | |||
<li>Set <var>serialized</var>.\[[Name]] to <var>value</var>'s [=DOMException/name=].</li> | |||
<li>Set <var>serialized</var>.\[[Message]] to <var>value</var>'s [=DOMException/message=].</li> | |||
<li>Set <var>serialized</var>.\[[Cause]] to the [=sub-serialization=] of the value of <var>value</var>'s [=DOMException/cause=].</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<li>Set <var>serialized</var>.\[[Cause]] to the [=sub-serialization=] of the value of <var>value</var>'s [=DOMException/cause=].</li> | |
<li>Set <var>serialized</var>.\[[Cause]] to the [=sub-serialization=] of <var>value</var>'s [=DOMException/cause=].</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed!
I'm happy to implement |
Add cause support to DOMException.
Fixes #969
(See WHATWG Working Mode: Changes for more details.)
Preview | Diff