Skip to content

Commit

Permalink
Improve legacy iterators checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mhassan1 committed Jul 12, 2024
1 parent 657b8e6 commit 1b75629
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion polyfills/Array/prototype/values/detect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'Symbol' in self && 'iterator' in self.Symbol && !!Array.prototype.values && !![].values()[self.Symbol.iterator] && (function () {
// firefox 44 and below uses legacy iterators
// https://github.com/zloirock/core-js/commit/bb3b34bbf92b1d1a7b50d3a5a445c84dc2fb5cd5#diff-25d2a16dc5a355ce40a572773be144d1c8e085a809633e42ec$
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][self.Symbol.iterator]()));
var IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([].values()[self.Symbol.iterator]()));
var test = {};
return IteratorPrototype[self.Symbol.iterator].call(test) === test;
})()
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 1b75629

Please sign in to comment.