js-sys: Add bindings for TypeError

This commit is contained in:
Nick Fitzgerald 2018-08-10 13:45:39 -07:00
parent 38ef5f9ffe
commit 36e15149c7
3 changed files with 34 additions and 0 deletions

View File

@ -2517,6 +2517,25 @@ extern {
pub fn new(message: &str) -> SyntaxError;
}
// TypeError
#[wasm_bindgen]
extern {
/// The TypeError object represents an error when a value is not of the
/// expected type.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError
#[wasm_bindgen(extends = Error)]
#[derive(Clone, Debug)]
pub type TypeError;
/// The TypeError object represents an error when a value is not of the
/// expected type.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError
#[wasm_bindgen(constructor)]
pub fn new(message: &str) -> TypeError;
}
// Uint8Array
#[wasm_bindgen]
extern "C" {

View File

@ -0,0 +1,14 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
fn type_error() {
let error = TypeError::new("msg");
assert!(error.is_instance_of::<TypeError>());
assert!(error.is_instance_of::<Error>());
let base: &Error = error.as_ref();
assert_eq!(JsValue::from(base.message()), "msg");
}

View File

@ -33,6 +33,7 @@ pub mod Set;
pub mod SetIterator;
pub mod Symbol;
pub mod SyntaxError;
pub mod TypeError;
pub mod TypedArray;
pub mod UriError;
pub mod WeakMap;