summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/js/add-to-primitive.html
blob: 21a1de43d44031e8d30dbe569295fb3dfc1f1041 (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
<p>This page tests that string addition prefers valueOf() over toString() for conversion. If the test passes, you'll see a PASS message below.</p>

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

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

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

if (this.testRunner)
    testRunner.dumpAsText();
    
var valueOfIsZero = {
    valueOf: function valueOf() { return 0; },
    toString: function toString() { return 1; }
};

shouldBe('1' + valueOfIsZero, "'1' + valueOfIsZero", "10");

</script>