<p>Tests that custom prototypes on DOM objects persist after garbage collection.</p>
<pre id="console"></pre>

<p id="p"></p>

<script>
function $(id)
{
    return document.getElementById(id);
}

function log(s)
{
    $("console").appendChild(document.createTextNode(s + "\n"));
}

function shouldBe(aDescription, a, b)
{
    if (a != b) {
        log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
        return;
    }

    log("PASS: " + aDescription + " should be " + b + " and is.");
}

function gc()
{
    if (window.GCController) {
        GCController.collect();
        return;
    }
    
    for (var i = 0; i < 10000; ++i)
        new Object;
}

function shouldBeNull(aDescription, a)
{
    if (a == null) {
        log("PASS: " + aDescription + " should be null and is.");
        return;
    }
    
    log("FAIL: " + aDescription + " should be null but instead is " + a + ".");
}

function shouldBeNonNull(aDescription, a)
{
    if (a != null) {
        log("PASS: " + aDescription + " should be null and is.");
        return;
    }
    
    log("FAIL: " + aDescription + " should be null but instead is " + a + ".");
}

(function () {
    if (window.testRunner)
        testRunner.dumpAsText();

    shouldBeNonNull("$('p').__proto__", $('p').__proto__);
    $('p').__proto__ = null;
    shouldBeNull("$('p').__proto__", $('p').__proto__);

    gc();

    shouldBeNull("$('p').__proto__", $('p').__proto__);
})();
</script>
