summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Statements/property-reference-self-assignment.js
blob: 81c95b9cfb608a0717e81eb0d6b5e6644feb9374 (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
var hits = 0;

var p = { toString() { hits++; return "prop" } };
var obj = { foo: 1 };


var ops = [["obj[p]++", 2],
           ["++obj[p]", 2],
           ["--obj[p]", 0],
           ["obj[p]--", 0],
           ["obj[p] += 2", 3],
           ["obj[p] -= 2", -1],
           ["obj[p] *= 2", 2],
           ["obj[p] /= 2", 0.5],
           ["obj[p] %= 2", 1],
           ["obj[p] >>>= 2", 0],
           ["obj[p] >>= 2", 0],
           ["obj[p] <<= 2", 4],
           ["obj[p] |= 2", 3],
           ["obj[p] ^= 2", 3],
           ["obj[p] &= 2", 0]];

var testHits = 0;
for (let op of ops) {
    // Seed the value for each test.
    obj.prop = 1;

    // Do the operation.
    eval(op[0]);
    assertEq(obj.prop, op[1]);

    // We should always call toString once, for each operation.
    testHits++;
    assertEq(hits, testHits);
}

if (typeof reportCompare === 'function')
    reportCompare(0,0,"OK");