summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_8_5/reflect-parse/object-rest.js
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2019-07-20 20:43:11 +0000
committerGitHub <noreply@github.com>2019-07-20 20:43:11 +0000
commit779ef307af82035d987744bc5d6fc74e9fb6fac7 (patch)
treef52eaf7c1392997b75b176c82218edba4e856eef /js/src/tests/js1_8_5/reflect-parse/object-rest.js
parent9dce66f58910b0d1363be3a8e3b5232d79692516 (diff)
parent4a0061a3e0976d4001e23d66af04b06af792675f (diff)
downloadUXP-779ef307af82035d987744bc5d6fc74e9fb6fac7.tar
UXP-779ef307af82035d987744bc5d6fc74e9fb6fac7.tar.gz
UXP-779ef307af82035d987744bc5d6fc74e9fb6fac7.tar.lz
UXP-779ef307af82035d987744bc5d6fc74e9fb6fac7.tar.xz
UXP-779ef307af82035d987744bc5d6fc74e9fb6fac7.zip
Merge pull request #1192 from g4jc/parser_tuneup
Issues #816 / #802 - SpiderMonkey Tuneup
Diffstat (limited to 'js/src/tests/js1_8_5/reflect-parse/object-rest.js')
-rw-r--r--js/src/tests/js1_8_5/reflect-parse/object-rest.js45
1 files changed, 45 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);