message-channel-gc-3.html-disabled 1.2 KB
Newer Older
ap@webkit.org's avatar
ap@webkit.org committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<body>
<p>Test that MessagePort messages are delivered even if both ports are inaccessible from JS any more.</p>
<p>Should say PASS twice.</p>
<pre id=log></pre>
<script>
function gc()
{
    if (window.GCController)
        return GCController.collect();

    for (var i = 0; i < 10000; i++) { // > force garbage collection (FF requires about 9K allocations before a collect)
        var s = new String("abc");
    }
}

function log(message)
{
    document.getElementById("log").innerHTML += message + "<br>";
}

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

function test1()
{
    var channel = new MessageChannel;
    
    channel.port1.onmessage = function(evt) { log("PASS: message delivered. Port: " + evt.target); test2(); }
    channel.port1.start();
    channel.port2.postMessage("msg");
    
    channel = 0;
    gc();
}

function test2()
{
    var channel = new MessageChannel;
    
    channel.port1.onclose = function(evt) { log("PASS: close message delivered. Port: " + evt.target); if (window.layoutTestController) layoutTestController.notifyDone(); }
    channel.port2.close();
    
    channel = 0;
    gc();
}

test1();

</script>
</body>