Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / gc-12.html
blob9380910170bce1168af7f0408fedb2c6e694fcff
1 <p>
2 This test verifies that DOM nodes are not garbage collected as long as a node in the
3 tree is referenced from JavaScript.
4 </p>
6 <pre id="console"></pre>
8 <script>
9 function log(s)
11 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
14 function shouldBeNode(a, aDescription)
16 if (!(a instanceof Node)) {
17 log("FAIL: " + aDescription + " should be a Node but instead is " + a + ".");
18 return;
21 log("PASS: " + aDescription + " should be a Node and is.");
24 function gc()
26 if (window.GCController)
27 return GCController.collect();
29 for (var i = 0; i < 10000; i++)
30 var s = new String("");
33 (function () {
34 if (window.testRunner) {
35 testRunner.dumpAsText();
38 (function() {
39 // Try to create an orphan tree by removal.
40 var p = document.createElement("p");
41 document.body.appendChild(p);
42 p.innerHTML ='<div><span id="span"><br></span></div>';
43 var span = document.getElementById("span");
44 p.innerHTML = "";
46 gc();
48 shouldBeNode(span, "span");
49 shouldBeNode(span.parentNode, "span.parentNode");
50 shouldBeNode(span.firstChild, "span.firstChild");
51 })();
53 (function() {
54 // Try to create an orphan tree by insertion.
55 var p = document.createElement("p");
56 var span = document.createElement("span");
57 p.appendChild(span);
58 p = null;
60 gc();
62 shouldBeNode(span, "span");
63 shouldBeNode(span.parentNode, "span.parentNode");
64 })();
65 })();
66 </script>