1 | 'use strict';
|
---|
2 | var fails = require('../internals/fails');
|
---|
3 | var isCallable = require('../internals/is-callable');
|
---|
4 | var isObject = require('../internals/is-object');
|
---|
5 | var create = require('../internals/object-create');
|
---|
6 | var getPrototypeOf = require('../internals/object-get-prototype-of');
|
---|
7 | var defineBuiltIn = require('../internals/define-built-in');
|
---|
8 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
9 | var IS_PURE = require('../internals/is-pure');
|
---|
10 |
|
---|
11 | var ITERATOR = wellKnownSymbol('iterator');
|
---|
12 | var BUGGY_SAFARI_ITERATORS = false;
|
---|
13 |
|
---|
14 | // `%IteratorPrototype%` object
|
---|
15 | // https://tc39.es/ecma262/#sec-%iteratorprototype%-object
|
---|
16 | var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
|
---|
17 |
|
---|
18 | /* eslint-disable es/no-array-prototype-keys -- safe */
|
---|
19 | if ([].keys) {
|
---|
20 | arrayIterator = [].keys();
|
---|
21 | // Safari 8 has buggy iterators w/o `next`
|
---|
22 | if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
|
---|
23 | else {
|
---|
24 | PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator));
|
---|
25 | if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype;
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | var NEW_ITERATOR_PROTOTYPE = !isObject(IteratorPrototype) || fails(function () {
|
---|
30 | var test = {};
|
---|
31 | // FF44- legacy iterators case
|
---|
32 | return IteratorPrototype[ITERATOR].call(test) !== test;
|
---|
33 | });
|
---|
34 |
|
---|
35 | if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype = {};
|
---|
36 | else if (IS_PURE) IteratorPrototype = create(IteratorPrototype);
|
---|
37 |
|
---|
38 | // `%IteratorPrototype%[@@iterator]()` method
|
---|
39 | // https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
|
---|
40 | if (!isCallable(IteratorPrototype[ITERATOR])) {
|
---|
41 | defineBuiltIn(IteratorPrototype, ITERATOR, function () {
|
---|
42 | return this;
|
---|
43 | });
|
---|
44 | }
|
---|
45 |
|
---|
46 | module.exports = {
|
---|
47 | IteratorPrototype: IteratorPrototype,
|
---|
48 | BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
|
---|
49 | };
|
---|