Atomics.notify.js 1.9 KB

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