Atomics.wait.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. describe("errors", () => {
  2. test("called on non-TypedArray", () => {
  3. expect(() => {
  4. Atomics.wait(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.wait(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.wait(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.wait(typedArray, 0, 0, 0);
  30. }).toThrowWithMessage(
  31. TypeError,
  32. "The TypedArray's underlying buffer must be a SharedArrayBuffer"
  33. );
  34. });
  35. test("invalid index", () => {
  36. expect(() => {
  37. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  38. const typedArray = new Int32Array(buffer);
  39. Atomics.wait(typedArray, 4, 0, 0);
  40. }).toThrowWithMessage(RangeError, "Index 4 is out of range of array length 4");
  41. });
  42. test("invalid value", () => {
  43. expect(() => {
  44. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  45. const typedArray = new Int32Array(buffer);
  46. Atomics.wait(typedArray, 0, Symbol.hasInstance, 0);
  47. }).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
  48. expect(() => {
  49. const buffer = new SharedArrayBuffer(4 * BigInt64Array.BYTES_PER_ELEMENT);
  50. const typedArray = new BigInt64Array(buffer);
  51. Atomics.wait(typedArray, 0, Symbol.hasInstance, 0);
  52. }).toThrowWithMessage(TypeError, "Cannot convert symbol to BigInt");
  53. });
  54. test("invalid timeout", () => {
  55. expect(() => {
  56. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  57. const typedArray = new Int32Array(buffer);
  58. Atomics.wait(typedArray, 0, 0, Symbol.hasInstance);
  59. }).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
  60. });
  61. });
  62. test("basic functionality", () => {
  63. test("invariants", () => {
  64. expect(Atomics.wait).toHaveLength(4);
  65. });
  66. });