You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

4 years ago
  1. 'use strict';
  2. var GetIntrinsic = require('./GetIntrinsic');
  3. var ES2016 = require('./es2016');
  4. var assign = require('./helpers/assign');
  5. var forEach = require('./helpers/forEach');
  6. var callBind = require('./helpers/callBind');
  7. var $TypeError = GetIntrinsic('%TypeError%');
  8. var callBound = require('./helpers/callBound');
  9. var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
  10. var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));
  11. var $arrayPush = callBound('Array.prototype.push');
  12. var ES2017 = assign(assign({}, ES2016), {
  13. ToIndex: function ToIndex(value) {
  14. if (typeof value === 'undefined') {
  15. return 0;
  16. }
  17. var integerIndex = this.ToInteger(value);
  18. if (integerIndex < 0) {
  19. throw new RangeError('index must be >= 0');
  20. }
  21. var index = this.ToLength(integerIndex);
  22. if (!this.SameValueZero(integerIndex, index)) {
  23. throw new RangeError('index must be >= 0 and < 2 ** 53 - 1');
  24. }
  25. return index;
  26. },
  27. // https://www.ecma-international.org/ecma-262/8.0/#sec-enumerableownproperties
  28. EnumerableOwnProperties: function EnumerableOwnProperties(O, kind) {
  29. var keys = ES2016.EnumerableOwnNames(O);
  30. if (kind === 'key') {
  31. return keys;
  32. }
  33. if (kind === 'value' || kind === 'key+value') {
  34. var results = [];
  35. forEach(keys, function (key) {
  36. if ($isEnumerable(O, key)) {
  37. $pushApply(results, [
  38. kind === 'value' ? O[key] : [key, O[key]]
  39. ]);
  40. }
  41. });
  42. return results;
  43. }
  44. throw new $TypeError('Assertion failed: "kind" is not "key", "value", or "key+value": ' + kind);
  45. },
  46. // https://www.ecma-international.org/ecma-262/8.0/#sec-iterabletolist
  47. IterableToList: function IterableToList(items, method) {
  48. var iterator = this.GetIterator(items, method);
  49. var values = [];
  50. var next = true;
  51. while (next) {
  52. next = this.IteratorStep(iterator);
  53. if (next) {
  54. var nextValue = this.IteratorValue(next);
  55. $arrayPush(values, nextValue);
  56. }
  57. }
  58. return values;
  59. }
  60. });
  61. delete ES2017.EnumerableOwnNames; // replaced with EnumerableOwnProperties
  62. delete ES2017.IterableToArrayLike; // replaced with IterableToList
  63. module.exports = ES2017;