summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_8_5/reflect-parse/object-spread.js
blob: a4b269c40986832cf4e689e65bdddfee0b7cc1e7 (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
// |reftest| skip-if(!xulRuntime.shell)

function property(key, value = key, shorthand = key === value) {
    return { key, value, shorthand };
}

function test() {
    // Any expression can be spreaded.
    assertExpr("({...x})", objExpr([spread(ident("x"))]));
    assertExpr("({...f()})", objExpr([spread(callExpr(ident("f"), []))]));
    assertExpr("({...123})", objExpr([spread(lit(123))]));

    // Multiple spread expression are allowed.
    assertExpr("({...x, ...obj.p})", objExpr([spread(ident("x")), spread(dotExpr(ident("obj"), ident("p")))]));

    // Spread expression can appear anywhere in an object literal.
    assertExpr("({p, ...x})", objExpr([property(ident("p")), spread(ident("x"))]));
    assertExpr("({p: a, ...x})", objExpr([property(ident("p"), ident("a")), spread(ident("x"))]));
    assertExpr("({...x, p: a})", objExpr([spread(ident("x")), property(ident("p"), ident("a"))]));

    // Trailing comma after spread expression is allowed.
    assertExpr("({...x,})", objExpr([spread(ident("x"))]));

    // __proto__ is not special in spread expressions.
    assertExpr("({...__proto__})", objExpr([spread(ident("__proto__"))]));
    assertExpr("({...__proto__, ...__proto__})", objExpr([spread(ident("__proto__")), spread(ident("__proto__"))]));
}

runtest(test);