iterators-core.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var getPrototypeOf = require('../internals/object-get-prototype-of');
  3. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  4. var has = require('../internals/has');
  5. var wellKnownSymbol = require('../internals/well-known-symbol');
  6. var IS_PURE = require('../internals/is-pure');
  7. var ITERATOR = wellKnownSymbol('iterator');
  8. var BUGGY_SAFARI_ITERATORS = false;
  9. var returnThis = function () { return this; };
  10. // `%IteratorPrototype%` object
  11. // https://tc39.github.io/ecma262/#sec-%iteratorprototype%-object
  12. var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
  13. if ([].keys) {
  14. arrayIterator = [].keys();
  15. // Safari 8 has buggy iterators w/o `next`
  16. if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
  17. else {
  18. PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator));
  19. if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype;
  20. }
  21. }
  22. if (IteratorPrototype == undefined) IteratorPrototype = {};
  23. // 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
  24. if (!IS_PURE && !has(IteratorPrototype, ITERATOR)) {
  25. createNonEnumerableProperty(IteratorPrototype, ITERATOR, returnThis);
  26. }
  27. module.exports = {
  28. IteratorPrototype: IteratorPrototype,
  29. BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
  30. };