object-expression-numeric-property.js 821 B

123456789101112131415161718192021222324252627282930
  1. test("numeric properties", () => {
  2. const i32Max = 2 ** 31 - 1;
  3. const u32Max = 2 ** 32 - 1;
  4. const o = {
  5. [-1]: "foo",
  6. 0: "foo",
  7. 1: "foo",
  8. [i32Max - 1]: "foo",
  9. [i32Max]: "foo",
  10. [i32Max + 1]: "foo",
  11. [u32Max - 1]: "foo",
  12. [u32Max]: "foo",
  13. [u32Max + 1]: "foo",
  14. };
  15. // Numeric properties come first in Object.getOwnPropertyNames()'s output,
  16. // which means we can test what each is treated as internally.
  17. expect(Object.getOwnPropertyNames(o)).toEqual([
  18. // Numeric properties
  19. "0",
  20. "1",
  21. "2147483646",
  22. "2147483647",
  23. "2147483648",
  24. "4294967294",
  25. // Non-numeric properties
  26. "-1",
  27. "4294967295", // >= 2^32 - 1
  28. "4294967296", // >= 2^32 - 1
  29. ]);
  30. });