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:
@@ -1460,16 +1460,27 @@ parser_parse_tagged_template_literal (parser_context_t *context_p) /**< context
|
|||||||
return call_arguments;
|
return call_arguments;
|
||||||
} /* parser_parse_tagged_template_literal */
|
} /* 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.
|
* Throws an error if the current expression is not an assignment expression.
|
||||||
*/
|
*/
|
||||||
static inline void JERRY_ATTR_ALWAYS_INLINE
|
static inline void JERRY_ATTR_ALWAYS_INLINE
|
||||||
parser_check_assignment_expr (parser_context_t *context_p)
|
parser_check_assignment_expr (parser_context_t *context_p)
|
||||||
{
|
{
|
||||||
if (context_p->stack_top_uint8 != LEXER_EXPRESSION_START
|
if (!parser_is_assignment_expr (context_p))
|
||||||
&& 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_raise_error (context_p, PARSER_ERR_ASSIGNMENT_EXPECTED);
|
parser_raise_error (context_p, PARSER_ERR_ASSIGNMENT_EXPECTED);
|
||||||
}
|
}
|
||||||
@@ -1719,9 +1730,15 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
|
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);
|
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER);
|
||||||
|
|
||||||
|
if (parser_is_assignment_expr (context_p))
|
||||||
|
{
|
||||||
parser_parse_object_initializer (context_p, PARSER_PATTERN_NO_OPTS);
|
parser_parse_object_initializer (context_p, PARSER_PATTERN_NO_OPTS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scanner_release_next (context_p, sizeof (scanner_location_info_t));
|
||||||
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
parser_parse_object_literal (context_p);
|
parser_parse_object_literal (context_p);
|
||||||
@@ -1733,9 +1750,15 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
|||||||
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
|
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);
|
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER);
|
||||||
|
|
||||||
|
if (parser_is_assignment_expr (context_p))
|
||||||
|
{
|
||||||
parser_parse_array_initializer (context_p, PARSER_PATTERN_NO_OPTS);
|
parser_parse_array_initializer (context_p, PARSER_PATTERN_NO_OPTS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scanner_release_next (context_p, sizeof (scanner_location_info_t));
|
||||||
|
}
|
||||||
#endif /* ENABLED (JERRY_ES2015) */
|
#endif /* ENABLED (JERRY_ES2015) */
|
||||||
|
|
||||||
parser_parse_array_literal (context_p);
|
parser_parse_array_literal (context_p);
|
||||||
|
|||||||
@@ -304,3 +304,10 @@ mustThrow ("try { throw 5 } catch (e) {"
|
|||||||
+ "var iter = __createIterableObject([], "
|
+ "var iter = __createIterableObject([], "
|
||||||
+ "{ 'return': function() { return 5; }});"
|
+ "{ 'return': function() { return 5; }});"
|
||||||
+ "var [a] = iter }");
|
+ "var [a] = iter }");
|
||||||
|
|
||||||
|
try {
|
||||||
|
eval ("var a = 0; 1 + [a] = [1]");
|
||||||
|
assert (false);
|
||||||
|
} catch (e) {
|
||||||
|
assert (e instanceof ReferenceError);
|
||||||
|
}
|
||||||
|
|||||||
@@ -225,3 +225,10 @@ mustThrow ("function f ({}) {}; f();");
|
|||||||
({"a": ((a)) } = {a : 7});
|
({"a": ((a)) } = {a : 7});
|
||||||
assert (a === 7);
|
assert (a === 7);
|
||||||
}) ();
|
}) ();
|
||||||
|
|
||||||
|
try {
|
||||||
|
eval ("var a = 0; -{a} = {a:1}");
|
||||||
|
assert (false);
|
||||||
|
} catch (e) {
|
||||||
|
assert (e instanceof ReferenceError);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user