summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/watchtower/property-modification.js
blob: 993cb5bdf822dcfadb2b59beaf4eac124eced31e (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
function getLogString(obj) {
    let log = getWatchtowerLog();
    return log.map(item => {
        assertEq(item.object, obj);
        if (typeof item.extra === "symbol") {
            item.extra = "<symbol>";
        }
        return item.kind + (item.extra ? ": " + item.extra : "");
    }).join("\n");
}

function testBasic() {
    let o = { a: 10 };
    addWatchtowerTarget(o);

    // modify-prop: a
    o.a = 12;
    let p = { a: 15 };

    // modify-prop: a
    Object.assign(o, p);

    // change-prop: a
    Object.defineProperty(o, "a", { value: 19 });
    let log = getLogString(o);

    assertEq(log,
        `modify-prop: a
modify-prop: a
change-prop: a`);
}

for (var i = 0; i < 20; i++) {
    console.log(`Iteration ${i}`);
    testBasic();
}