es2017.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. var bind = require('function-bind');
  3. var ES2016 = require('./es2016');
  4. var assign = require('./helpers/assign');
  5. var forEach = require('./helpers/forEach');
  6. var GetIntrinsic = require('./GetIntrinsic');
  7. var $TypeError = GetIntrinsic('%TypeError%');
  8. var $isEnumerable = bind.call(Function.call, GetIntrinsic('%ObjectPrototype%').propertyIsEnumerable);
  9. var $pushApply = bind.call(Function.apply, GetIntrinsic('%ArrayPrototype%').push);
  10. var ES2017 = assign(assign({}, ES2016), {
  11. ToIndex: function ToIndex(value) {
  12. if (typeof value === 'undefined') {
  13. return 0;
  14. }
  15. var integerIndex = this.ToInteger(value);
  16. if (integerIndex < 0) {
  17. throw new RangeError('index must be >= 0');
  18. }
  19. var index = this.ToLength(integerIndex);
  20. if (!this.SameValueZero(integerIndex, index)) {
  21. throw new RangeError('index must be >= 0 and < 2 ** 53 - 1');
  22. }
  23. return index;
  24. },
  25. // https://www.ecma-international.org/ecma-262/8.0/#sec-enumerableownproperties
  26. EnumerableOwnProperties: function EnumerableOwnProperties(O, kind) {
  27. var keys = ES2016.EnumerableOwnNames(O);
  28. if (kind === 'key') {
  29. return keys;
  30. }
  31. if (kind === 'value' || kind === 'key+value') {
  32. var results = [];
  33. forEach(keys, function (key) {
  34. if ($isEnumerable(O, key)) {
  35. $pushApply(results, [
  36. kind === 'value' ? O[key] : [key, O[key]]
  37. ]);
  38. }
  39. });
  40. return results;
  41. }
  42. throw new $TypeError('Assertion failed: "kind" is not "key", "value", or "key+value": ' + kind);
  43. }
  44. });
  45. delete ES2017.EnumerableOwnNames; // replaced with EnumerableOwnProperties
  46. module.exports = ES2017;