Skip to content

Commit

Permalink
make {Map, Set}#forEach non-generic, close #144
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 15, 2015
1 parent 575ce3e commit 5d2a566
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions library/modules/_collection-strong.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = {
// 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined)
// 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined)
forEach: function forEach(callbackfn /*, that = undefined */){
anInstance(this, C, 'forEach');
var f = ctx(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3)
, entry;
while(entry = entry ? entry.n : this._f){
Expand Down
1 change: 1 addition & 0 deletions library/modules/_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function(NAME, wrapper, methods, common, IS_MAP, IS_WEAK){
$.each.call('add,clear,delete,forEach,get,has,set,keys,values,entries'.split(','),function(KEY){
var IS_ADDER = KEY == 'add' || KEY == 'set';
if(KEY in proto && !(IS_WEAK && KEY == 'clear'))hide(C.prototype, KEY, function(a, b){
anInstance(this, C, KEY);
if(!IS_ADDER && IS_WEAK && !isObject(a))return KEY == 'get' ? undefined : false;
var result = this._c[KEY](a === 0 ? 0 : a, b);
return IS_ADDER ? this : result;
Expand Down
1 change: 1 addition & 0 deletions modules/_collection-strong.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = {
// 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined)
// 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined)
forEach: function forEach(callbackfn /*, that = undefined */){
anInstance(this, C, 'forEach');
var f = ctx(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3)
, entry;
while(entry = entry ? entry.n : this._f){
Expand Down
1 change: 1 addition & 0 deletions modules/library/_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function(NAME, wrapper, methods, common, IS_MAP, IS_WEAK){
$.each.call('add,clear,delete,forEach,get,has,set,keys,values,entries'.split(','),function(KEY){
var IS_ADDER = KEY == 'add' || KEY == 'set';
if(KEY in proto && !(IS_WEAK && KEY == 'clear'))hide(C.prototype, KEY, function(a, b){
anInstance(this, C, KEY);
if(!IS_ADDER && IS_WEAK && !isObject(a))return KEY == 'get' ? undefined : false;
var result = this._c[KEY](a === 0 ? 0 : a, b);
return IS_ADDER ? this : result;
Expand Down
10 changes: 8 additions & 2 deletions tests/es.js

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

18 changes: 12 additions & 6 deletions tests/library.js

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

3 changes: 2 additions & 1 deletion tests/library/es6.map.ls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module \ES6

same = (a, b)-> if a is b => a isnt 0 or 1 / a is 1 / b else a !~= a and b !~= b
{Map, Symbol} = core
{Map, Set, Symbol} = core
{getOwnPropertyDescriptor, freeze} = core.Object
{iterator} = core.Symbol

Expand Down Expand Up @@ -102,6 +102,7 @@ test 'Map#forEach' (assert)->
if s isnt '' => throw '!!!'
s += it
assert.strictEqual s, \1
assert.throws (!-> Map::forEach.call new Set, !->), 'non-generic'

test 'Map#get' (assert)->
assert.isFunction Map::get
Expand Down
3 changes: 2 additions & 1 deletion tests/library/es6.set.ls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module \ES6

same = (a, b)-> if a is b => a isnt 0 or 1 / a is 1 / b else a !~= a and b !~= b
{Set, Symbol} = core
{Set, Map, Symbol} = core
{getOwnPropertyDescriptor, freeze} = core.Object
{iterator} = core.Symbol

Expand Down Expand Up @@ -131,6 +131,7 @@ test 'Set#forEach' (assert)->
if s isnt '' => throw '!!!'
s += it
assert.strictEqual s, \0
assert.throws (!-> Set::forEach.call new Map, !->), 'non-generic'

test 'Set#has' (assert)->
assert.isFunction Set::has
Expand Down
10 changes: 8 additions & 2 deletions tests/tests.js

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

1 change: 1 addition & 0 deletions tests/tests/es6.map.ls
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ test 'Map#forEach' (assert)->
if s isnt '' => throw '!!!'
s += it
assert.strictEqual s, \1
assert.throws (!-> Map::forEach.call new Set, !->), 'non-generic'

test 'Map#get' (assert)->
assert.isFunction Map::get
Expand Down
1 change: 1 addition & 0 deletions tests/tests/es6.set.ls
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ test 'Set#forEach' (assert)->
if s isnt '' => throw '!!!'
s += it
assert.strictEqual s, \0
assert.throws (!-> Set::forEach.call new Map, !->), 'non-generic'

test 'Set#has' (assert)->
assert.isFunction Set::has
Expand Down

0 comments on commit 5d2a566

Please sign in to comment.