2 <script src=
"../../resources/js-test.js"></script>
5 description('Tests that the window.internals.observeGC hook works.');
7 shouldBe('typeof window.internals.observeGC', '"function"',
8 'this test requires window.internals');
10 // "Generic Kid's Movie III": ... where nobody dies.
13 observationA
= internals
.observeGC(valueA
);
15 shouldBeFalse('observationA.wasCollected');
16 // value ineligible for GC should not be flagged as collected
20 // "Romeo and GCuliet": Romeo JavaScript finds G.uliet C.apulet and dies.
23 observationB
= internals
.observeGC(valueB
);
26 shouldBeTrue('observationB.wasCollected');
27 // value eligible for GC should be flagged as collected
30 // "One DOM Tree Hill": A family struggles with the loss of
31 // innocence. And a DOM node.
33 var valueC
= document
.createElement('div');
34 observationC
= internals
.observeGC(valueC
);
37 shouldBeTrue('observationC.wasCollected');
38 // DOM node eligible for GC should be flagged as collected
41 // Now, movies that failed:
43 shouldThrow('internals.observeGC(undefined)', '"TypeError: value to observe is null or undefined"');
44 shouldThrow('internals.observeGC(null)', '"TypeError: value to observe is null or undefined"');
46 // Try to create objects and observers that will die at once
49 var observerD
= internals
.observeGC(valueD
);
50 valueD
.observer
= observerD
;
51 observerD
.observed
= valueD
;
52 valueD
= observerD
= null;
54 testPassed('did not crash');
56 var successfullyParsed
= true;