.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / define-iterator.js
1 'use strict';
2 var $ = require('../internals/export');
3 var createIteratorConstructor = require('../internals/create-iterator-constructor');
4 var getPrototypeOf = require('../internals/object-get-prototype-of');
5 var setPrototypeOf = require('../internals/object-set-prototype-of');
6 var setToStringTag = require('../internals/set-to-string-tag');
7 var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
8 var redefine = require('../internals/redefine');
9 var wellKnownSymbol = require('../internals/well-known-symbol');
10 var IS_PURE = require('../internals/is-pure');
11 var Iterators = require('../internals/iterators');
12 var IteratorsCore = require('../internals/iterators-core');
13
14 var IteratorPrototype = IteratorsCore.IteratorPrototype;
15 var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
16 var ITERATOR = wellKnownSymbol('iterator');
17 var KEYS = 'keys';
18 var VALUES = 'values';
19 var ENTRIES = 'entries';
20
21 var returnThis = function () { return this; };
22
23 module.exports = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
24   createIteratorConstructor(IteratorConstructor, NAME, next);
25
26   var getIterationMethod = function (KIND) {
27     if (KIND === DEFAULT && defaultIterator) return defaultIterator;
28     if (!BUGGY_SAFARI_ITERATORS && KIND in IterablePrototype) return IterablePrototype[KIND];
29     switch (KIND) {
30       case KEYS: return function keys() { return new IteratorConstructor(this, KIND); };
31       case VALUES: return function values() { return new IteratorConstructor(this, KIND); };
32       case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); };
33     } return function () { return new IteratorConstructor(this); };
34   };
35
36   var TO_STRING_TAG = NAME + ' Iterator';
37   var INCORRECT_VALUES_NAME = false;
38   var IterablePrototype = Iterable.prototype;
39   var nativeIterator = IterablePrototype[ITERATOR]
40     || IterablePrototype['@@iterator']
41     || DEFAULT && IterablePrototype[DEFAULT];
42   var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT);
43   var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
44   var CurrentIteratorPrototype, methods, KEY;
45
46   // fix native
47   if (anyNativeIterator) {
48     CurrentIteratorPrototype = getPrototypeOf(anyNativeIterator.call(new Iterable()));
49     if (IteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) {
50       if (!IS_PURE && getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype) {
51         if (setPrototypeOf) {
52           setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype);
53         } else if (typeof CurrentIteratorPrototype[ITERATOR] != 'function') {
54           createNonEnumerableProperty(CurrentIteratorPrototype, ITERATOR, returnThis);
55         }
56       }
57       // Set @@toStringTag to native iterators
58       setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true);
59       if (IS_PURE) Iterators[TO_STRING_TAG] = returnThis;
60     }
61   }
62
63   // fix Array#{values, @@iterator}.name in V8 / FF
64   if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
65     INCORRECT_VALUES_NAME = true;
66     defaultIterator = function values() { return nativeIterator.call(this); };
67   }
68
69   // define iterator
70   if ((!IS_PURE || FORCED) && IterablePrototype[ITERATOR] !== defaultIterator) {
71     createNonEnumerableProperty(IterablePrototype, ITERATOR, defaultIterator);
72   }
73   Iterators[NAME] = defaultIterator;
74
75   // export additional methods
76   if (DEFAULT) {
77     methods = {
78       values: getIterationMethod(VALUES),
79       keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
80       entries: getIterationMethod(ENTRIES)
81     };
82     if (FORCED) for (KEY in methods) {
83       if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
84         redefine(IterablePrototype, KEY, methods[KEY]);
85       }
86     } else $({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
87   }
88
89   return methods;
90 };