Check rest initializer existence after pattern finalization (#4950)

Since the scanner info is not present for invalid destructuring patterns we can only ensure the existence of the rest element after the pattern is finalized.
This patch fixes #4928.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
Robert Fancsik
2022-01-14 10:15:48 +01:00
committed by GitHub
parent 799583e5c8
commit 47d025c74f
2 changed files with 32 additions and 2 deletions
+12 -2
View File
@@ -4072,6 +4072,10 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
return;
}
#ifndef JERRY_NDEBUG
bool rest_found = false;
#endif /* !defined(JERRY_NDEBUG) */
cbc_ext_opcode_t context_opcode = CBC_EXT_OBJ_INIT_CONTEXT_CREATE;
if (flags & PARSER_PATTERN_HAS_REST_ELEMENT)
@@ -4115,8 +4119,9 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED);
}
/* Checked at the end because there might be syntax errors before. */
JERRY_ASSERT (flags & PARSER_PATTERN_HAS_REST_ELEMENT);
#ifndef JERRY_NDEBUG
rest_found = true;
#endif /* !defined(JERRY_NDEBUG) */
break;
}
@@ -4203,6 +4208,11 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
parser_emit_cbc_ext (context_p, CBC_EXT_OBJ_INIT_CONTEXT_END);
parser_pattern_finalize (context_p, flags, &end_pos);
#ifndef JERRY_NDEBUG
/* Checked at the end because there might be syntax errors before. */
JERRY_ASSERT (!!(flags & PARSER_PATTERN_HAS_REST_ELEMENT) == rest_found);
#endif /* !defined(JERRY_NDEBUG) */
} /* parser_parse_object_initializer */
/**