values.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
  3. var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
  4. var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
  5. var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
  6. var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
  7. var objects = [{}, coercibleObject, toStringOnlyObject, valueOfOnlyObject];
  8. var nullPrimitives = [undefined, null];
  9. var nonIntegerNumbers = [-1.3, 0.2, 1.8, 1 / 3];
  10. var numbers = [0, -0, Infinity, -Infinity, 42].concat(nonIntegerNumbers);
  11. var strings = ['', 'foo', 'a\uD83D\uDCA9c'];
  12. var booleans = [true, false];
  13. var symbols = hasSymbols ? [Symbol.iterator, Symbol('foo')] : [];
  14. var nonSymbolPrimitives = [].concat(nullPrimitives, booleans, strings, numbers);
  15. var nonNumberPrimitives = [].concat(nullPrimitives, booleans, strings, symbols);
  16. var nonNullPrimitives = [].concat(booleans, strings, numbers, symbols);
  17. var nonUndefinedPrimitives = [].concat(null, nonNullPrimitives);
  18. var nonStrings = [].concat(nullPrimitives, booleans, numbers, symbols, objects);
  19. var primitives = [].concat(nullPrimitives, nonNullPrimitives);
  20. var nonPropertyKeys = [].concat(nullPrimitives, booleans, numbers, objects);
  21. var propertyKeys = [].concat(strings, symbols);
  22. var nonBooleans = [].concat(nullPrimitives, strings, symbols, numbers, objects);
  23. var falsies = [].concat(nullPrimitives, false, '', 0, -0, NaN);
  24. var truthies = [].concat(true, 'foo', 42, symbols, objects);
  25. var timestamps = [].concat(0, 946713600000, 1546329600000);
  26. module.exports = {
  27. coercibleObject: coercibleObject,
  28. valueOfOnlyObject: valueOfOnlyObject,
  29. toStringOnlyObject: toStringOnlyObject,
  30. uncoercibleObject: uncoercibleObject,
  31. objects: objects,
  32. nullPrimitives: nullPrimitives,
  33. numbers: numbers,
  34. strings: strings,
  35. booleans: booleans,
  36. symbols: symbols,
  37. hasSymbols: hasSymbols,
  38. nonSymbolPrimitives: nonSymbolPrimitives,
  39. nonNumberPrimitives: nonNumberPrimitives,
  40. nonNullPrimitives: nonNullPrimitives,
  41. nonUndefinedPrimitives: nonUndefinedPrimitives,
  42. nonStrings: nonStrings,
  43. nonNumbers: nonNumberPrimitives.concat(objects),
  44. nonIntegerNumbers: nonIntegerNumbers,
  45. primitives: primitives,
  46. nonPropertyKeys: nonPropertyKeys,
  47. propertyKeys: propertyKeys,
  48. nonBooleans: nonBooleans,
  49. falsies: falsies,
  50. truthies: truthies,
  51. timestamps: timestamps,
  52. bothDescriptor: function () {
  53. return { '[[Get]]': function () {}, '[[Value]]': true };
  54. },
  55. accessorDescriptor: function () {
  56. return {
  57. '[[Get]]': function () {},
  58. '[[Enumerable]]': true,
  59. '[[Configurable]]': true
  60. };
  61. },
  62. mutatorDescriptor: function () {
  63. return {
  64. '[[Set]]': function () {},
  65. '[[Enumerable]]': true,
  66. '[[Configurable]]': true
  67. };
  68. },
  69. dataDescriptor: function () {
  70. return {
  71. '[[Value]]': 42,
  72. '[[Writable]]': false
  73. };
  74. },
  75. genericDescriptor: function () {
  76. return {
  77. '[[Configurable]]': true,
  78. '[[Enumerable]]': false
  79. };
  80. }
  81. };