Skip to content

web-sys: More precise exception types #2004

@strax

Description

@strax

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions