js-sys: Add bindings for SyntaxError

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

View File

@ -2496,6 +2496,27 @@ extern {
pub fn values(set: &Set) -> Iterator;
}
// SyntaxError
#[wasm_bindgen]
extern {
/// A SyntaxError is thrown when the JavaScript engine encounters tokens or
/// token order that does not conform to the syntax of the language when
/// parsing code.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError
#[wasm_bindgen(extends = Error)]
#[derive(Clone, Debug)]
pub type SyntaxError;
/// A SyntaxError is thrown when the JavaScript engine encounters tokens or
/// token order that does not conform to the syntax of the language when
/// parsing code.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError
#[wasm_bindgen(constructor)]
pub fn new(message: &str) -> SyntaxError;
}
// 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 syntax_error() {
let error = SyntaxError::new("msg");
assert!(error.is_instance_of::<SyntaxError>());
assert!(error.is_instance_of::<Error>());
let base: &Error = error.as_ref();
assert_eq!(JsValue::from(base.message()), "msg");
}

View File

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