Skip to content

Commit

Permalink
Ensure that Set#keys is the same object as Set#values.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 20, 2014
1 parent 151113e commit c955ed7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 4 additions & 5 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1943,11 +1943,6 @@
return this['[[SetData]]'].clear();
},

keys: function () {
ensureMap(this);
return this['[[SetData]]'].keys();
},

values: function () {
ensureMap(this);
return this['[[SetData]]'].values();
Expand All @@ -1967,6 +1962,7 @@
});
}
});
defineProperty(SetShim, 'keys', SetShim.values, true);
addIterator(SetShim.prototype, function () { return this.values(); });

return SetShim;
Expand Down Expand Up @@ -2004,6 +2000,9 @@
globals.Set = collectionShims.Set;
}
}
if (globals.Set.prototype.keys !== globals.Set.prototype.values) {
defineProperty(globals.Set.prototype, 'keys', globals.Set.prototype.values, true);
}
// Shim incomplete iterator implementations.
addIterator(Object.getPrototypeOf((new globals.Map()).keys()));
addIterator(Object.getPrototypeOf((new globals.Set()).keys()));
Expand Down
6 changes: 5 additions & 1 deletion test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,14 @@ describe('Collections', function () {
expect(typeof Set).to.equal('function');
});

it('should have the right arity', function () {
it('has the right arity', function () {
expect(Set.length).to.equal(1);
});

it('has #keys which is the same object as #values', function () {
expect(Set.prototype.keys).to.equal(Set.prototype.values);
});

it('returns the set from #add() for chaining', function () {
expect(set.add({})).to.equal(set);
});
Expand Down

0 comments on commit c955ed7

Please sign in to comment.