67 lines
1.6 KiB
HTML
67 lines
1.6 KiB
HTML
<p>
|
|
This test verifies that DOM nodes are not garbage collected as long as a node in the
|
|
tree is referenced from JavaScript.
|
|
</p>
|
|
|
|
<pre id="console"></pre>
|
|
|
|
<script>
|
|
function log(s)
|
|
{
|
|
document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
|
|
}
|
|
|
|
function shouldBeNode(a, aDescription)
|
|
{
|
|
if (!(a instanceof Node)) {
|
|
log("FAIL: " + aDescription + " should be a Node but instead is " + a + ".");
|
|
return;
|
|
}
|
|
|
|
log("PASS: " + aDescription + " should be a Node and is.");
|
|
}
|
|
|
|
function gc()
|
|
{
|
|
if (window.GCController)
|
|
return GCController.collect();
|
|
|
|
for (var i = 0; i < 10000; i++)
|
|
var s = new String("");
|
|
}
|
|
|
|
(function () {
|
|
if (window.testRunner) {
|
|
testRunner.dumpAsText();
|
|
}
|
|
|
|
(function() {
|
|
// Try to create an orphan tree by removal.
|
|
var p = document.createElement("p");
|
|
document.body.appendChild(p);
|
|
p.innerHTML ='<div><span id="span"><br></span></div>';
|
|
var span = document.getElementById("span");
|
|
p.innerHTML = "";
|
|
|
|
gc();
|
|
|
|
shouldBeNode(span, "span");
|
|
shouldBeNode(span.parentNode, "span.parentNode");
|
|
shouldBeNode(span.firstChild, "span.firstChild");
|
|
})();
|
|
|
|
(function() {
|
|
// Try to create an orphan tree by insertion.
|
|
var p = document.createElement("p");
|
|
var span = document.createElement("span");
|
|
p.appendChild(span);
|
|
p = null;
|
|
|
|
gc();
|
|
|
|
shouldBeNode(span, "span");
|
|
shouldBeNode(span.parentNode, "span.parentNode");
|
|
})();
|
|
})();
|
|
</script>
|