| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 enumerable: false, | 297 enumerable: false, |
| 298 configurable: false | 298 configurable: false |
| 299 }, Object.getOwnPropertyDescriptor(C, "prototype")); | 299 }, Object.getOwnPropertyDescriptor(C, "prototype")); |
| 300 } | 300 } |
| 301 TestPrototype(Set); | 301 TestPrototype(Set); |
| 302 TestPrototype(Map); | 302 TestPrototype(Map); |
| 303 TestPrototype(WeakMap); | 303 TestPrototype(WeakMap); |
| 304 TestPrototype(WeakSet); | 304 TestPrototype(WeakSet); |
| 305 | 305 |
| 306 | 306 |
| 307 // Test that constructor can be called only on appropriate objects only once. |
| 308 function TestConstructorBehavior(C) { |
| 309 var obj = new C(); |
| 310 assertThrows(function() { C.call(obj); }, TypeError); |
| 311 assertThrows(function() { C.call({}); }, TypeError); |
| 312 var uninitObj = %NewObject(C); |
| 313 C.call(uninitObj); // shouldn't throw |
| 314 } |
| 315 TestConstructorBehavior(Set); |
| 316 TestConstructorBehavior(Map); |
| 317 TestConstructorBehavior(WeakMap); |
| 318 TestConstructorBehavior(WeakSet); |
| 319 |
| 320 |
| 307 // Test constructor property of the Set, Map, WeakMap and WeakSet prototype. | 321 // Test constructor property of the Set, Map, WeakMap and WeakSet prototype. |
| 308 function TestConstructor(C) { | 322 function TestConstructor(C) { |
| 309 assertFalse(C === Object.prototype.constructor); | 323 assertFalse(C === Object.prototype.constructor); |
| 310 assertSame(C, C.prototype.constructor); | 324 assertSame(C, C.prototype.constructor); |
| 311 assertSame(C, (new C).__proto__.constructor); | 325 assertSame(C, (new C).__proto__.constructor); |
| 312 } | 326 } |
| 313 TestConstructor(Set); | 327 TestConstructor(Set); |
| 314 TestConstructor(Map); | 328 TestConstructor(Map); |
| 315 TestConstructor(WeakMap); | 329 TestConstructor(WeakMap); |
| 316 TestConstructor(WeakSet); | 330 TestConstructor(WeakSet); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 490 |
| 477 | 491 |
| 478 // Test WeakSet clear | 492 // Test WeakSet clear |
| 479 (function() { | 493 (function() { |
| 480 var k = new Object(); | 494 var k = new Object(); |
| 481 var w = new WeakSet(); | 495 var w = new WeakSet(); |
| 482 w.add(k); | 496 w.add(k); |
| 483 assertTrue(w.has(k)); | 497 assertTrue(w.has(k)); |
| 484 w.clear(); | 498 w.clear(); |
| 485 assertFalse(w.has(k)); | 499 assertFalse(w.has(k)); |
| 486 })(); | 500 })(); |
| OLD | NEW |