summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/class/superSetProperty.js
blob: 6e136cb58b63089d329d0ff238cc0809c212023a (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
class Base
{
    set setter(val) {
        this.set_val = val;
        this.set_this = this;
    }
}
Base.prototype.prop = "Base";

class Derived extends Base
{
    set setter(val) { super.setter = val; }
    setelem(pname, val) { super[pname] = val; }
}

// Test SETPROP_SUPER invoke setters correctly
function testSetterChain() {
    let d = new Derived();

    for (let i = 0; i < 10; ++i)
    {
        d.setter = i;
        assertEq(d.set_val, i);
        assertEq(d.set_this, d);
    }
}
function testSetterChainElem() {
    let d = new Derived();

    for (let i = 0; i < 10; ++i)
    {
        d.setelem("setter", i);
        assertEq(d.set_val, i);
        assertEq(d.set_this, d);
    }
}

// Test that SETPROP_SUPER modifies |this| and not home object
function testSuperSetProp() {
    let d = new Derived();

    for (let i = 0; i < 10; ++i)
    {
        d.prop = i;
        assertEq(d.prop, i);
        assertEq(d.hasOwnProperty("prop"), true);
        assertEq(Derived.prototype.prop, "Base");
    }
}
function testSuperSetPropElem() {
    let d = new Derived();

    for (let i = 0; i < 10; ++i)
    {
        d.setelem("prop", i);
        assertEq(d.prop, i);
        assertEq(d.hasOwnProperty("prop"), true);
        assertEq(Derived.prototype.prop, "Base");
    }
}

testSetterChain();
testSetterChainElem();

testSuperSetProp();
testSuperSetPropElem();