mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
js-sys: Add bindings for TypeError
This commit is contained in:
parent
38ef5f9ffe
commit
36e15149c7
@ -2517,6 +2517,25 @@ extern {
|
|||||||
pub fn new(message: &str) -> SyntaxError;
|
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
|
// Uint8Array
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
14
crates/js-sys/tests/wasm/TypeError.rs
Normal file
14
crates/js-sys/tests/wasm/TypeError.rs
Normal 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");
|
||||||
|
}
|
@ -33,6 +33,7 @@ pub mod Set;
|
|||||||
pub mod SetIterator;
|
pub mod SetIterator;
|
||||||
pub mod Symbol;
|
pub mod Symbol;
|
||||||
pub mod SyntaxError;
|
pub mod SyntaxError;
|
||||||
|
pub mod TypeError;
|
||||||
pub mod TypedArray;
|
pub mod TypedArray;
|
||||||
pub mod UriError;
|
pub mod UriError;
|
||||||
pub mod WeakMap;
|
pub mod WeakMap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user