Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / harness / internals-observe-gc.html
blob803497787766eaceb30d56b2883a973bc053b152
1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script>
3 <body>
4 <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.
12 var valueA = {};
13 observationA = internals.observeGC(valueA);
14 gc();
15 shouldBeFalse('observationA.wasCollected');
16 // value ineligible for GC should not be flagged as collected
17 valueA = null;
18 observationA = null;
20 // "Romeo and GCuliet": Romeo JavaScript finds G.uliet C.apulet and dies.
22 var valueB = {};
23 observationB = internals.observeGC(valueB);
24 valueB = null;
25 gc();
26 shouldBeTrue('observationB.wasCollected');
27 // value eligible for GC should be flagged as collected
28 observationB = null;
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);
35 valueC = null;
36 gc();
37 shouldBeTrue('observationC.wasCollected');
38 // DOM node eligible for GC should be flagged as collected
39 observationC = null;
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
48 var valueD = {};
49 var observerD = internals.observeGC(valueD);
50 valueD.observer = observerD;
51 observerD.observed = valueD;
52 valueD = observerD = null;
53 gc();
54 testPassed('did not crash');
56 var successfullyParsed = true;
57 </script>