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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 assertFalse(m.hasOwnProperty('size')); | 370 assertFalse(m.hasOwnProperty('size')); |
371 for (var i = 0; i < 10; i++) { | 371 for (var i = 0; i < 10; i++) { |
372 assertEquals(i, m.size); | 372 assertEquals(i, m.size); |
373 m.set(i, i); | 373 m.set(i, i); |
374 } | 374 } |
375 for (var i = 9; i >= 0; i--) { | 375 for (var i = 9; i >= 0; i--) { |
376 m.delete(i); | 376 m.delete(i); |
377 assertEquals(i, m.size); | 377 assertEquals(i, m.size); |
378 } | 378 } |
379 | 379 |
380 // Test clear | |
381 var a = new Set(); | |
382 s.add(42); | |
383 assertTrue(s.has(42)); | |
384 s.clear(); | |
385 assertFalse(s.has(42)); | |
386 assertEquals(0, s.size); | |
387 | 380 |
388 var m = new Map(); | 381 // Test Set clear |
389 m.set(42, true); | 382 (function() { |
390 assertTrue(m.has(42)); | 383 var s = new Set(); |
391 m.clear(); | 384 s.add(42); |
392 assertFalse(m.has(42)); | 385 assertTrue(s.has(42)); |
393 assertEquals(0, m.size); | 386 assertEquals(1, s.size); |
| 387 s.clear(); |
| 388 assertFalse(s.has(42)); |
| 389 assertEquals(0, s.size); |
| 390 })(); |
| 391 |
| 392 |
| 393 // Test Map clear |
| 394 (function() { |
| 395 var m = new Map(); |
| 396 m.set(42, true); |
| 397 assertTrue(m.has(42)); |
| 398 assertEquals(1, m.size); |
| 399 m.clear(); |
| 400 assertFalse(m.has(42)); |
| 401 assertEquals(0, m.size); |
| 402 })(); |
| 403 |
| 404 |
| 405 // Test WeakMap clear |
| 406 (function() { |
| 407 var k = new Object(); |
| 408 var w = new WeakMap(); |
| 409 w.set(k, 23); |
| 410 assertTrue(w.has(k)); |
| 411 assertEquals(23, w.get(k)); |
| 412 w.clear(); |
| 413 assertFalse(w.has(k)); |
| 414 assertEquals(undefined, w.get(k)); |
| 415 })(); |
OLD | NEW |