js-sys: Add bindings to RangeError

This commit is contained in:
Nick Fitzgerald 2018-08-10 13:03:44 -07:00
parent adad606ee3
commit 879fd43edb
3 changed files with 34 additions and 0 deletions

View File

@ -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" {

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 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");
}

View File

@ -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;