mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-27 20:15:14 +03:00
js-sys: Add bindings to RangeError
This commit is contained in:
parent
adad606ee3
commit
879fd43edb
@ -2084,6 +2084,25 @@ extern {
|
||||
pub fn revocable(target: &JsValue, handler: &Object) -> Object;
|
||||
}
|
||||
|
||||
// RangeError
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
/// The RangeError object indicates an error when a value is not in the set
|
||||
/// or range of allowed values.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError
|
||||
#[wasm_bindgen(extends = Error)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type RangeError;
|
||||
|
||||
/// The RangeError object indicates an error when a value is not in the set
|
||||
/// or range of allowed values.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(message: &str) -> RangeError;
|
||||
}
|
||||
|
||||
// Reflect
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
|
14
crates/js-sys/tests/wasm/RangeError.rs
Normal file
14
crates/js-sys/tests/wasm/RangeError.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 range_error() {
|
||||
let error = RangeError::new("out of range yo");
|
||||
assert!(error.is_instance_of::<RangeError>());
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
|
||||
let base: &Error = error.as_ref();
|
||||
assert_eq!(JsValue::from(base.message()), "out of range yo");
|
||||
}
|
@ -25,6 +25,7 @@ pub mod Math;
|
||||
pub mod Number;
|
||||
pub mod Object;
|
||||
pub mod Proxy;
|
||||
pub mod RangeError;
|
||||
pub mod Reflect;
|
||||
pub mod RegExp;
|
||||
pub mod Set;
|
||||
|
Loading…
Reference in New Issue
Block a user