| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 assertThrows(function () { m.set(0, 0) }, TypeError); | 58 assertThrows(function () { m.set(0, 0) }, TypeError); |
| 59 assertThrows(function () { m.get('a-key') }, TypeError); | 59 assertThrows(function () { m.get('a-key') }, TypeError); |
| 60 assertThrows(function () { m.set('a-key', 0) }, TypeError); | 60 assertThrows(function () { m.set('a-key', 0) }, TypeError); |
| 61 } | 61 } |
| 62 TestInvalidCalls(new WeakMap); | 62 TestInvalidCalls(new WeakMap); |
| 63 | 63 |
| 64 | 64 |
| 65 // Test expected behavior for Sets | 65 // Test expected behavior for Sets |
| 66 function TestSet(set, key) { | 66 function TestSet(set, key) { |
| 67 assertFalse(set.has(key)); | 67 assertFalse(set.has(key)); |
| 68 set.add(key); | 68 assertSame(undefined, set.add(key)); |
| 69 assertTrue(set.has(key)); | 69 assertTrue(set.has(key)); |
| 70 set.delete(key); | 70 assertTrue(set.delete(key)); |
| 71 assertFalse(set.has(key)); |
| 72 assertFalse(set.delete(key)); |
| 71 assertFalse(set.has(key)); | 73 assertFalse(set.has(key)); |
| 72 } | 74 } |
| 73 function TestSetBehavior(set) { | 75 function TestSetBehavior(set) { |
| 74 for (var i = 0; i < 20; i++) { | 76 for (var i = 0; i < 20; i++) { |
| 75 TestSet(set, new Object); | 77 TestSet(set, new Object); |
| 76 TestSet(set, i); | 78 TestSet(set, i); |
| 77 TestSet(set, i / 100); | 79 TestSet(set, i / 100); |
| 78 TestSet(set, 'key-' + i); | 80 TestSet(set, 'key-' + i); |
| 79 } | 81 } |
| 80 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; | 82 var keys = [ +0, -0, +Infinity, -Infinity, true, false, null, undefined ]; |
| 81 for (var i = 0; i < keys.length; i++) { | 83 for (var i = 0; i < keys.length; i++) { |
| 82 TestSet(set, keys[i]); | 84 TestSet(set, keys[i]); |
| 83 } | 85 } |
| 84 } | 86 } |
| 85 TestSetBehavior(new Set); | 87 TestSetBehavior(new Set); |
| 86 | 88 |
| 87 | 89 |
| 88 // Test expected mapping behavior for Maps and WeakMaps | 90 // Test expected mapping behavior for Maps and WeakMaps |
| 89 function TestMapping(map, key, value) { | 91 function TestMapping(map, key, value) { |
| 90 map.set(key, value); | 92 assertSame(undefined, map.set(key, value)); |
| 91 assertSame(value, map.get(key)); | 93 assertSame(value, map.get(key)); |
| 92 } | 94 } |
| 93 function TestMapBehavior1(m) { | 95 function TestMapBehavior1(m) { |
| 94 TestMapping(m, new Object, 23); | 96 TestMapping(m, new Object, 23); |
| 95 TestMapping(m, new Object, 'the-value'); | 97 TestMapping(m, new Object, 'the-value'); |
| 96 TestMapping(m, new Object, new Object); | 98 TestMapping(m, new Object, new Object); |
| 97 } | 99 } |
| 98 TestMapBehavior1(new Map); | 100 TestMapBehavior1(new Map); |
| 99 TestMapBehavior1(new WeakMap); | 101 TestMapBehavior1(new WeakMap); |
| 100 | 102 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 307 } |
| 306 } | 308 } |
| 307 } | 309 } |
| 308 TestBogusReceivers(bogusReceiversTestSet); | 310 TestBogusReceivers(bogusReceiversTestSet); |
| 309 | 311 |
| 310 | 312 |
| 311 // Stress Test | 313 // Stress Test |
| 312 // There is a proposed stress-test available at the es-discuss mailing list | 314 // There is a proposed stress-test available at the es-discuss mailing list |
| 313 // which cannot be reasonably automated. Check it out by hand if you like: | 315 // which cannot be reasonably automated. Check it out by hand if you like: |
| 314 // https://mail.mozilla.org/pipermail/es-discuss/2011-May/014096.html | 316 // https://mail.mozilla.org/pipermail/es-discuss/2011-May/014096.html |
| OLD | NEW |