Atomics.waitAsync.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. describe("errors", () => {
  2. test("called on non-TypedArray", () => {
  3. expect(() => {
  4. Atomics.waitAsync(Symbol.hasInstance, 0, 0, 0);
  5. }).toThrowWithMessage(TypeError, "Not an object of type TypedArray");
  6. });
  7. test("detached buffer", () => {
  8. expect(() => {
  9. const typedArray = new Int32Array(4);
  10. detachArrayBuffer(typedArray.buffer);
  11. Atomics.waitAsync(typedArray, 0, 0, 0);
  12. }).toThrowWithMessage(
  13. TypeError,
  14. "TypedArray contains a property which references a value at an index not contained within its buffer's bounds"
  15. );
  16. });
  17. test("invalid TypedArray type", () => {
  18. expect(() => {
  19. const typedArray = new Float32Array(4);
  20. Atomics.waitAsync(typedArray, 0, 0, 0);
  21. }).toThrowWithMessage(
  22. TypeError,
  23. "Typed array Float32Array element type is not Int32 or BigInt64"
  24. );
  25. });
  26. test("non-shared ArrayBuffer", () => {
  27. expect(() => {
  28. const typedArray = new Int32Array(4);
  29. Atomics.waitAsync(typedArray, 0, 0, 0);
  30. }).toThrowWithMessage(TypeError, "The array buffer object must be a SharedArrayBuffer");
  31. });
  32. test("invalid index", () => {
  33. expect(() => {
  34. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  35. const typedArray = new Int32Array(buffer);
  36. Atomics.waitAsync(typedArray, 4, 0, 0);
  37. }).toThrowWithMessage(RangeError, "Index 4 is out of range of array length 4");
  38. });
  39. test("invalid value", () => {
  40. expect(() => {
  41. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  42. const typedArray = new Int32Array(buffer);
  43. Atomics.waitAsync(typedArray, 0, Symbol.hasInstance, 0);
  44. }).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
  45. expect(() => {
  46. const buffer = new SharedArrayBuffer(4 * BigInt64Array.BYTES_PER_ELEMENT);
  47. const typedArray = new BigInt64Array(buffer);
  48. Atomics.waitAsync(typedArray, 0, Symbol.hasInstance, 0);
  49. }).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt");
  50. });
  51. test("invalid timeout", () => {
  52. expect(() => {
  53. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  54. const typedArray = new Int32Array(buffer);
  55. Atomics.waitAsync(typedArray, 0, 0, Symbol.hasInstance);
  56. }).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
  57. });
  58. });
  59. test("basic functionality", () => {
  60. test("invariants", () => {
  61. expect(Atomics.waitAsync).toHaveLength(4);
  62. });
  63. });