-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib: make DOMException attributes configurable and enumerable #22550
Conversation
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 for this – not sure how I overlooked it when creating the class. I have become a fan of the way TextEncoder sets the property descriptor bits though, as something like this:
class DOMException ... {
get name() {
// …
}
get message() {
// …
}
}
Object.defineProperties(DOMException.prototype, {
name: { enumerable: true },
message: { enumerable: true }
});
This has several advantages, the first being that we can continue to use the nice class syntax, and the second being that Object.getOwnPropertyDescriptor(DOMException.prototype, 'name').get.name
would be 'get name'
rather than 'get'
, which is what the IDL spec mandates (see step 3).
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.
couldn't we also use defineIDLClass
@TimothyGu Indeed that looks nicer! Thanks for the suggestion, I'll switch to that.
@devsnek |
I have mixed feels about Node throwing DOM exceptions. Update: I mean if we're doing it, then it should be correct, but I can see this being slippery. |
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.
@@ -43,6 +43,12 @@ class DOMException extends Error { | |||
} | |||
} | |||
|
|||
Object.defineProperties(DOMException.prototype, { | |||
name: { enumerable: true, configurable: true }, |
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.
Nit: the configurable: true
isn't necessary, as the property is already configurable and Object.defineProperties won't override it.
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'd prefer to be explicit here since Object.defineProperties
will read inherited properties of descriptors and Node internals aren't run in an isolated realm yet.
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.
DOMException
was created right above this with its prototype having them as own properties, so that is not an issue here.
@jdalton, it was a conscious decision when the class was added to not expose it globally, precisely because of the "slippery slope" you mentioned. It is instead only used where it's necessary for compatibility with HTML's |
Ah, it does 👍 Update: Other thought: I'm not sure if it's implied but at least in Chrome the |
Oh yeah, this probably needs [Symbol.toStringTag]: { configurable: true, value: 'DOMException' } @jdalton Would you be open to approving this PR once that's fixed? |
Yep, this is already out of the bottle. The main reason I held is because it had more than 2 approvals, meaning a merge could be imminent, and I wanted a bit more discussion. |
I don't quite understand...do you want more discussion about the enumerability of these existing properties? If not, in general we open new issues or PRs to discuss, instead of trying to fix everything in one PR. |
Following up, I dug up spec bits I think are relevant for the The While it doesn't state having |
@jdalton Can you open another PR for the
that you requested? I don't see why those have to be fixed in this particular PR and block this one? |
My requested change is in line with "align DOMException with the Web" and is just an additional line after the 3 properties you've defined. |
Does it help if I change the commit title to "lib: make DOMException attributes configurable and enumerable"? I don't mind fixing those myself, but personally even if I fix them in this PR I would not squash them into the first commit when I land the changes, so I'd prefer to have another PR open for that (In general I prefer to squash every commit in one PR whenever possible and keep commits that should be separated in different PR). |
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 (no matter if we add the toStringTag in this PR or not and no strong opinion about explicitly adding configurable: true
)
The `name`, `message` and `code` attributes of the DOMException interface should be enumerable and configurable. Aligning the definition with the Web allows us to use it when running the Web Platform Tests. Refs: https://heycam.github.io/webidl/#idl-DOMException
f1dd395
to
c4d3df8
Compare
Rebased and renamed the PR to focus on the enumerability and configurability. I think other compliance issues can be dealt with in another PR - I'll open one next week if no one picks it up. |
@jdalton Do you insist that this PR fixing the enumerability and configurability cannot land until other attributes get fixed? |
@joyeecheung Yes please. It's a single additional attribute and I believe a reasonable change request. |
CI is green |
PR-URL: #22933 Refs: #22550 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 676bd5f, thanks! |
The `name`, `message` and `code` attributes of the DOMException interface should be enumerable and configurable. Aligning the definition with the Web allows us to use it when running the Web Platform Tests. Refs: https://heycam.github.io/webidl/#idl-DOMException PR-URL: #22550 Refs: web-platform-tests/wpt@125950d Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #22933 Refs: #22550 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
The `name`, `message` and `code` attributes of the DOMException interface should be enumerable and configurable. Aligning the definition with the Web allows us to use it when running the Web Platform Tests. Refs: https://heycam.github.io/webidl/#idl-DOMException PR-URL: #22550 Refs: web-platform-tests/wpt@125950d Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
The
name
,message
andcode
attributes of the DOMExceptioninterface should be enumerable and configurable. Aligning
the definition with the Web allows us to use it when
running the Web Platform Tests.
Refs: https://heycam.github.io/webidl/#idl-DOMException
Refs: web-platform-tests/wpt@125950d
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes