web.dom.iterable.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var $iterators = require('./es6.array.iterator');
  2. var getKeys = require('./_object-keys');
  3. var redefine = require('./_redefine');
  4. var global = require('./_global');
  5. var hide = require('./_hide');
  6. var Iterators = require('./_iterators');
  7. var wks = require('./_wks');
  8. var ITERATOR = wks('iterator');
  9. var TO_STRING_TAG = wks('toStringTag');
  10. var ArrayValues = Iterators.Array;
  11. var DOMIterables = {
  12. CSSRuleList: true, // TODO: Not spec compliant, should be false.
  13. CSSStyleDeclaration: false,
  14. CSSValueList: false,
  15. ClientRectList: false,
  16. DOMRectList: false,
  17. DOMStringList: false,
  18. DOMTokenList: true,
  19. DataTransferItemList: false,
  20. FileList: false,
  21. HTMLAllCollection: false,
  22. HTMLCollection: false,
  23. HTMLFormElement: false,
  24. HTMLSelectElement: false,
  25. MediaList: true, // TODO: Not spec compliant, should be false.
  26. MimeTypeArray: false,
  27. NamedNodeMap: false,
  28. NodeList: true,
  29. PaintRequestList: false,
  30. Plugin: false,
  31. PluginArray: false,
  32. SVGLengthList: false,
  33. SVGNumberList: false,
  34. SVGPathSegList: false,
  35. SVGPointList: false,
  36. SVGStringList: false,
  37. SVGTransformList: false,
  38. SourceBufferList: false,
  39. StyleSheetList: true, // TODO: Not spec compliant, should be false.
  40. TextTrackCueList: false,
  41. TextTrackList: false,
  42. TouchList: false
  43. };
  44. for (var collections = getKeys(DOMIterables), i = 0; i < collections.length; i++) {
  45. var NAME = collections[i];
  46. var explicit = DOMIterables[NAME];
  47. var Collection = global[NAME];
  48. var proto = Collection && Collection.prototype;
  49. var key;
  50. if (proto) {
  51. if (!proto[ITERATOR]) hide(proto, ITERATOR, ArrayValues);
  52. if (!proto[TO_STRING_TAG]) hide(proto, TO_STRING_TAG, NAME);
  53. Iterators[NAME] = ArrayValues;
  54. if (explicit) for (key in $iterators) if (!proto[key]) redefine(proto, key, $iterators[key], true);
  55. }
  56. }