feat(js) Support exception on WebAssembly::validate.

This commit is contained in:
Ivan Enderlin
2018-07-04 15:51:55 +02:00
parent fe25a9a268
commit c450fbf237
2 changed files with 3 additions and 3 deletions

View File

@ -1148,8 +1148,8 @@ extern "C" {
/// form a valid wasm module (`true`) or not (`false`). /// form a valid wasm module (`true`) or not (`false`).
/// ///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate
#[wasm_bindgen(static_method_of = WebAssembly)] #[wasm_bindgen(static_method_of = WebAssembly, catch)]
pub fn validate(bufferSource: JsValue) -> bool; pub fn validate(bufferSource: JsValue) -> Result<bool, JsValue>;
} }
// JsString // JsString

View File

@ -15,7 +15,7 @@ fn validate() {
#[wasm_bindgen] #[wasm_bindgen]
pub fn validate_wasm(wasm: JsValue) -> bool { pub fn validate_wasm(wasm: JsValue) -> bool {
WebAssembly::validate(wasm) WebAssembly::validate(wasm).unwrap_or(false)
} }
"#) "#)
.file("test.ts", r#" .file("test.ts", r#"