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