summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/js/string-replace-exception-crash.html
blob: b542c54173055669b479f69e04e9cf151168a095 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<p>This page tests for a crash when throwing an exception from a callback provided
to String.prototype.replace.
</p>

<p>If the test passes, you'll see a series of PASS messages below.
</p>

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

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

if (window.layoutTestController)
    layoutTestController.dumpAsText();

// these should not crash

try {
    (function () {
        "aa".replace(/a/g, function() {
            var bogus;
            bogus.property;
        });
    })();
} catch(e) {
    log ("PASS: You didn't crash.");
}

try {
    (function () {
        "aa".replace("a", function() {
            ({})();
        });
    })();
} catch(e) {
    log ("PASS: You didn't crash.");
}

// this should not continue execution after an exception

var message = "PASS: String.prototype.replace did not continue executing after an exception was thrown.";
try {
    (function () {
        var count = 0;
        "aa".replace(/a/g, function() {
            if (++count > 1)
                message = "FAIL: String.prototype.replace continued executing after an exception was thrown.";

            var bogus;
            bogus.property;
        });
    })();
} catch(e) {
    try {
        (function x() { return 'blargh'.replace(/a/g, x) })()
    } catch(e) {
        log (message);
    }
}

</script>