Skip to content

Commit

Permalink
fix an issue with non-configurable Chrome~42 DOMTokenList methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 20, 2018
1 parent 7c8b5cb commit b5069b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/core-js/modules/web.dom-collections.for-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ var global = require('../internals/global');
for (var COLLECTION_NAME in DOMIterables) {
var Collection = global[COLLECTION_NAME];
var CollectionPrototype = Collection && Collection.prototype;
if (CollectionPrototype && CollectionPrototype.forEach !== forEach) {
// some Chrome versions have non-configurable methods on DOMTokenList
if (CollectionPrototype && CollectionPrototype.forEach !== forEach) try {
hide(CollectionPrototype, 'forEach', forEach);
} catch (e) {
CollectionPrototype.forEach = forEach;
}
}
13 changes: 9 additions & 4 deletions packages/core-js/modules/web.dom-collections.iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ for (var COLLECTION_NAME in DOMIterables) {
var Collection = global[COLLECTION_NAME];
var CollectionPrototype = Collection && Collection.prototype;
if (CollectionPrototype) {
// some Chrome versions die on an attempt to redefine iterator, for example, on DOMTokenList
// some Chrome versions have non-configurable methods on DOMTokenList
if (CollectionPrototype[ITERATOR] !== ArrayValues) try {
hide(CollectionPrototype, ITERATOR, ArrayValues);
} catch (e) { /* empty */ }
} catch (e) {
CollectionPrototype[ITERATOR] = ArrayValues;
}
if (!CollectionPrototype[TO_STRING_TAG]) hide(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME);
if (DOMIterables[COLLECTION_NAME]) for (var METHOD_NAME in ArrayIteratorMethods) {
if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) {
hide(CollectionPrototype, METHOD_NAME, ArrayIteratorMethods[METHOD_NAME], true);
// some Chrome versions have non-configurable methods on DOMTokenList
if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) try {
hide(CollectionPrototype, METHOD_NAME, ArrayIteratorMethods[METHOD_NAME]);
} catch (e) {
CollectionPrototype[METHOD_NAME] = ArrayIteratorMethods[METHOD_NAME];
}
}
}
Expand Down

0 comments on commit b5069b1

Please sign in to comment.