Fix evaluation order in non-binding destructuring patterns (#4173)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2020-08-28 15:13:02 +02:00
committed by GitHub
parent 28c186c98f
commit 2f08d8ac08
11 changed files with 92 additions and 36 deletions
+9 -7
View File
@@ -3192,13 +3192,10 @@ parser_pattern_form_assignment (parser_context_t *context_p, /**< context */
parser_stack_push_uint8 (context_p, LEXER_EXPRESSION_START);
uint8_t assign_opcode = parser_append_binary_single_assignment_token (context_p, flags);
if (flags & PARSER_PATTERN_ARRAY)
{
int32_t stack_adjustment = (CBC_STACK_ADJUST_BASE - (cbc_flags[assign_opcode] >> CBC_STACK_ADJUST_SHIFT));
JERRY_ASSERT (stack_adjustment >= 1 && stack_adjustment <= 3);
int32_t stack_adjustment = (CBC_STACK_ADJUST_BASE - (cbc_flags[assign_opcode] >> CBC_STACK_ADJUST_SHIFT));
JERRY_ASSERT (stack_adjustment >= 1 && stack_adjustment <= 3);
rhs_opcode = (uint16_t) (rhs_opcode + stack_adjustment - 1);
}
rhs_opcode = (uint16_t) (rhs_opcode + stack_adjustment - 1);
parser_pattern_emit_rhs (context_p, rhs_opcode, literal_index);
@@ -3366,6 +3363,9 @@ parser_pattern_process_assignment (parser_context_t *context_p, /**< context */
}
else
{
/* RHS should be evaulated first */
parser_pattern_emit_rhs (context_p, rhs_opcode, literal_index);
parser_flush_cbc (context_p);
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA | PARSE_EXPR_LEFT_HAND_SIDE);
@@ -3373,6 +3373,9 @@ parser_pattern_process_assignment (parser_context_t *context_p, /**< context */
{
parser_raise_error (context_p, PARSER_ERR_INVALID_DESTRUCTURING_PATTERN);
}
rhs_opcode = CBC_EXT_MOVE;
literal_index = PARSER_PATTERN_RHS_NO_LIT;
}
parser_pattern_form_assignment (context_p, flags, rhs_opcode, literal_index, ident_line_counter);
@@ -3386,7 +3389,6 @@ parser_parse_array_initializer (parser_context_t *context_p, /**< context */
parser_pattern_flags_t flags) /**< flags */
{
parser_pattern_end_marker_t end_pos = parser_pattern_get_target (context_p, flags);
flags |= PARSER_PATTERN_ARRAY;
lexer_next_token (context_p);
parser_emit_cbc_ext (context_p, CBC_EXT_GET_ITERATOR);