Skip to content

Commit af22a26

Browse files
author
ibaryshnikov
committed
added tests for SharedArrayBuffer
1 parent 7e512ba commit af22a26

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

crates/js-sys/tests/wasm/ArrayBuffer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ fn is_view() {
2222
assert!(ArrayBuffer::is_view(&JsValue::from(x)));
2323
}
2424

25-
#[test]
25+
#[wasm_bindgen_test]
2626
fn slice() {
2727
let buf = ArrayBuffer::new(4);
2828
let slice = buf.slice(2);
2929
assert!(JsValue::from(slice).is_object());
3030
}
3131

32-
#[test]
32+
#[wasm_bindgen_test]
3333
fn slice_with_end() {
3434
let buf = ArrayBuffer::new(4);
3535
let slice = buf.slice_with_end(1, 2);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exports.is_shared_array_buffer_supported = function () {
2+
return typeof SharedArrayBuffer === 'function';
3+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use js_sys::*;
2+
use wasm_bindgen::JsCast;
3+
use wasm_bindgen::prelude::*;
4+
use wasm_bindgen_test::*;
5+
6+
#[wasm_bindgen(module = "tests/wasm/SharedArrayBuffer.js")]
7+
extern "C" {
8+
fn is_shared_array_buffer_supported() -> bool;
9+
}
10+
11+
#[wasm_bindgen_test]
12+
fn 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]
22+
fn 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]
31+
fn 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]
41+
fn 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]
51+
fn 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+
}

crates/js-sys/tests/wasm/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod Reflect;
3434
pub mod RegExp;
3535
pub mod Set;
3636
pub mod SetIterator;
37+
pub mod SharedArrayBuffer;
3738
pub mod Symbol;
3839
pub mod SyntaxError;
3940
pub mod TypeError;

0 commit comments

Comments
 (0)