SharedArrayBuffer.rs 1.4 KB

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