Skip to content

Commit

Permalink
Support using arguments as an iterable.
Browse files Browse the repository at this point in the history
We can't add an @@iterator field to the prototype of `arguments`, so we
need to special case it in ES.GetIterator and ES.IsIterable instead.
  • Loading branch information
cscott committed Feb 14, 2014
1 parent 85dc5ed commit 7ea1664
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,15 @@
},

IsIterable: function(o) {
return ES.TypeIsObject(o) && ES.IsCallable(o[$iterator$]);
return ES.TypeIsObject(o) &&
(ES.IsCallable(o[$iterator$]) || isArguments(o));
},

GetIterator: function(o) {
if (isArguments(o)) {
// special case support for `arguments`
return new ArrayIterator(o, "value");
}
var it = o[$iterator$]();
if (!ES.TypeIsObject(it)) {
throw new TypeError('bad iterator');
Expand Down

0 comments on commit 7ea1664

Please sign in to comment.