Skip to content

Commit

Permalink
Improve legacy iterators check
Browse files Browse the repository at this point in the history
  • Loading branch information
mhassan1 committed Jul 12, 2024
1 parent 657b8e6 commit 8021f70
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions polyfills/Array/prototype/values/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* global CreateMethodProperty, Symbol, ToObject, ArrayIterator */
// 22.1.3.30/ Array.prototype.values ( )

var hasLegacyIterator = !(function () {
var hasModernIterator = function () {
// firefox 44 and below uses legacy iterators
// https://github.com/zloirock/core-js/commit/bb3b34bbf92b1d1a7b50d3a5a445c84dc2fb5cd5#diff-25d2a16dc5a355ce40a572773be144d1c8e085a809633e42ec$
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()));
var test = {};
return IteratorPrototype[Symbol.iterator].call(test) === test;
})();
}

// Firefox, Chrome and Opera have Array.prototype[Symbol.iterator], which is the exact same function as Array.prototype.values.
if ('Symbol' in self && 'iterator' in Symbol && typeof Array.prototype[Symbol.iterator] === 'function' && !hasLegacyIterator) {
if ('Symbol' in self && 'iterator' in Symbol && typeof Array.prototype[Symbol.iterator] === 'function' && hasModernIterator()) {
CreateMethodProperty(Array.prototype, 'values', Array.prototype[Symbol.iterator]);
} else {
CreateMethodProperty(Array.prototype, 'values', function values () {
Expand Down

0 comments on commit 8021f70

Please sign in to comment.