1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var globalThis = require('../internals/global-this');
|
---|
4 | var anInstance = require('../internals/an-instance');
|
---|
5 | var anObject = require('../internals/an-object');
|
---|
6 | var isCallable = require('../internals/is-callable');
|
---|
7 | var getPrototypeOf = require('../internals/object-get-prototype-of');
|
---|
8 | var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
|
---|
9 | var createProperty = require('../internals/create-property');
|
---|
10 | var fails = require('../internals/fails');
|
---|
11 | var hasOwn = require('../internals/has-own-property');
|
---|
12 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
13 | var IteratorPrototype = require('../internals/iterators-core').IteratorPrototype;
|
---|
14 | var DESCRIPTORS = require('../internals/descriptors');
|
---|
15 | var IS_PURE = require('../internals/is-pure');
|
---|
16 |
|
---|
17 | var CONSTRUCTOR = 'constructor';
|
---|
18 | var ITERATOR = 'Iterator';
|
---|
19 | var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
---|
20 |
|
---|
21 | var $TypeError = TypeError;
|
---|
22 | var NativeIterator = globalThis[ITERATOR];
|
---|
23 |
|
---|
24 | // FF56- have non-standard global helper `Iterator`
|
---|
25 | var FORCED = IS_PURE
|
---|
26 | || !isCallable(NativeIterator)
|
---|
27 | || NativeIterator.prototype !== IteratorPrototype
|
---|
28 | // FF44- non-standard `Iterator` passes previous tests
|
---|
29 | || !fails(function () { NativeIterator({}); });
|
---|
30 |
|
---|
31 | var IteratorConstructor = function Iterator() {
|
---|
32 | anInstance(this, IteratorPrototype);
|
---|
33 | if (getPrototypeOf(this) === IteratorPrototype) throw new $TypeError('Abstract class Iterator not directly constructable');
|
---|
34 | };
|
---|
35 |
|
---|
36 | var defineIteratorPrototypeAccessor = function (key, value) {
|
---|
37 | if (DESCRIPTORS) {
|
---|
38 | defineBuiltInAccessor(IteratorPrototype, key, {
|
---|
39 | configurable: true,
|
---|
40 | get: function () {
|
---|
41 | return value;
|
---|
42 | },
|
---|
43 | set: function (replacement) {
|
---|
44 | anObject(this);
|
---|
45 | if (this === IteratorPrototype) throw new $TypeError("You can't redefine this property");
|
---|
46 | if (hasOwn(this, key)) this[key] = replacement;
|
---|
47 | else createProperty(this, key, replacement);
|
---|
48 | }
|
---|
49 | });
|
---|
50 | } else IteratorPrototype[key] = value;
|
---|
51 | };
|
---|
52 |
|
---|
53 | if (!hasOwn(IteratorPrototype, TO_STRING_TAG)) defineIteratorPrototypeAccessor(TO_STRING_TAG, ITERATOR);
|
---|
54 |
|
---|
55 | if (FORCED || !hasOwn(IteratorPrototype, CONSTRUCTOR) || IteratorPrototype[CONSTRUCTOR] === Object) {
|
---|
56 | defineIteratorPrototypeAccessor(CONSTRUCTOR, IteratorConstructor);
|
---|
57 | }
|
---|
58 |
|
---|
59 | IteratorConstructor.prototype = IteratorPrototype;
|
---|
60 |
|
---|
61 | // `Iterator` constructor
|
---|
62 | // https://tc39.es/ecma262/#sec-iterator
|
---|
63 | $({ global: true, constructor: true, forced: FORCED }, {
|
---|
64 | Iterator: IteratorConstructor
|
---|
65 | });
|
---|