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

var symbols = [
    Symbol(),
    Symbol("one"),
    Symbol.for("two"),
    Symbol.iterator,
    Object(Symbol())
];

for (var sym of symbols) {
    var obj = {};

    // access a nonexistent property
    assertEq(sym in obj, false);
    assertEq(obj.hasOwnProperty(sym), false);
    assertEq(obj[sym], undefined);
    assertEq(typeof obj[sym], "undefined");
    assertEq(Object.getOwnPropertyDescriptor(obj, sym), undefined);

    // assign, then try accessing again
    obj[sym] = "ok";
    assertEq(sym in obj, true);
    assertEq(obj.hasOwnProperty(sym), true);
    assertEq(obj[sym], "ok");
    assertDeepEq(Object.getOwnPropertyDescriptor(obj, sym), {
        value: "ok",
        writable: true,
        enumerable: true,
        configurable: true
    });

    // assign again, observe value is overwritten
    obj[sym] = 12;
    assertEq(obj[sym], 12);

    // increment
    assertEq(obj[sym]++, 12);
    assertEq(obj[sym], 13);
}

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