Skip to content

Why every method from Location returns a Result<T, JsValue>? #3713

Answered by Liamolucko
xeho91 asked this question in Q&A
Discussion options

You must be logged in to vote

web-sys is automatically generated from a pile of 'WebIDL' files here, which is how web APIs define their interfaces. In particular, it decides whether or not a function or getter should return a Result based on whether it's annotated with a [Throws] attribute in WebIDL, which location.origin is:

[Throws, NeedsSubjectPrincipal]
readonly attribute USVString origin;

...Except, the [Throws] attribute isn't actually an official part of WebIDL. It's a custom addition used by Firefox, which is where web-sys copied most of its WebIDL from. So, the answer to why it returns Result is pretty…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@xeho91
Comment options

Answer selected by xeho91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants