summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_8_5
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2019-07-14 20:54:31 -0400
committerGaming4JC <g4jc@hyperbola.info>2019-07-18 22:38:47 -0400
commit262b1194ffeba70fcb81abad4adfa40f1bf646be (patch)
treeef11426d1d23ffe3c224ba19ea0aeb09f3b039dc /js/src/tests/js1_8_5
parent3048ff4346bf2021059bdecec6343c73bb26833a (diff)
downloadUXP-262b1194ffeba70fcb81abad4adfa40f1bf646be.tar
UXP-262b1194ffeba70fcb81abad4adfa40f1bf646be.tar.gz
UXP-262b1194ffeba70fcb81abad4adfa40f1bf646be.tar.lz
UXP-262b1194ffeba70fcb81abad4adfa40f1bf646be.tar.xz
UXP-262b1194ffeba70fcb81abad4adfa40f1bf646be.zip
1339395 - Part 5: Add Reflect.parse tests for object rest and spread properties.
Diffstat (limited to 'js/src/tests/js1_8_5')
-rw-r--r--js/src/tests/js1_8_5/reflect-parse/object-rest.js45
-rw-r--r--js/src/tests/js1_8_5/reflect-parse/object-spread.js29
2 files changed, 74 insertions, 0 deletions
diff --git a/js/src/tests/js1_8_5/reflect-parse/object-rest.js b/js/src/tests/js1_8_5/reflect-parse/object-rest.js
new file mode 100644
index 000000000..5af06909b
--- /dev/null
+++ b/js/src/tests/js1_8_5/reflect-parse/object-rest.js
@@ -0,0 +1,45 @@
+// |reftest| skip-if(!xulRuntime.shell)
+
+function property(key, value = key, shorthand = key === value) {
+ return { key, value, shorthand };
+}
+
+function assertDestrAssign(src, pattern) {
+ assertExpr(`(${src} = 0)`, aExpr("=", pattern, lit(0)));
+}
+
+function assertDestrBinding(src, pattern) {
+ assertDecl(`var ${src} = 0`, varDecl([{id: pattern, init: lit(0)}]));
+}
+
+function test() {
+ // Target expression must be a simple assignment target or a nested pattern
+ // in object assignment patterns.
+ assertDestrAssign("{...x}", objPatt([spread(ident("x"))]));
+ assertDestrAssign("{...(x)}", objPatt([spread(ident("x"))]));
+ assertDestrAssign("{...obj.p}", objPatt([spread(dotExpr(ident("obj"), ident("p")))]));
+ assertDestrAssign("{...{}}", objPatt([spread(objPatt([]))]));
+ assertDestrAssign("{...[]}", objPatt([spread(arrPatt([]))]));
+
+ // Object binding patterns only allow binding identifiers or nested patterns.
+ assertDestrBinding("{...x}", objPatt([spread(ident("x"))]));
+ assertDestrBinding("{...{}}", objPatt([spread(objPatt([]))]));
+ assertDestrBinding("{...[]}", objPatt([spread(arrPatt([]))]));
+
+ // The rest-property can be preceded by other properties.
+ for (var assertDestr of [assertDestrAssign, assertDestrBinding]) {
+ assertDestr("{a, ...x}", objPatt([property(ident("a")), spread(ident("x"))]));
+ assertDestr("{a: b, ...x}", objPatt([property(ident("a"), ident("b")), spread(ident("x"))]));
+ assertDestr("{[a]: b, ...x}", objPatt([property(comp(ident("a")), ident("b")), spread(ident("x"))]));
+ }
+
+ // Tests when __proto__ is used in the object pattern.
+ for (var assertDestr of [assertDestrAssign, assertDestrBinding]) {
+ assertDestr("{...__proto__}", objPatt([spread(ident("__proto__"))]));
+ assertDestr("{__proto__, ...x}", objPatt([property(ident("__proto__")), spread(ident("x"))]));
+ }
+ assertDestrAssign("{__proto__: a, ...x}", objPatt([property(lit("__proto__"), ident("a")), spread(ident("x"))]));
+ assertDestrBinding("{__proto__: a, ...x}", objPatt([property(ident("__proto__"), ident("a")), spread(ident("x"))]));
+}
+
+runtest(test);
diff --git a/js/src/tests/js1_8_5/reflect-parse/object-spread.js b/js/src/tests/js1_8_5/reflect-parse/object-spread.js
new file mode 100644
index 000000000..a4b269c40
--- /dev/null
+++ b/js/src/tests/js1_8_5/reflect-parse/object-spread.js
@@ -0,0 +1,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);