summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/bug507180.js
blob: 9d8fb195803d7b950c6c668b846b26d83e7fa1c5 (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
65
66
67
68
69
var o = {
  valueOf : function() {
    return {
      toString : function() { return "fail" }
    }
  },
  toString : function() { return "good" }
};

var p = {
  valueOf : function() {
    return {
      toString : function() { return "0" }
    }
  },
  toString : function() { return "7" }
};

var q = {
  toString : function() {
    return {
      valueOf : function() { return "0" }
    }
  },
  valueOf : function() { return "7" }
};

function assert(b, s) {
    if (b)
        return;
    assertEq("imacro produces incorrect result for " + s, "fail");
}

function run() {
    for (var i = 0; i < 5; ++i) {
        // equality / inequality
        assert(!(o == "fail"), "obj == any");
        assert(!("fail" == o), "any == obj");
        assert(!(o != "good"), "obj != any");
        assert(!("good" != o), "any != obj");

        // binary
        assert(!((p | 3) != 7), "obj | any");
        assert(!((3 | p) != 7), "any | obj");
        assert(!((p | p) != 7), "obj | obj");
        assert(!((p & 3) != 3), "obj & any");
        assert(!((3 & p) != 3), "any & obj");
        assert(!((p & p) != 7), "obj & obj");
        assert(!((p * 3) != 21), "obj * any");
        assert(!((3 * p) != 21), "any * obj");
        assert(!((p * p) != 49), "obj * obj");

        // addition
        assert(!(o + "" != "good"), "obj + any");
        assert(!("" + o != "good"), "any + obj");
        assert(!(o + o != "goodgood"), "any + any");

        // sign
        assert(!(-p != -7), "-obj");
        assert(!(+p != 7), "+obj");

        // String
        assert(!(String(q) != "7"), "String(obj)");
        assert(!(new String(q) != "7"), "new String(obj)");
    }
    return true;
}

run();