fpizlo@apple.com | 1795570 | 2014-03-02 03:45:06 +0000 | [diff] [blame] | 1 | // Tests that opaque roots behave correctly during young generation collections |
mhahnenberg@apple.com | cf05714 | 2014-02-10 19:59:16 +0000 | [diff] [blame] | 2 | |
| 3 | // Create the primary Root. |
| 4 | var root = new Root(); |
| 5 | // This secondary root is for allocating a second Element without overriding |
| 6 | // the primary Root's Element. |
| 7 | var otherRoot = new Root(); |
| 8 | |
| 9 | // Run an Eden collection so that the Root will be in the old gen (and won't be rescanned). |
| 10 | edenGC(); |
| 11 | |
| 12 | // Create a new Element and set a custom property on it. |
| 13 | var elem = new Element(root); |
| 14 | elem.customProperty = "hello"; |
| 15 | |
| 16 | // Make the Element unreachable except through the ephemeron with the Root. |
| 17 | elem = null; |
| 18 | |
| 19 | // Create another Element so that we process the weak handles in block of the original Element. |
| 20 | var test = new Element(otherRoot); |
| 21 | |
| 22 | // Run another Eden collection to process the weak handles in the Element's block. If opaque roots |
| 23 | // are cleared then we'll think that the original Element is dead because the Root won't be in the |
| 24 | // set of opaque roots. |
| 25 | edenGC(); |
| 26 | |
| 27 | // Check if the primary Root's Element exists and has our custom property. |
| 28 | var elem = getElement(root); |
fpizlo@apple.com | 1795570 | 2014-03-02 03:45:06 +0000 | [diff] [blame] | 29 | if (elem.customProperty != "hello") |
| 30 | throw new Error("bad value of customProperty: " + elem.customProperty); |