summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/js/throw-from-array-sort.html
blob: a78b742428889c48a68221e9d80b1efa0b660e3f (plain)
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
<p>This test verifies that an exception thrown during array sort immediately ends execution.</p>
<p>If the test passes, you'll see a pass message below.</p>

<pre id="console">FAIL: Exception did not propogate from array sort.</pre>

<script>
function log(s)
{
    document.getElementById("console").innerHTML = s + "\n";
}

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

var passed = true;

var array = [ 1, 2, 3 ];
var sortFunction = (function () {
    var alreadyCalled = false;
    return function (a, b)
    {
        if (alreadyCalled)
            passed = false;

        alreadyCalled = true;
        throw 'threw';
    };
})();

try {
    array.sort(sortFunction);
} catch(e) {
    var result = passed ? "PASS"
                        : "FAIL: sort function was called after an exception was thrown"
    log (result);
}
</script>