mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 16:51:33 +00:00
feat(js) Implement the WebAssembly.validate
binding.
This commit is contained in:
14
src/js.rs
14
src/js.rs
@ -1138,6 +1138,20 @@ extern "C" {
|
|||||||
pub fn delete(this: &WeakSet, value: Object) -> bool;
|
pub fn delete(this: &WeakSet, value: Object) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebAssembly
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
pub type WebAssembly;
|
||||||
|
|
||||||
|
/// The `WebAssembly.validate()` function validates a given typed
|
||||||
|
/// array of WebAssembly binary code, returning whether the bytes
|
||||||
|
/// form a valid wasm module (`true`) or not (`false`).
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate
|
||||||
|
#[wasm_bindgen(static_method_of = WebAssembly)]
|
||||||
|
pub fn validate(bufferSource: JsValue) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
// JsString
|
// JsString
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
30
tests/all/js_globals/WebAssembly.rs
Normal file
30
tests/all/js_globals/WebAssembly.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
use super::project;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn validate() {
|
||||||
|
project()
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use JsValue;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js::WebAssembly;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn validate_wasm(wasm: JsValue) -> bool {
|
||||||
|
WebAssembly::validate(wasm)
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
assert.equal(wasm.validate_wasm(new ArrayBuffer(42)), false);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
@ -20,6 +20,7 @@ mod SetIterator;
|
|||||||
mod TypedArray;
|
mod TypedArray;
|
||||||
mod WeakMap;
|
mod WeakMap;
|
||||||
mod WeakSet;
|
mod WeakSet;
|
||||||
|
mod WebAssembly;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
Reference in New Issue
Block a user