object-expression-numeric-property.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. });
  31. test("big int properties", () => {
  32. const o = {
  33. [-1n]: "foo",
  34. 0n: "foo",
  35. 1n: "foo",
  36. [12345678901n]: "foo",
  37. [4294967294n]: "foo",
  38. [4294967295n]: "foo",
  39. };
  40. // Numeric properties come first in Object.getOwnPropertyNames()'s output,
  41. // which means we can test what each is treated as internally.
  42. expect(Object.getOwnPropertyNames(o)).toEqual([
  43. // Numeric properties
  44. "0",
  45. "1",
  46. "4294967294",
  47. // Non-numeric properties
  48. "-1",
  49. "12345678901", // >= 2^32 - 1
  50. "4294967295", // >= 2^32 - 1
  51. ]);
  52. });