debian-mirror-gitlab/core-js/modules/esnext.iterator.constructor.js

49 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-10-31 01:37:42 +05:30
'use strict';
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var global = require('../internals/global');
var anInstance = require('../internals/an-instance');
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
2019-12-04 20:38:33 +05:30
var fails = require('../internals/fails');
2019-10-31 01:37:42 +05:30
var has = require('../internals/has');
var wellKnownSymbol = require('../internals/well-known-symbol');
var IteratorPrototype = require('../internals/iterators-core').IteratorPrototype;
var IS_PURE = require('../internals/is-pure');
var ITERATOR = wellKnownSymbol('iterator');
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
var NativeIterator = global.Iterator;
// FF56- have non-standard global helper `Iterator`
2019-12-04 20:38:33 +05:30
var FORCED = IS_PURE
|| typeof NativeIterator != 'function'
|| NativeIterator.prototype !== IteratorPrototype
// FF44- non-standard `Iterator` passes previous tests
|| !fails(function () { NativeIterator({}); });
2019-10-31 01:37:42 +05:30
var IteratorConstructor = function Iterator() {
anInstance(this, IteratorConstructor);
};
if (IS_PURE) {
IteratorPrototype = {};
createNonEnumerableProperty(IteratorPrototype, ITERATOR, function () {
return this;
});
}
if (!has(IteratorPrototype, TO_STRING_TAG)) {
createNonEnumerableProperty(IteratorPrototype, TO_STRING_TAG, 'Iterator');
}
2019-12-04 20:38:33 +05:30
if (FORCED || !has(IteratorPrototype, 'constructor') || IteratorPrototype.constructor === Object) {
2019-10-31 01:37:42 +05:30
createNonEnumerableProperty(IteratorPrototype, 'constructor', IteratorConstructor);
}
IteratorConstructor.prototype = IteratorPrototype;
$({ global: true, forced: FORCED }, {
Iterator: IteratorConstructor
});