Fix function declaration issues inside catch blocks. (#3700)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-04-29 13:53:14 +02:00
committed by GitHub
parent 85401db547
commit 9e6c44be4f
5 changed files with 163 additions and 15 deletions
+1 -1
View File
@@ -218,10 +218,10 @@ typedef enum
SCANNER_BINDING_NONE, /**< not a destructuring binding expression */
SCANNER_BINDING_VAR, /**< destructuring var binding */
SCANNER_BINDING_LET, /**< destructuring let binding */
SCANNER_BINDING_CATCH, /**< destructuring catch binding */
SCANNER_BINDING_CONST, /**< destructuring const binding */
SCANNER_BINDING_ARG, /**< destructuring arg binding */
SCANNER_BINDING_ARROW_ARG, /**< possible destructuring arg binding of an arrow function */
SCANNER_BINDING_CATCH, /**< destructuring catch binding */
} scanner_binding_type_t;
/**
+16 -5
View File
@@ -564,14 +564,23 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
{
no_declarations++;
#if !ENABLED (JERRY_ES2015)
#if ENABLED (JERRY_ES2015)
if ((type & (SCANNER_LITERAL_IS_CONST | SCANNER_LITERAL_IS_ARG)) == SCANNER_LITERAL_IS_CONST)
{
JERRY_ASSERT (type & SCANNER_LITERAL_IS_LET);
/* Catch parameters cannot be functions. */
literal_p->type = (uint8_t) (type & ~SCANNER_LITERAL_IS_FUNC);
no_declarations--;
}
#else /* !ENABLED (JERRY_ES2015) */
if (type & SCANNER_LITERAL_IS_LOCAL)
{
/* Catch parameters cannot be functions. */
literal_p->type = (uint8_t) (type & ~SCANNER_LITERAL_IS_FUNC);
no_declarations--;
}
#endif /* !ENABLED (JERRY_ES2015) */
#endif /* ENABLED (JERRY_ES2015) */
}
intptr_t diff = (intptr_t) (literal_p->char_p - prev_source_p);
@@ -617,12 +626,14 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
#if ENABLED (JERRY_ES2015)
extended_type |= SCANNER_LITERAL_IS_USED;
const uint8_t mask = (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_LOCAL);
if ((type & SCANNER_LITERAL_IS_ARG)
|| (!(literal_location_p->type & SCANNER_LITERAL_IS_ARG)
&& (literal_location_p->type & SCANNER_LITERAL_IS_LOCAL)))
|| (literal_location_p->type & mask) == SCANNER_LITERAL_IS_LET
|| (literal_location_p->type & mask) == SCANNER_LITERAL_IS_CONST)
{
/* Clears the SCANNER_LITERAL_IS_VAR and SCANNER_LITERAL_IS_FUNC flags
* for speculative arrow paramters and local (non-var) functions. */
* for speculative arrow parameters and local (non-var) functions. */
type = 0;
}
#endif /* ENABLED (JERRY_ES2015) */
+11 -9
View File
@@ -1397,8 +1397,11 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p);
#if ENABLED (JERRY_ES2015)
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
&& !(literal_p->type & (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_ARG)))
const uint8_t mask = (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LOCAL);
if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL)
&& (literal_p->type & mask) != (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG)
&& (literal_p->type & mask) != (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
{
scanner_raise_redeclaration_error (context_p);
}
@@ -2970,10 +2973,10 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
{
JERRY_ASSERT (scanner_context.binding_type == SCANNER_BINDING_VAR
|| scanner_context.binding_type == SCANNER_BINDING_LET
|| scanner_context.binding_type == SCANNER_BINDING_CATCH
|| scanner_context.binding_type == SCANNER_BINDING_CONST
|| scanner_context.binding_type == SCANNER_BINDING_ARG
|| scanner_context.binding_type == SCANNER_BINDING_ARROW_ARG
|| scanner_context.binding_type == SCANNER_BINDING_CATCH);
|| scanner_context.binding_type == SCANNER_BINDING_ARROW_ARG);
if (type == LEXER_THREE_DOTS)
{
@@ -3035,14 +3038,13 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
{
scanner_detect_invalid_let (context_p, literal_p);
if (scanner_context.binding_type == SCANNER_BINDING_LET)
if (scanner_context.binding_type <= SCANNER_BINDING_CATCH)
{
JERRY_ASSERT ((scanner_context.binding_type == SCANNER_BINDING_LET)
|| (scanner_context.binding_type == SCANNER_BINDING_CATCH));
literal_p->type |= SCANNER_LITERAL_IS_LET;
}
else if (scanner_context.binding_type == SCANNER_BINDING_CATCH)
{
literal_p->type |= SCANNER_LITERAL_IS_LOCAL;
}
else
{
literal_p->type |= SCANNER_LITERAL_IS_CONST;