chromium/third_party/blink/web_tests/fast/dom/Window/setTimeout-string-argument.html

<pre id="console"></pre>

<script>
if (window.testRunner) {
    testRunner.waitUntilDone();
    testRunner.dumpAsText()
}

function log(msg)
{
    document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
}

var intervalId;
function cancelSetInterval()
{
    window.clearInterval(intervalId);
}

function setTimeout1()
{
    var id = window.setTimeout("log('PASS: setTimeout(\"STRING\", 0) works.'); setInterval1()", 0);
    if (id == undefined)
        done(false);
}

function setInterval1()
{
    intervalId = window.setInterval("log('PASS: setInterval(\"STRING\", 0) works.'); cancelSetInterval(); setTimeout2()", 0);
    if (intervalId == undefined)
        done(false);
}

function setTimeout2()
{
    var id = window.setTimeout(String("log('PASS: setTimeout(String(\"STRING\"), 0) works.'); setInterval2()"), 0);
    if (id == undefined)
        done(false);
}

function setInterval2()
{
    intervalId = window.setInterval(String("log('PASS: setInterval(String(\"STRING\"), 0) works.'); cancelSetInterval(); setTimeout3()"), 0);
    if (intervalId == undefined)
        done(false);
}

function setTimeout3()
{
    var id = window.setTimeout({ toString : function() { return "log('PASS: setTimeout({toString:function(){}}, 0) works.'); setInterval3();" } }, 0);
    if (id == undefined)
        done(false);
}

function setInterval3()
{
    intervalId = window.setInterval({ toString : function() { return "log('PASS: setInterval({toString:function(){}}, 0) works.'); cancelSetInterval(); setTimeout4()" } }, 0);
    if (intervalId == undefined)
        done(false);
}

function setTimeout4()
{
    try {
        var id = window.setTimeout({ toString : function() { throw "Exception"; } }, 0);
        done(false);
    } catch (e) {
        log("PASS: setTimeout({ toString : function() { throw \"Exception\"; } }, 0) correctly threw an exception.");
        setInterval4();
    }
}

function setInterval4()
{
    try {
        var id = window.setInterval({ toString : function() { throw "Exception"; } }, 0);
        window.clearInterval(id);
        done(false);
    } catch (e) {
        log("PASS: setInterval({ toString : function() { throw \"Exception\"; } }, 0) correctly threw an exception.");
        done(true);
    }
}


function done(didPass)
{
    if (didPass)
        log("PASS: All tests passed.");
    else
        log("FAIL: All tests did not pass.");

    if (window.testRunner)
        testRunner.notifyDone();
}

setTimeout1();

</script>