-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Motivation
In web-sys
, operations that can fail currently return Result<T, JsValue>
. The WebIDL specification lists the exceptions that specification-compliant implementations may throw, namely:
EvalError
RangeError
ReferenceError
TypeError
URIError
DOMException
Since all web_sys
operations are derived from WebIDL, it seems that the error type could be narrowed to the above set.
Proposed Solution
Errors thrown by the WebIDL ECMAScript bindings could be converted to Rust structs implementing Error
. This would further reduce the need of exposing JS objects to the Rust code; for example, parameters are already passed as Rust values and not JsValues
, so modelling errors as Rust values would further hide the JS glue layer as an implementation detail. No idea about the potential performance hit though.
Has this behaviour been considered before and what are the motivations behind the current one?