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:
@@ -27,7 +27,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)
|
||||
*/
|
||||
JERRY_STATIC_ASSERT (CBC_END == 238,
|
||||
number_of_cbc_opcodes_changed);
|
||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 136,
|
||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 135,
|
||||
number_of_cbc_ext_opcodes_changed);
|
||||
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
|
||||
@@ -724,24 +724,22 @@
|
||||
VM_OC_APPEND_ARRAY) \
|
||||
CBC_OPCODE (CBC_EXT_REST_INITIALIZER, CBC_NO_FLAG, 1, \
|
||||
VM_OC_REST_INITIALIZER) \
|
||||
CBC_OPCODE (CBC_EXT_REST_INITIALIZER_2, CBC_NO_FLAG, 1, \
|
||||
VM_OC_REST_INITIALIZER) \
|
||||
CBC_OPCODE (CBC_EXT_REST_INITIALIZER_3, CBC_NO_FLAG, 1, \
|
||||
VM_OC_REST_INITIALIZER) \
|
||||
CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, \
|
||||
VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_SPREAD_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
|
||||
VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_MOVE, CBC_NO_FLAG, 0, \
|
||||
VM_OC_MOVE) \
|
||||
CBC_OPCODE (CBC_EXT_MOVE_2, CBC_NO_FLAG, 0, \
|
||||
VM_OC_MOVE) \
|
||||
CBC_OPCODE (CBC_EXT_MOVE_3, CBC_NO_FLAG, 0, \
|
||||
VM_OC_MOVE) \
|
||||
\
|
||||
/* Iterator related opcodes. */ \
|
||||
CBC_OPCODE (CBC_EXT_GET_ITERATOR, CBC_NO_FLAG, 1, \
|
||||
VM_OC_GET_ITERATOR) \
|
||||
CBC_OPCODE (CBC_EXT_ITERATOR_STEP, CBC_NO_FLAG, 1, \
|
||||
VM_OC_ITERATOR_STEP) \
|
||||
CBC_OPCODE (CBC_EXT_ITERATOR_STEP_2, CBC_NO_FLAG, 1, \
|
||||
VM_OC_ITERATOR_STEP) \
|
||||
CBC_OPCODE (CBC_EXT_ITERATOR_STEP_3, CBC_NO_FLAG, 1, \
|
||||
VM_OC_ITERATOR_STEP) \
|
||||
CBC_OPCODE (CBC_EXT_ITERATOR_CLOSE, CBC_NO_FLAG, -1, \
|
||||
VM_OC_ITERATOR_CLOSE | VM_OC_GET_STACK) \
|
||||
\
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -115,7 +115,6 @@ typedef enum
|
||||
PARSER_PATTERN_LOCAL = (1u << 6), /**< pattern is a local (catch parameter) declaration */
|
||||
PARSER_PATTERN_REST_ELEMENT = (1u << 7), /**< parse rest array initializer */
|
||||
PARSER_PATTERN_ARGUMENTS = (1u << 8), /**< parse arguments binding */
|
||||
PARSER_PATTERN_ARRAY = (1u << 9), /**< array pattern is being parsed */
|
||||
} parser_pattern_flags_t;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user