Skip to content

Commit 1770cca

Browse files
authored
Object/Array initializers should be parsed as AssignmentExpression (#3851)
This patch fixes #3849. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 0d41169 commit 1770cca

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

jerry-core/parser/js/js-parser-expr.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,14 +1581,14 @@ parser_check_assignment_expr (parser_context_t *context_p)
15811581
} /* parser_check_assignment_expr */
15821582

15831583
/**
1584-
* Checks whether the next token is a valid continuation token after an arrow function.
1584+
* Checks whether the next token is a valid continuation token after an AssignmentExpression.
15851585
*/
15861586
static inline bool JERRY_ATTR_ALWAYS_INLINE
1587-
parser_abort_parsing_after_arrow (parser_context_t *context_p)
1587+
parser_abort_parsing_after_assignment_expression (parser_context_t *context_p)
15881588
{
15891589
return (context_p->token.type != LEXER_RIGHT_PAREN
15901590
&& context_p->token.type != LEXER_COMMA);
1591-
} /* parser_abort_parsing_after_arrow */
1591+
} /* parser_abort_parsing_after_assignment_expression */
15921592

15931593
#endif /* ENABLED (JERRY_ES2015) */
15941594

@@ -1732,7 +1732,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
17321732

17331733
parser_check_assignment_expr (context_p);
17341734
parser_parse_function_expression (context_p, arrow_status_flags);
1735-
return parser_abort_parsing_after_arrow (context_p);
1735+
return parser_abort_parsing_after_assignment_expression (context_p);
17361736
}
17371737
#endif /* ENABLED (JERRY_ES2015) */
17381738

@@ -1828,7 +1828,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
18281828
if (parser_is_assignment_expr (context_p))
18291829
{
18301830
parser_parse_object_initializer (context_p, PARSER_PATTERN_NO_OPTS);
1831-
return false;
1831+
return parser_abort_parsing_after_assignment_expression (context_p);
18321832
}
18331833

18341834
scanner_release_next (context_p, sizeof (scanner_location_info_t));
@@ -1848,7 +1848,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
18481848
if (parser_is_assignment_expr (context_p))
18491849
{
18501850
parser_parse_array_initializer (context_p, PARSER_PATTERN_NO_OPTS);
1851-
return false;
1851+
return parser_abort_parsing_after_assignment_expression (context_p);
18521852
}
18531853

18541854
scanner_release_next (context_p, sizeof (scanner_location_info_t));
@@ -1949,7 +1949,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
19491949
parser_check_assignment_expr (context_p);
19501950

19511951
parser_parse_function_expression (context_p, PARSER_IS_FUNCTION | PARSER_IS_ARROW_FUNCTION);
1952-
return parser_abort_parsing_after_arrow (context_p);
1952+
return parser_abort_parsing_after_assignment_expression (context_p);
19531953
}
19541954
case LEXER_KEYW_YIELD:
19551955
{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
try {
16+
eval(`[]=$--['']`);
17+
assert(false);
18+
} catch (e) {
19+
assert(e instanceof SyntaxError);
20+
}
21+

0 commit comments

Comments
 (0)