Atomics.notify.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. describe("errors", () => {
  2. test("called on non-TypedArray", () => {
  3. expect(() => {
  4. Atomics.notify(Symbol.hasInstance, 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.notify(typedArray, 0, 0);
  12. }).toThrowWithMessage(TypeError, "ArrayBuffer is detached");
  13. });
  14. test("invalid TypedArray type", () => {
  15. expect(() => {
  16. const typedArray = new Float32Array(4);
  17. Atomics.notify(typedArray, 0, 0);
  18. }).toThrowWithMessage(
  19. TypeError,
  20. "Typed array Float32Array element type is not Int32 or BigInt64"
  21. );
  22. });
  23. test("invalid index", () => {
  24. expect(() => {
  25. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  26. const typedArray = new Int32Array(buffer);
  27. Atomics.notify(typedArray, 4, 0);
  28. }).toThrowWithMessage(RangeError, "Index 4 is out of range of array length 4");
  29. });
  30. test("invalid count", () => {
  31. expect(() => {
  32. const buffer = new SharedArrayBuffer(4 * Int32Array.BYTES_PER_ELEMENT);
  33. const typedArray = new Int32Array(buffer);
  34. Atomics.notify(typedArray, 0, Symbol.hasInstance);
  35. }).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
  36. });
  37. });
  38. test("basic functionality", () => {
  39. test("invariants", () => {
  40. expect(Atomics.notify).toHaveLength(3);
  41. });
  42. test("non-shared ArrayBuffer", () => {
  43. const typedArray = new Int32Array(4);
  44. const waiters = Atomics.notify(typedArray, 0, 0);
  45. expect(waiters).toBe(0);
  46. });
  47. });