mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 09:11:35 +00:00
Move the js
module to a js_sys
crate (#512)
* Move the `js` module to a `js_sys` crate * Update js-sys tests to pass again * Update binding_to_unimplemented_apis_doesnt_break_everything Remove its dependency on the `js` module * Update metadata for js-sys * Fix the `closures` example
This commit is contained in:
70
crates/js-sys/tests/all/WebAssembly.rs
Normal file
70
crates/js-sys/tests/all/WebAssembly.rs
Normal file
@ -0,0 +1,70 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use super::project;
|
||||
|
||||
#[test]
|
||||
fn validate() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate js_sys;
|
||||
use JsValue;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use js_sys::WebAssembly;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn validate_wasm(wasm: JsValue) -> JsValue {
|
||||
match WebAssembly::validate(wasm) {
|
||||
Ok(value) => value.into(),
|
||||
Err(err) => err
|
||||
}
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.equal(wasm.validate_wasm(new ArrayBuffer(42)), false);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_with_invalid_input() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate js_sys;
|
||||
use JsValue;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use js_sys::WebAssembly;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn validate_wasm(wasm: JsValue) -> JsValue {
|
||||
match WebAssembly::validate(wasm) {
|
||||
Ok(value) => value.into(),
|
||||
Err(err) => err
|
||||
}
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
try {
|
||||
wasm.validate_wasm(42);
|
||||
assert.ok(false);
|
||||
} catch (e) {
|
||||
assert.ok(true);
|
||||
}
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
Reference in New Issue
Block a user