OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 assertThrows(function () { m.set(0, 0) }, TypeError); | 60 assertThrows(function () { m.set(0, 0) }, TypeError); |
61 assertThrows(function () { m.get('a-key') }, TypeError); | 61 assertThrows(function () { m.get('a-key') }, TypeError); |
62 assertThrows(function () { m.set('a-key', 0) }, TypeError); | 62 assertThrows(function () { m.set('a-key', 0) }, TypeError); |
63 } | 63 } |
64 TestInvalidCalls(new WeakMap); | 64 TestInvalidCalls(new WeakMap); |
65 | 65 |
66 | 66 |
67 // Test expected behavior for Sets and WeakSets | 67 // Test expected behavior for Sets and WeakSets |
68 function TestSet(set, key) { | 68 function TestSet(set, key) { |
69 assertFalse(set.has(key)); | 69 assertFalse(set.has(key)); |
70 assertSame(undefined, set.add(key)); | 70 assertSame(set, set.add(key)); |
71 assertTrue(set.has(key)); | 71 assertTrue(set.has(key)); |
72 assertTrue(set.delete(key)); | 72 assertTrue(set.delete(key)); |
73 assertFalse(set.has(key)); | 73 assertFalse(set.has(key)); |
74 assertFalse(set.delete(key)); | 74 assertFalse(set.delete(key)); |
75 assertFalse(set.has(key)); | 75 assertFalse(set.has(key)); |
76 } | 76 } |
77 function TestSetBehavior(set) { | 77 function TestSetBehavior(set) { |
78 for (var i = 0; i < 20; i++) { | 78 for (var i = 0; i < 20; i++) { |
79 TestSet(set, new Object); | 79 TestSet(set, new Object); |
80 TestSet(set, i); | 80 TestSet(set, i); |
81 TestSet(set, i / 100); | 81 TestSet(set, i / 100); |
82 TestSet(set, 'key-' + i); | 82 TestSet(set, 'key-' + i); |
83 } | 83 } |
84 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; | 84 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; |
85 for (var i = 0; i < keys.length; i++) { | 85 for (var i = 0; i < keys.length; i++) { |
86 TestSet(set, keys[i]); | 86 TestSet(set, keys[i]); |
87 } | 87 } |
88 } | 88 } |
89 TestSetBehavior(new Set); | 89 TestSetBehavior(new Set); |
90 TestSet(new WeakSet, new Object); | 90 TestSet(new WeakSet, new Object); |
91 | 91 |
92 | 92 |
93 // Test expected mapping behavior for Maps and WeakMaps | 93 // Test expected mapping behavior for Maps and WeakMaps |
94 function TestMapping(map, key, value) { | 94 function TestMapping(map, key, value) { |
95 assertSame(undefined, map.set(key, value)); | 95 assertSame(map, map.set(key, value)); |
96 assertSame(value, map.get(key)); | 96 assertSame(value, map.get(key)); |
97 } | 97 } |
98 function TestMapBehavior1(m) { | 98 function TestMapBehavior1(m) { |
99 TestMapping(m, new Object, 23); | 99 TestMapping(m, new Object, 23); |
100 TestMapping(m, new Object, 'the-value'); | 100 TestMapping(m, new Object, 'the-value'); |
101 TestMapping(m, new Object, new Object); | 101 TestMapping(m, new Object, new Object); |
102 } | 102 } |
103 TestMapBehavior1(new Map); | 103 TestMapBehavior1(new Map); |
104 TestMapBehavior1(new WeakMap); | 104 TestMapBehavior1(new WeakMap); |
105 | 105 |
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 new Map(iterator); | 1238 new Map(iterator); |
1239 }, TypeError); | 1239 }, TypeError); |
1240 })(); | 1240 })(); |
1241 | 1241 |
1242 | 1242 |
1243 (function TestMapConstructorIteratorNotObjectValues() { | 1243 (function TestMapConstructorIteratorNotObjectValues() { |
1244 assertThrows(function() { | 1244 assertThrows(function() { |
1245 new Map([1, 2].values()); | 1245 new Map([1, 2].values()); |
1246 }, TypeError); | 1246 }, TypeError); |
1247 })(); | 1247 })(); |
OLD | NEW |