Why every method from Location
returns a Result<T, JsValue>
?
#3713
-
Hi I'd like to understand the reasoning behind the setting return value of every methods from the Lets take Following the MDN WebAPI for Why then, instead of returning Trying to study and understand by myself, I found out that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
wasm-bindgen/crates/web-sys/webidls/enabled/Location.webidl Lines 25 to 26 in bb12058 ...Except, the (Copying Firefox's WebIDL instead of using the versions from the actual standards has led to some issues before, e.g. #3227, although I can't remember any particular cases where something was incorrectly annotated with As for whether or not it should return
Apparently it can throw a |
Beta Was this translation helpful? Give feedback.
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 aResult
based on whether it's annotated with a[Throws]
attribute in WebIDL, whichlocation.origin
is:wasm-bindgen/crates/web-sys/webidls/enabled/Location.webidl
Lines 25 to 26 in bb12058
...Except, the
[Throws]
attribute isn't actually an official part of WebIDL. It's a custom addition used by Firefox, which is whereweb-sys
copied most of its WebIDL from. So, the answer to why it returnsResult
is pretty…