summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Symbol/property-accessor.js
blob: 7a2c149a1e32a4c8844916a1b286b2841f4f209a (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/ */

var obj = {};
var sym = Symbol();

var gets = 0;
var sets = [];
Object.defineProperty(obj, sym, {
    get: function () { return ++gets; },
    set: function (v) { sets.push(v); }
});

// getter
for (var i = 1; i < 9; i++)
    assertEq(obj[sym], i);

// setter
var expected = [];
for (var i = 0; i < 9; i++) {
    assertEq(obj[sym] = i, i);
    expected.push(i);
}
assertDeepEq(sets, expected);

// increment operator
gets = 0;
sets = [];
assertEq(obj[sym]++, 1);
assertDeepEq(sets, [2]);

// assignment
gets = 0;
sets = [];
assertEq(obj[sym] *= 12, 12);
assertDeepEq(sets, [12]);

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