Skip to content

Commit

Permalink
add HTMLCollection#@@iterator for some browsers, #37, #68
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 21, 2015
1 parent cfe654a commit 558a0b9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
12 changes: 8 additions & 4 deletions library/modules/web.dom.iterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ var $ = require('./$')
, Iterators = require('./$.iter').Iterators
, ITERATOR = require('./$.wks')('iterator')
, ArrayValues = Iterators.Array
, NodeList = $.g.NodeList;
if($.FW && NodeList && !(ITERATOR in NodeList.prototype)){
$.hide(NodeList.prototype, ITERATOR, ArrayValues);
, NL = $.g.NodeList
, HTC = $.g.HTMLCollection
, NLProto = NL && NL.prototype
, HTCProto = HTC && HTC.prototype;
if($.FW){
if(NL && !(ITERATOR in NLProto))$.hide(NLProto, ITERATOR, ArrayValues);
if(HTC && !(ITERATOR in HTCProto))$.hide(HTCProto, ITERATOR, ArrayValues);
}
Iterators.NodeList = ArrayValues;
Iterators.NodeList = Iterators.HTMLCollection = ArrayValues;
12 changes: 8 additions & 4 deletions modules/web.dom.iterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ var $ = require('./$')
, Iterators = require('./$.iter').Iterators
, ITERATOR = require('./$.wks')('iterator')
, ArrayValues = Iterators.Array
, NodeList = $.g.NodeList;
if($.FW && NodeList && !(ITERATOR in NodeList.prototype)){
$.hide(NodeList.prototype, ITERATOR, ArrayValues);
, NL = $.g.NodeList
, HTC = $.g.HTMLCollection
, NLProto = NL && NL.prototype
, HTCProto = HTC && HTC.prototype;
if($.FW){
if(NL && !(ITERATOR in NLProto))$.hide(NLProto, ITERATOR, ArrayValues);
if(HTC && !(ITERATOR in HTCProto))$.hide(HTCProto, ITERATOR, ArrayValues);
}
Iterators.NodeList = ArrayValues;
Iterators.NodeList = Iterators.HTMLCollection = ArrayValues;
19 changes: 19 additions & 0 deletions tests/tests-library.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/tests-library/web.dom.itarable.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
QUnit.module 'DOM iterable'

isFunction = -> typeof! it is \Function

if NodeList? and document?querySelectorAll and typeof! document.querySelectorAll(\div) is \NodeList
test 'NodeList.prototype@@iterator' !->
ok core.isIterable(document.querySelectorAll(\div)), 'Is iterable'

if HTMLCollection? and document?getElementsByTagName and typeof! document.getElementsByTagName(\div) is \HTMLCollection
test 'HTMLCollection.prototype@@iterator' !->
ok core.isIterable(document.getElementsByTagName(\div)), 'Is iterable' # Buggy in some Chromium versions
9 changes: 7 additions & 2 deletions tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions tests/tests/web.dom.itarable.ls
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ QUnit.module 'DOM iterable'

isFunction = -> typeof! it is \Function

if NodeList? => test 'NodeList.prototype@@iterator' !->
ok isFunction(NodeList.prototype[Symbol.iterator]), 'Is function'
if NodeList? and document?querySelectorAll and document.querySelectorAll(\div) instanceof NodeList
test 'NodeList.prototype@@iterator' !->
ok isFunction(document.querySelectorAll(\div)[Symbol.iterator]), 'Is function'

if HTMLCollection? and document?getElementsByTagName and document.getElementsByTagName(\div) instanceof HTMLCollection
test 'HTMLCollection.prototype@@iterator' !->
ok isFunction(document.getElementsByTagName(\div)[Symbol.iterator]), 'Is function' # Buggy in some Chromium versions

0 comments on commit 558a0b9

Please # to comment.