Skip to content

Commit

Permalink
Distinguish Set and Map iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
cscott committed Dec 16, 2015
1 parent 8dc13d7 commit a81693f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -2731,7 +2731,11 @@
};

MapIterator.prototype = {
isMapIterator: true,
next: function next() {
if (!this.isMapIterator) {
throw new TypeError('Not a MapIterator');
}
var i = this.i, kind = this.kind, head = this.head, result;
if (typeof this.i === 'undefined') {
return { value: void 0, done: true };
Expand Down Expand Up @@ -3058,13 +3062,13 @@
values: function values() {
requireSetSlot(this, 'values');
ensureMap(this);
return this['[[SetData]]'].values();
return new SetIterator(this['[[SetData]]'].values());
},

entries: function entries() {
requireSetSlot(this, 'entries');
ensureMap(this);
return this['[[SetData]]'].entries();
return new SetIterator(this['[[SetData]]'].entries());
},

forEach: function forEach(callback) {
Expand All @@ -3084,6 +3088,20 @@
defineProperty(SetShim.prototype, 'keys', SetShim.prototype.values, true);
addIterator(SetShim.prototype, SetShim.prototype.values);

var SetIterator = function (it) {
this.it = it;
};
SetIterator.prototype = {
isSetIterator: true,
next: function next() {
if (!this.isSetIterator) {
throw new TypeError('Not a SetIterator');
}
return this.it.next();
}
};
addIterator(SetIterator.prototype);

return SetShim;
}())
};
Expand Down

0 comments on commit a81693f

Please sign in to comment.