Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 assertDoesNotThrow(function () { m.delete(new Object) }); | 45 assertDoesNotThrow(function () { m.delete(new Object) }); |
| 46 } | 46 } |
| 47 TestValidMapCalls(new Map); | 47 TestValidMapCalls(new Map); |
| 48 TestValidMapCalls(new WeakMap); | 48 TestValidMapCalls(new WeakMap); |
| 49 | 49 |
| 50 | 50 |
| 51 // Test invalid getter and setter calls for WeakMap only | 51 // Test invalid getter and setter calls for WeakMap only |
| 52 function TestInvalidCalls(m) { | 52 function TestInvalidCalls(m) { |
| 53 assertThrows(function () { m.get(undefined) }, TypeError); | 53 assertThrows(function () { m.get(undefined) }, TypeError); |
| 54 assertThrows(function () { m.set(undefined, 0) }, TypeError); | 54 assertThrows(function () { m.set(undefined, 0) }, TypeError); |
| 55 assertThrows(function () { m.get(null) }, TypeError); | |
| 56 assertThrows(function () { m.set(null, 0) }, TypeError); | |
| 55 assertThrows(function () { m.get(0) }, TypeError); | 57 assertThrows(function () { m.get(0) }, TypeError); |
| 56 assertThrows(function () { m.set(0, 0) }, TypeError); | 58 assertThrows(function () { m.set(0, 0) }, TypeError); |
| 57 assertThrows(function () { m.get('a-key') }, TypeError); | 59 assertThrows(function () { m.get('a-key') }, TypeError); |
| 58 assertThrows(function () { m.set('a-key', 0) }, TypeError); | 60 assertThrows(function () { m.set('a-key', 0) }, TypeError); |
| 59 } | 61 } |
| 60 TestInvalidCalls(new WeakMap); | 62 TestInvalidCalls(new WeakMap); |
| 61 | 63 |
| 62 | 64 |
| 63 // Test expected behavior for Sets | 65 // Test expected behavior for Sets |
| 64 function TestSet(set, key) { | 66 function TestSet(set, key) { |
| 65 assertFalse(set.has(key)); | 67 assertFalse(set.has(key)); |
| 66 set.add(key); | 68 set.add(key); |
| 67 assertTrue(set.has(key)); | 69 assertTrue(set.has(key)); |
| 68 set.delete(key); | 70 set.delete(key); |
| 69 assertFalse(set.has(key)); | 71 assertFalse(set.has(key)); |
| 70 } | 72 } |
| 71 function TestSetBehavior(set) { | 73 function TestSetBehavior(set) { |
| 72 for (i = 0; i < 20; i++) { | 74 for (var i = 0; i < 20; i++) { |
|
rossberg
2011/11/02 15:17:37
Ts-ts-ts.
| |
| 73 TestSet(set, new Object); | 75 TestSet(set, new Object); |
| 74 } | 76 } |
| 75 } | 77 } |
| 76 TestSet(new Set, 23); | 78 TestSet(new Set, 23); |
| 77 TestSet(new Set, 'foo'); | 79 TestSet(new Set, 'foo'); |
| 78 TestSetBehavior(new Set); | 80 TestSetBehavior(new Set); |
| 79 | 81 |
| 80 | 82 |
| 81 // Test expected mapping behavior for Maps and WeakMaps | 83 // Test expected mapping behavior for Maps and WeakMaps |
| 82 function TestMapping(map, key, value) { | 84 function TestMapping(map, key, value) { |
| 83 map.set(key, value); | 85 map.set(key, value); |
| 84 assertSame(value, map.get(key)); | 86 assertSame(value, map.get(key)); |
| 85 } | 87 } |
| 86 function TestMapBehavior1(m) { | 88 function TestMapBehavior1(m) { |
| 87 TestMapping(m, new Object, 23); | 89 TestMapping(m, new Object, 23); |
| 88 TestMapping(m, new Object, 'the-value'); | 90 TestMapping(m, new Object, 'the-value'); |
| 89 TestMapping(m, new Object, new Object); | 91 TestMapping(m, new Object, new Object); |
| 90 } | 92 } |
| 91 TestMapBehavior1(new Map); | 93 TestMapBehavior1(new Map); |
| 92 TestMapBehavior1(new WeakMap); | 94 TestMapBehavior1(new WeakMap); |
| 93 | 95 |
| 94 | 96 |
| 95 // Test expected mapping behavior for Maps only | 97 // Test expected mapping behavior for Maps only |
| 96 function TestMapBehavior2(m) { | 98 function TestMapBehavior2(m) { |
| 97 for (var i = 0; i < 20; i++) { | 99 for (var i = 0; i < 20; i++) { |
| 98 TestMapping(m, i, new Object); | 100 TestMapping(m, i, new Object); |
| 99 TestMapping(m, i / 10, new Object); | 101 TestMapping(m, i / 10, new Object); |
| 100 TestMapping(m, 'key-' + i, new Object); | 102 TestMapping(m, 'key-' + i, new Object); |
| 101 } | 103 } |
| 102 var keys = [ +0, -0, +Infinity, -Infinity, true, false ]; | 104 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null ]; |
| 103 for (var i = 0; i < keys.length; i++) { | 105 for (var i = 0; i < keys.length; i++) { |
| 104 TestMapping(m, keys[i], new Object); | 106 TestMapping(m, keys[i], new Object); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 TestMapBehavior2(new Map); | 109 TestMapBehavior2(new Map); |
| 108 | 110 |
| 109 | 111 |
| 110 // Test expected querying behavior of Maps and WeakMaps | 112 // Test expected querying behavior of Maps and WeakMaps |
| 111 function TestQuery(m) { | 113 function TestQuery(m) { |
| 112 var key = new Object; | 114 var key = new Object; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 TestEnumerable(Map); | 179 TestEnumerable(Map); |
| 178 TestEnumerable(WeakMap); | 180 TestEnumerable(WeakMap); |
| 179 | 181 |
| 180 | 182 |
| 181 // Test arbitrary properties on Maps and WeakMaps | 183 // Test arbitrary properties on Maps and WeakMaps |
| 182 function TestArbitrary(m) { | 184 function TestArbitrary(m) { |
| 183 function TestProperty(map, property, value) { | 185 function TestProperty(map, property, value) { |
| 184 map[property] = value; | 186 map[property] = value; |
| 185 assertEquals(value, map[property]); | 187 assertEquals(value, map[property]); |
| 186 } | 188 } |
| 187 for (i = 0; i < 20; i++) { | 189 for (var i = 0; i < 20; i++) { |
| 188 TestProperty(m, i, 'val' + i); | 190 TestProperty(m, i, 'val' + i); |
| 189 TestProperty(m, 'foo' + i, 'bar' + i); | 191 TestProperty(m, 'foo' + i, 'bar' + i); |
| 190 } | 192 } |
| 191 TestMapping(m, new Object, 'foobar'); | 193 TestMapping(m, new Object, 'foobar'); |
| 192 } | 194 } |
| 193 TestArbitrary(new Map); | 195 TestArbitrary(new Map); |
| 194 TestArbitrary(new WeakMap); | 196 TestArbitrary(new WeakMap); |
| 195 | 197 |
| 196 | 198 |
| 197 // Test direct constructor call | 199 // Test direct constructor call |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 configurable: true, | 266 configurable: true, |
| 265 writable: true | 267 writable: true |
| 266 }}); | 268 }}); |
| 267 assertEquals(10, o.myValue); | 269 assertEquals(10, o.myValue); |
| 268 | 270 |
| 269 | 271 |
| 270 // Stress Test | 272 // Stress Test |
| 271 // There is a proposed stress-test available at the es-discuss mailing list | 273 // There is a proposed stress-test available at the es-discuss mailing list |
| 272 // which cannot be reasonably automated. Check it out by hand if you like: | 274 // which cannot be reasonably automated. Check it out by hand if you like: |
| 273 // https://mail.mozilla.org/pipermail/es-discuss/2011-May/014096.html | 275 // https://mail.mozilla.org/pipermail/es-discuss/2011-May/014096.html |
| OLD | NEW |