Fix block-scoped var/function redeclarations (#4080)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai
2020-07-31 17:43:15 +02:00
committed by GitHub
parent 84125275ea
commit 26a299adf0
5 changed files with 77 additions and 31 deletions
+12
View File
@@ -1382,6 +1382,14 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
}
scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p;
if (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK
&& (var_literal_p->type & (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
== (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
{
scanner_raise_redeclaration_error (context_p);
}
const uint8_t *char_p = var_literal_p->char_p;
prop_length_t length = var_literal_p->length;
@@ -1399,6 +1407,8 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
{
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
&& !(literal_p->type & SCANNER_LITERAL_IS_ARG)
&& !((literal_p->type & SCANNER_LITERAL_IS_FUNC)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK) == 0)
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
&& literal_p->length == length)
{
@@ -1424,6 +1434,8 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
{
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
&& !(literal_p->type & SCANNER_LITERAL_IS_ARG)
&& !((literal_p->type & SCANNER_LITERAL_IS_FUNC)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK) == 0)
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
&& lexer_compare_identifiers (context_p, literal_p, var_literal_p))
{
+8
View File
@@ -1438,6 +1438,14 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
scanner_raise_redeclaration_error (context_p);
}
scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p;
if (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK
&& (literal_p->type & (SCANNER_LITERAL_IS_VAR)))
{
scanner_raise_redeclaration_error (context_p);
}
literal_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION;
scanner_context_p->status_flags &= (uint16_t) ~SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION;