summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_5/strict/primitive-this-getter.js
blob: 55fd79d9df4b71e7a2d6192169c9762f566410ff (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
let primitives = [
    10,
    false,
    "test",
    Symbol()
]

let getter = "getter";
let getter2 = "getter2";
let key = "key";

for (let value of primitives) {
    let prototype = Object.getPrototypeOf(value);

    // Strict getters receive a primitive this value.
    Object.defineProperty(prototype, "getter", {get: function() {
        "use strict";
        assertEq(this, value);
        return "getter";
    }})

    assertEq(value.getter, "getter");
    assertEq(value[getter], "getter");

    // The proxy's [[Get]] trap is also invoked with primitive receiver values.
    let proxy = new Proxy({}, {
        get(target, property, receiver) {
            assertEq(property, "key");
            assertEq(receiver, value);
            return "get";
        }
    });

    Object.setPrototypeOf(prototype, proxy);
    assertEq(value.key, "get");
    assertEq(value[key], "get");
    assertEq(value.getter, "getter");
    assertEq(value[getter], "getter");

    // A getter still gets a primitive this value even after going through a proxy.
    proxy = new Proxy({
        get getter2() {
            "use strict";
            assertEq(this, value);
            return "getter2";
        }
    }, {});

    Object.setPrototypeOf(prototype, proxy);
    assertEq(value.getter2, "getter2");
    assertEq(value[getter2], "getter2");
    assertEq(value.getter, "getter");
    assertEq(value[getter], "getter");
}

reportCompare(true, true);