Array or object pattern must be assignment expression. (#3744)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-05-15 22:29:27 +02:00
committed by GitHub
parent 1f00d750b7
commit 4aa27371b6
3 changed files with 45 additions and 8 deletions
+31 -8
View File
@@ -1460,16 +1460,27 @@ parser_parse_tagged_template_literal (parser_context_t *context_p) /**< context
return call_arguments;
} /* parser_parse_tagged_template_literal */
/**
* Checks wheteher the current expression can be an assignment expression.
*
* @return true if the current expression can be an assignment expression, false otherwise
*/
static inline bool JERRY_ATTR_ALWAYS_INLINE
parser_is_assignment_expr (parser_context_t *context_p)
{
return (context_p->stack_top_uint8 == LEXER_EXPRESSION_START
|| context_p->stack_top_uint8 == LEXER_LEFT_PAREN
|| context_p->stack_top_uint8 == LEXER_COMMA_SEP_LIST
|| LEXER_IS_BINARY_LVALUE_TOKEN (context_p->stack_top_uint8));
} /* parser_is_assignment_expr */
/**
* Throws an error if the current expression is not an assignment expression.
*/
static inline void JERRY_ATTR_ALWAYS_INLINE
parser_check_assignment_expr (parser_context_t *context_p)
{
if (context_p->stack_top_uint8 != LEXER_EXPRESSION_START
&& context_p->stack_top_uint8 != LEXER_LEFT_PAREN
&& context_p->stack_top_uint8 != LEXER_COMMA_SEP_LIST
&& !LEXER_IS_BINARY_LVALUE_TOKEN (context_p->stack_top_uint8))
if (!parser_is_assignment_expr (context_p))
{
parser_raise_error (context_p, PARSER_ERR_ASSIGNMENT_EXPECTED);
}
@@ -1719,8 +1730,14 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
{
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER);
parser_parse_object_initializer (context_p, PARSER_PATTERN_NO_OPTS);
return false;
if (parser_is_assignment_expr (context_p))
{
parser_parse_object_initializer (context_p, PARSER_PATTERN_NO_OPTS);
return false;
}
scanner_release_next (context_p, sizeof (scanner_location_info_t));
}
#endif /* ENABLED (JERRY_ES2015) */
@@ -1733,8 +1750,14 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
{
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER);
parser_parse_array_initializer (context_p, PARSER_PATTERN_NO_OPTS);
return false;
if (parser_is_assignment_expr (context_p))
{
parser_parse_array_initializer (context_p, PARSER_PATTERN_NO_OPTS);
return false;
}
scanner_release_next (context_p, sizeof (scanner_location_info_t));
}
#endif /* ENABLED (JERRY_ES2015) */
+7
View File
@@ -304,3 +304,10 @@ mustThrow ("try { throw 5 } catch (e) {"
+ "var iter = __createIterableObject([], "
+ "{ 'return': function() { return 5; }});"
+ "var [a] = iter }");
try {
eval ("var a = 0; 1 + [a] = [1]");
assert (false);
} catch (e) {
assert (e instanceof ReferenceError);
}
+7
View File
@@ -225,3 +225,10 @@ mustThrow ("function f ({}) {}; f();");
({"a": ((a)) } = {a : 7});
assert (a === 7);
}) ();
try {
eval ("var a = 0; -{a} = {a:1}");
assert (false);
} catch (e) {
assert (e instanceof ReferenceError);
}