<html>
<script>
function stateChange() {
    document.write(this.foo + '<br>');
    if (this.readyState == 4) {
        if (window.testRunner)
            testRunner.notifyDone();
    }
}

function collectGarbage() {
    if (window.GCController) {
        window.GCController.collect();
    } else {
      for (var i = 0; i < 50000; i++)
          new Object();
    }
}

function runTest() {
    document.write("Tests that garbage collection doesn't drop the XMLHttpRequest JS wrapper until the send command is done.  You should see 'bar' four times below.<br>");

    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    var xhr = new XMLHttpRequest();
    xhr.foo = 'bar';
    xhr.onreadystatechange = stateChange;
    xhr.open("GET", "xmlhttprequest-gc.html", true);
    xhr.send(null);

    xhr = null;
    collectGarbage();
}

</script>
<body onload='runTest()'>
</body>
</html>
