Skip to content

Commit f3a9949

Browse files
0xegbrail
authored andcommitted
Handle unimplemented rest parameters in destructuring
1 parent f1fde56 commit f3a9949

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

rhino/src/main/java/org/mozilla/javascript/Parser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4920,7 +4920,10 @@ boolean destructuringObject(
49204920
boolean defaultValuesSetup = false;
49214921

49224922
for (AbstractObjectProperty abstractProp : node.getElements()) {
4923-
if (abstractProp instanceof SpreadObjectProperty) throw Kit.codeBug();
4923+
if (abstractProp instanceof SpreadObjectProperty) {
4924+
reportError("msg.no.object.rest");
4925+
return false;
4926+
}
49244927
ObjectProperty prop = (ObjectProperty) abstractProp;
49254928

49264929
int lineno = 0, column = 0;

rhino/src/main/resources/org/mozilla/javascript/resources/Messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ msg.no.paren.after.parms =\
348348
msg.parm.after.rest =\
349349
parameter after rest parameter
350350

351+
msg.no.object.rest =\
352+
object rest properties in destructuring are not supported
353+
351354
msg.no.brace.body =\
352355
missing '{' before function body
353356

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.mozilla.javascript.tests;
2+
3+
import org.junit.Test;
4+
import org.mozilla.javascript.testutils.Utils;
5+
6+
/** Object rest in destructuring throws SyntaxError */
7+
public class ObjectRestErrorTest {
8+
9+
@Test
10+
public void objectRestThrowsSyntaxError() {
11+
Utils.assertEvaluatorExceptionES6(
12+
"object rest properties in destructuring are not supported",
13+
"function f() { var { a, ...rest } = { a: 1, b: 2, c: 3 }; }");
14+
}
15+
16+
@Test
17+
public void objectRestInFunctionParamThrowsSyntaxError() {
18+
Utils.assertEvaluatorExceptionES6(
19+
"object rest properties in destructuring are not supported",
20+
"function f({ a, ...rest }) { return rest; }");
21+
}
22+
23+
@Test
24+
public void objectRestInVariableDeclarationThrowsSyntaxError() {
25+
Utils.assertEvaluatorExceptionES6(
26+
"object rest properties in destructuring are not supported",
27+
"var { a, ...rest } = { a: 1, b: 2, c: 3 };");
28+
}
29+
}

0 commit comments

Comments
 (0)