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.
1 /* test Set.prototype.forEach */
3 load(libdir + 'asserts.js');
4 load(libdir + 'iteration.js');
6 // testing success conditions of Set.prototype.forEach
8 var testSet = new Set();
10 function callback(value, key, set) {
11 assertEq(value, key);
12 testSet.add(value);
13 assertEq(set.has(key), true);
14 }
16 var initialSet = new Set(['a', 1, undefined]);
17 initialSet.forEach(callback);
19 // test that both the Sets are equal and are in same order
20 var iterator = initialSet[std_iterator]();
21 var count = 0;
22 for (var v of testSet) {
23 assertEq(initialSet.has(v), true);
24 assertIteratorNext(iterator, v);
25 count++;
26 }
28 //check both the Sets we have are equal in size
29 assertEq(initialSet.size, testSet.size);
30 assertEq(initialSet.size, count);
32 var x = { abc: 'test'};
33 function callback2(value, key, set) {
34 assertEq(x, this);
35 }
36 initialSet = new Set(['a']);
37 initialSet.forEach(callback2, x);
39 // testing failure conditions of Set.prototype.forEach
41 var m = new Map([['a', 1], ['b', 2.3], ['c', undefined]]);
42 assertThrowsInstanceOf(function() {
43 Set.prototype.forEach.call(m, callback);
44 }, TypeError, "Set.prototype.forEach should raise TypeError if not a used on a Set");
46 var fn = 2;
47 assertThrowsInstanceOf(function() {
48 initialSet.forEach(fn);
49 }, TypeError, "Set.prototype.forEach should raise TypeError if callback is not a function");