From a58c2584b3a9a5d7ba920e1076a54ad17d41e00a Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 10 Aug 2018 13:37:34 -0700 Subject: [PATCH] js-sys: Add bindings to `URIError` --- crates/js-sys/src/lib.rs | 19 +++++++++++++++++++ crates/js-sys/tests/wasm/UriError.rs | 14 ++++++++++++++ crates/js-sys/tests/wasm/main.rs | 1 + 3 files changed, 34 insertions(+) create mode 100644 crates/js-sys/tests/wasm/UriError.rs diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 5d7a0d38..2745f7ef 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2706,6 +2706,25 @@ extern "C" { pub fn byte_offset(this: &Uint32Array) -> u32; } +// URIError +#[wasm_bindgen] +extern { + /// The URIError object represents an error when a global URI handling + /// function was used in a wrong way. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError + #[wasm_bindgen(extends = Error, js_name = URIError)] + #[derive(Clone, Debug)] + pub type UriError; + + /// The URIError object represents an error when a global URI handling + /// function was used in a wrong way. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError + #[wasm_bindgen(constructor, js_class = "URIError")] + pub fn new(message: &str) -> UriError; +} + // WeakMap #[wasm_bindgen] extern "C" { diff --git a/crates/js-sys/tests/wasm/UriError.rs b/crates/js-sys/tests/wasm/UriError.rs new file mode 100644 index 00000000..86ff417e --- /dev/null +++ b/crates/js-sys/tests/wasm/UriError.rs @@ -0,0 +1,14 @@ +use wasm_bindgen::JsValue; +use wasm_bindgen_test::*; +use wasm_bindgen::JsCast; +use js_sys::*; + +#[wasm_bindgen_test] +fn uri_error() { + let error = UriError::new("msg"); + assert!(error.is_instance_of::()); + assert!(error.is_instance_of::()); + + let base: &Error = error.as_ref(); + assert_eq!(JsValue::from(base.message()), "msg"); +} diff --git a/crates/js-sys/tests/wasm/main.rs b/crates/js-sys/tests/wasm/main.rs index 628eb59b..f1e1138b 100755 --- a/crates/js-sys/tests/wasm/main.rs +++ b/crates/js-sys/tests/wasm/main.rs @@ -33,6 +33,7 @@ pub mod Set; pub mod SetIterator; pub mod Symbol; pub mod TypedArray; +pub mod UriError; pub mod WeakMap; pub mod WeakSet; pub mod WebAssembly;