2 This test verifies that DOM nodes are not garbage collected as long as a node in the
3 tree is referenced from JavaScript.
6 <pre id=
"console"></pre>
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
+ ".");
21 log("PASS: " + aDescription
+ " should be a Node and is.");
26 if (window
.GCController
)
27 return GCController
.collect();
29 for (var i
= 0; i
< 10000; i
++)
30 var s
= new String("");
34 if (window
.testRunner
) {
35 testRunner
.dumpAsText();
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");
48 shouldBeNode(span
, "span");
49 shouldBeNode(span
.parentNode
, "span.parentNode");
50 shouldBeNode(span
.firstChild
, "span.firstChild");
54 // Try to create an orphan tree by insertion.
55 var p
= document
.createElement("p");
56 var span
= document
.createElement("span");
62 shouldBeNode(span
, "span");
63 shouldBeNode(span
.parentNode
, "span.parentNode");