Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* test Set.prototype.forEach */ |
michael@0 | 2 | |
michael@0 | 3 | load(libdir + 'asserts.js'); |
michael@0 | 4 | load(libdir + 'iteration.js'); |
michael@0 | 5 | |
michael@0 | 6 | // testing success conditions of Set.prototype.forEach |
michael@0 | 7 | |
michael@0 | 8 | var testSet = new Set(); |
michael@0 | 9 | |
michael@0 | 10 | function callback(value, key, set) { |
michael@0 | 11 | assertEq(value, key); |
michael@0 | 12 | testSet.add(value); |
michael@0 | 13 | assertEq(set.has(key), true); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | var initialSet = new Set(['a', 1, undefined]); |
michael@0 | 17 | initialSet.forEach(callback); |
michael@0 | 18 | |
michael@0 | 19 | // test that both the Sets are equal and are in same order |
michael@0 | 20 | var iterator = initialSet[std_iterator](); |
michael@0 | 21 | var count = 0; |
michael@0 | 22 | for (var v of testSet) { |
michael@0 | 23 | assertEq(initialSet.has(v), true); |
michael@0 | 24 | assertIteratorNext(iterator, v); |
michael@0 | 25 | count++; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | //check both the Sets we have are equal in size |
michael@0 | 29 | assertEq(initialSet.size, testSet.size); |
michael@0 | 30 | assertEq(initialSet.size, count); |
michael@0 | 31 | |
michael@0 | 32 | var x = { abc: 'test'}; |
michael@0 | 33 | function callback2(value, key, set) { |
michael@0 | 34 | assertEq(x, this); |
michael@0 | 35 | } |
michael@0 | 36 | initialSet = new Set(['a']); |
michael@0 | 37 | initialSet.forEach(callback2, x); |
michael@0 | 38 | |
michael@0 | 39 | // testing failure conditions of Set.prototype.forEach |
michael@0 | 40 | |
michael@0 | 41 | var m = new Map([['a', 1], ['b', 2.3], ['c', undefined]]); |
michael@0 | 42 | assertThrowsInstanceOf(function() { |
michael@0 | 43 | Set.prototype.forEach.call(m, callback); |
michael@0 | 44 | }, TypeError, "Set.prototype.forEach should raise TypeError if not a used on a Set"); |
michael@0 | 45 | |
michael@0 | 46 | var fn = 2; |
michael@0 | 47 | assertThrowsInstanceOf(function() { |
michael@0 | 48 | initialSet.forEach(fn); |
michael@0 | 49 | }, TypeError, "Set.prototype.forEach should raise TypeError if callback is not a function"); |