1 use js_sys::*; 2 use wasm_bindgen::prelude::*; 3 use wasm_bindgen::JsCast; 4 use wasm_bindgen_test::*; 5 6 #[wasm_bindgen(module = "tests/wasm/SharedArrayBuffer.js")] 7 extern "C" { is_shared_array_buffer_supported() -> bool8 fn is_shared_array_buffer_supported() -> bool; 9 } 10 11 #[wasm_bindgen_test] new()12fn new() { 13 if !is_shared_array_buffer_supported() { 14 return; 15 } 16 let x = SharedArrayBuffer::new(42); 17 let y: JsValue = x.into(); 18 assert!(y.is_object()); 19 } 20 21 #[wasm_bindgen_test] byte_length()22fn byte_length() { 23 if !is_shared_array_buffer_supported() { 24 return; 25 } 26 let buf = SharedArrayBuffer::new(42); 27 assert_eq!(buf.byte_length(), 42); 28 } 29 30 #[wasm_bindgen_test] slice()31fn slice() { 32 if !is_shared_array_buffer_supported() { 33 return; 34 } 35 let buf = SharedArrayBuffer::new(4); 36 let slice = buf.slice(2); 37 assert!(JsValue::from(slice).is_object()); 38 } 39 40 #[wasm_bindgen_test] slice_with_end()41fn slice_with_end() { 42 if !is_shared_array_buffer_supported() { 43 return; 44 } 45 let buf = SharedArrayBuffer::new(4); 46 let slice = buf.slice_with_end(1, 2); 47 assert!(JsValue::from(slice).is_object()); 48 } 49 50 #[wasm_bindgen_test] sharedarraybuffer_inheritance()51fn sharedarraybuffer_inheritance() { 52 if !is_shared_array_buffer_supported() { 53 return; 54 } 55 let buf = SharedArrayBuffer::new(4); 56 assert!(buf.is_instance_of::<SharedArrayBuffer>()); 57 assert!(buf.is_instance_of::<Object>()); 58 let _: &Object = buf.as_ref(); 59 } 60