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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 assertThrows(function () { m.set(0, 0) }, TypeError); | 61 assertThrows(function () { m.set(0, 0) }, TypeError); |
62 assertThrows(function () { m.get('a-key') }, TypeError); | 62 assertThrows(function () { m.get('a-key') }, TypeError); |
63 assertThrows(function () { m.set('a-key', 0) }, TypeError); | 63 assertThrows(function () { m.set('a-key', 0) }, TypeError); |
64 } | 64 } |
65 TestInvalidCalls(new WeakMap); | 65 TestInvalidCalls(new WeakMap); |
66 | 66 |
67 | 67 |
68 // Test expected behavior for WeakSets | 68 // Test expected behavior for WeakSets |
69 function TestSet(set, key) { | 69 function TestSet(set, key) { |
70 assertFalse(set.has(key)); | 70 assertFalse(set.has(key)); |
71 assertSame(undefined, set.add(key)); | 71 assertSame(set, set.add(key)); |
72 assertTrue(set.has(key)); | 72 assertTrue(set.has(key)); |
73 assertTrue(set.delete(key)); | 73 assertTrue(set.delete(key)); |
74 assertFalse(set.has(key)); | 74 assertFalse(set.has(key)); |
75 assertFalse(set.delete(key)); | 75 assertFalse(set.delete(key)); |
76 assertFalse(set.has(key)); | 76 assertFalse(set.has(key)); |
77 } | 77 } |
78 function TestSetBehavior(set) { | 78 function TestSetBehavior(set) { |
79 for (var i = 0; i < 20; i++) { | 79 for (var i = 0; i < 20; i++) { |
80 TestSet(set, new Object); | 80 TestSet(set, new Object); |
81 TestSet(set, i); | 81 TestSet(set, i); |
82 TestSet(set, i / 100); | 82 TestSet(set, i / 100); |
83 TestSet(set, 'key-' + i); | 83 TestSet(set, 'key-' + i); |
84 } | 84 } |
85 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; | 85 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; |
86 for (var i = 0; i < keys.length; i++) { | 86 for (var i = 0; i < keys.length; i++) { |
87 TestSet(set, keys[i]); | 87 TestSet(set, keys[i]); |
88 } | 88 } |
89 } | 89 } |
90 TestSet(new WeakSet, new Object); | 90 TestSet(new WeakSet, new Object); |
91 | 91 |
92 | 92 |
93 // Test expected mapping behavior for WeakMaps | 93 // Test expected mapping behavior for 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 WeakMap); | 103 TestMapBehavior1(new WeakMap); |
104 | 104 |
105 | 105 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 // Test WeakSet clear | 325 // Test WeakSet clear |
326 (function() { | 326 (function() { |
327 var k = new Object(); | 327 var k = new Object(); |
328 var w = new WeakSet(); | 328 var w = new WeakSet(); |
329 w.add(k); | 329 w.add(k); |
330 assertTrue(w.has(k)); | 330 assertTrue(w.has(k)); |
331 w.clear(); | 331 w.clear(); |
332 assertFalse(w.has(k)); | 332 assertFalse(w.has(k)); |
333 })(); | 333 })(); |
OLD | NEW |