Skip to content

Commit afe941e

Browse files
committed
fix DOMTokenList.prototype.{ forEach, @@iterator, keys, values, entries } in old WebKit versions where element.classList is not an instance of global DOMTokenList
https://github.com/Financial-Times/polyfill-library/pull/1097
1 parent 8776099 commit afe941e

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Changelog
22
##### Unreleased
33
- Fixed some possible problems related to possible extension of `%IteratorPrototype%` and `%AsyncIteratorPrototype%` in the future
4+
- Fixed `DOMTokenList.prototype.{ forEach, @@iterator, keys, values, entries }` in old WebKit versions where `element.classList` is not an instance of global `DOMTokenList`
45
- Added NodeJS 16.9 compat data mapping
56
- Added Samsung Internet 16.0 compat data mapping
67

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// in old WebKit versions, `element.classList` is not an instance of global `DOMTokenList`
2+
var documentCreateElement = require('../internals/document-create-element');
3+
4+
var classList = documentCreateElement('span').classList;
5+
var DOMTokenListPrototype = classList && classList.constructor && classList.constructor.prototype;
6+
7+
module.exports = DOMTokenListPrototype === Object.prototype ? undefined : DOMTokenListPrototype;
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
var global = require('../internals/global');
22
var DOMIterables = require('../internals/dom-iterables');
3+
var DOMTokenListPrototype = require('../internals/dom-token-list-prototype');
34
var forEach = require('../internals/array-for-each');
45
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
56

6-
for (var COLLECTION_NAME in DOMIterables) {
7-
var Collection = global[COLLECTION_NAME];
8-
var CollectionPrototype = Collection && Collection.prototype;
7+
var handlePrototype = function (CollectionPrototype) {
98
// some Chrome versions have non-configurable methods on DOMTokenList
109
if (CollectionPrototype && CollectionPrototype.forEach !== forEach) try {
1110
createNonEnumerableProperty(CollectionPrototype, 'forEach', forEach);
1211
} catch (error) {
1312
CollectionPrototype.forEach = forEach;
1413
}
14+
};
15+
16+
for (var COLLECTION_NAME in DOMIterables) {
17+
handlePrototype(global[COLLECTION_NAME] && global[COLLECTION_NAME].prototype);
1518
}
19+
20+
handlePrototype(DOMTokenListPrototype);

packages/core-js/modules/web.dom-collections.iterator.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var global = require('../internals/global');
22
var DOMIterables = require('../internals/dom-iterables');
3+
var DOMTokenListPrototype = require('../internals/dom-token-list-prototype');
34
var ArrayIteratorMethods = require('../modules/es.array.iterator');
45
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
56
var wellKnownSymbol = require('../internals/well-known-symbol');
@@ -8,9 +9,7 @@ var ITERATOR = wellKnownSymbol('iterator');
89
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
910
var ArrayValues = ArrayIteratorMethods.values;
1011

11-
for (var COLLECTION_NAME in DOMIterables) {
12-
var Collection = global[COLLECTION_NAME];
13-
var CollectionPrototype = Collection && Collection.prototype;
12+
var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
1413
if (CollectionPrototype) {
1514
// some Chrome versions have non-configurable methods on DOMTokenList
1615
if (CollectionPrototype[ITERATOR] !== ArrayValues) try {
@@ -30,4 +29,10 @@ for (var COLLECTION_NAME in DOMIterables) {
3029
}
3130
}
3231
}
32+
};
33+
34+
for (var COLLECTION_NAME in DOMIterables) {
35+
handlePrototype(global[COLLECTION_NAME] && global[COLLECTION_NAME].prototype, COLLECTION_NAME);
3336
}
37+
38+
handlePrototype(DOMTokenListPrototype, 'DOMTokenList');

0 commit comments

Comments
 (0)