js-sys: Add bindings to ReferenceError

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

View File

@ -2103,6 +2103,25 @@ extern {
pub fn new(message: &str) -> RangeError;
}
// ReferenceError
#[wasm_bindgen]
extern {
/// The ReferenceError object represents an error when a non-existent
/// variable is referenced.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError
#[wasm_bindgen(extends = Error)]
#[derive(Clone, Debug)]
pub type ReferenceError;
/// The ReferenceError object represents an error when a non-existent
/// variable is referenced.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError
#[wasm_bindgen(constructor)]
pub fn new(message: &str) -> ReferenceError;
}
// 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 reference_error() {
let error = ReferenceError::new("bad reference, fool");
assert!(error.is_instance_of::<ReferenceError>());
assert!(error.is_instance_of::<Error>());
let base: &Error = error.as_ref();
assert_eq!(JsValue::from(base.message()), "bad reference, fool");
}

View File

@ -26,6 +26,7 @@ pub mod Number;
pub mod Object;
pub mod Proxy;
pub mod RangeError;
pub mod ReferenceError;
pub mod Reflect;
pub mod RegExp;
pub mod Set;