summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/js/negate-overflow.html
blob: 4f412c1d70ffd8f1ee204fc55997d1320907e06a (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
<p>Test for overflow when negating the largest negative signed int.</p>
<p>If the test passes, you'll see a series of PASS messages below.</p>

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

<script>
function $(id)
{
    return document.getElementById(id);
}

function log(s)
{
    $("console").appendChild(document.createTextNode(s + "\n"));
}

function shouldBe(aDescription, a, b)
{
    if (a === b) {
        log("PASS: " + aDescription + " should be " + b + " and is.");
    } else {
        log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
    }
}

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

    // Can be constant-folded by the parser.
    var x = -(-2147483648);
    shouldBe("x", x, 2147483648);
    
    // Can't be constant-folded without dataflow analysis.
    var y = -2147483648;
    y = -y;
    shouldBe("y", y, 2147483648);
})();
</script>