Skip to content

Commit

Permalink
Set#delete and Map#delete should return false unless a deletion occur…
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 28, 2014
1 parent d8ce5ce commit b3dbd35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,8 @@
'delete': function (key) {
var fkey;
if (this._storage && (fkey = fastkey(key)) !== null) {
return delete this._storage[fkey];
var hasFKey = _hasOwnProperty.call(this._storage, fkey);
return (delete this._storage[fkey]) && hasFKey;
}
ensureMap(this);
return this['[[SetData]]']['delete'](key);
Expand Down
11 changes: 11 additions & 0 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ describe('Collections', function () {
expect(function () { return Map.prototype.size; }).to['throw'](TypeError);
});

it('should return false when deleting a nonexistent key', function () {
expect(map.has('a')).to.equal(false);
expect(map.delete('a')).to.equal(false);
});

it('should have keys, values and size props', function () {
map.set('a', 1);
map.set('b', 2);
Expand Down Expand Up @@ -431,6 +436,7 @@ describe('Collections', function () {
set = new Set();
testSet = function (key) {
expect(set.has(key)).to.equal(false);
expect(set['delete'](key)).to.equal(false);
set.add(key);
expect(set.has(key)).to.equal(true);
expect(set['delete'](key)).to.equal(true);
Expand Down Expand Up @@ -459,6 +465,11 @@ describe('Collections', function () {
expect(set.add({})).to.equal(set);
});

it('should return false when deleting an item not in the set', function () {
expect(set.has('a')).to.equal(false);
expect(set.delete('a')).to.equal(false);
});

it('should accept an iterable as argument', function () {
testSet('a');
testSet('b');
Expand Down

0 comments on commit b3dbd35

Please sign in to comment.