Add WebAssembly.Memory to js-sys

This adds definitions for the `WebAssembly.Memory` type to `js-sys`.
This commit is contained in:
Alex Crichton
2018-08-21 13:31:31 -07:00
parent 8ce7465bba
commit bb7ca348c2
2 changed files with 55 additions and 0 deletions

View File

@ -153,3 +153,20 @@ fn runtime_error_inheritance() {
let _: &Error = error.as_ref();
}
#[wasm_bindgen_test]
fn memory_works() {
let obj = Object::new();
Reflect::set(obj.as_ref(), &"initial".into(), &1.into());
let mem = WebAssembly::Memory::new(&obj).unwrap();
assert!(mem.is_instance_of::<WebAssembly::Memory>());
assert!(mem.is_instance_of::<Object>());
assert!(mem.buffer().is_instance_of::<ArrayBuffer>());
assert_eq!(mem.grow(1), 1);
assert_eq!(mem.grow(2), 2);
assert_eq!(mem.grow(3), 4);
assert_eq!(
mem.buffer().dyn_into::<ArrayBuffer>().unwrap().byte_length(),
7 * 64 * 1024,
);
}