web.dom-collections.iterator.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var global = require('../internals/global');
  2. var DOMIterables = require('../internals/dom-iterables');
  3. var DOMTokenListPrototype = require('../internals/dom-token-list-prototype');
  4. var ArrayIteratorMethods = require('../modules/es.array.iterator');
  5. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  6. var wellKnownSymbol = require('../internals/well-known-symbol');
  7. var ITERATOR = wellKnownSymbol('iterator');
  8. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  9. var ArrayValues = ArrayIteratorMethods.values;
  10. var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
  11. if (CollectionPrototype) {
  12. // some Chrome versions have non-configurable methods on DOMTokenList
  13. if (CollectionPrototype[ITERATOR] !== ArrayValues) try {
  14. createNonEnumerableProperty(CollectionPrototype, ITERATOR, ArrayValues);
  15. } catch (error) {
  16. CollectionPrototype[ITERATOR] = ArrayValues;
  17. }
  18. if (!CollectionPrototype[TO_STRING_TAG]) {
  19. createNonEnumerableProperty(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME);
  20. }
  21. if (DOMIterables[COLLECTION_NAME]) for (var METHOD_NAME in ArrayIteratorMethods) {
  22. // some Chrome versions have non-configurable methods on DOMTokenList
  23. if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) try {
  24. createNonEnumerableProperty(CollectionPrototype, METHOD_NAME, ArrayIteratorMethods[METHOD_NAME]);
  25. } catch (error) {
  26. CollectionPrototype[METHOD_NAME] = ArrayIteratorMethods[METHOD_NAME];
  27. }
  28. }
  29. }
  30. };
  31. for (var COLLECTION_NAME in DOMIterables) {
  32. handlePrototype(global[COLLECTION_NAME] && global[COLLECTION_NAME].prototype, COLLECTION_NAME);
  33. }
  34. handlePrototype(DOMTokenListPrototype, 'DOMTokenList');