Support comma after last argument for function declarations (#3910)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-06-24 10:41:03 +02:00
committed by GitHub
parent e64fc9aca9
commit 5d8c5f3e92
5 changed files with 146 additions and 66 deletions
+21 -12
View File
@@ -1802,11 +1802,7 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */
while (true)
{
#if ENABLED (JERRY_ESNEXT)
if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM)
{
parser_raise_error (context_p, PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER);
}
else if (context_p->token.type == LEXER_THREE_DOTS)
if (context_p->token.type == LEXER_THREE_DOTS)
{
if (context_p->status_flags & PARSER_IS_PROPERTY_SETTER)
{
@@ -1974,18 +1970,31 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */
if (context_p->token.type != LEXER_COMMA)
{
if (context_p->token.type != end_type)
{
parser_error_t error = ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED
: PARSER_ERR_IDENTIFIER_EXPECTED);
parser_raise_error (context_p, error);
}
break;
}
#if ENABLED (JERRY_ESNEXT)
if (context_p->status_flags & PARSER_FUNCTION_HAS_REST_PARAM)
{
parser_raise_error (context_p, PARSER_ERR_FORMAL_PARAM_AFTER_REST_PARAMETER);
}
#endif /* ENABLED (JERRY_ESNEXT) */
lexer_next_token (context_p);
}
if (context_p->token.type != end_type)
{
parser_error_t error = ((end_type == LEXER_RIGHT_PAREN) ? PARSER_ERR_RIGHT_PAREN_EXPECTED
: PARSER_ERR_IDENTIFIER_EXPECTED);
parser_raise_error (context_p, error);
#if ENABLED (JERRY_ESNEXT)
if (context_p->token.type == end_type)
{
break;
}
#endif /* ENABLED (JERRY_ESNEXT) */
}
scanner_revert_active (context_p);
+51 -38
View File
@@ -182,65 +182,78 @@ scanner_check_arrow_arg (parser_context_t *context_p, /**< context */
lexer_next_token (context_p);
}
if (context_p->token.type == LEXER_LITERAL
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
switch (context_p->token.type)
{
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
if (lexer_check_arrow (context_p))
case LEXER_RIGHT_PAREN:
{
process_arrow = true;
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION_END;
return;
}
else
case LEXER_LITERAL:
{
if (context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
{
break;
}
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
if (lexer_check_arrow (context_p))
{
process_arrow = true;
break;
}
lexer_lit_location_t *argument_literal_p = scanner_append_argument (context_p, scanner_context_p);
scanner_detect_eval_call (context_p, scanner_context_p);
lexer_next_token (context_p);
if (context_p->token.type == LEXER_ASSIGN)
{
if (argument_literal_p->type & SCANNER_LITERAL_IS_USED)
{
JERRY_ASSERT (argument_literal_p->type & SCANNER_LITERAL_EARLY_CREATE);
return;
}
scanner_binding_literal_t binding_literal;
binding_literal.literal_p = argument_literal_p;
parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t));
parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT);
return;
}
if (context_p->token.type == LEXER_COMMA || context_p->token.type == LEXER_RIGHT_PAREN)
{
return;
}
}
}
else if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE)
{
scanner_append_hole (context_p, scanner_context_p);
scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_ARROW_ARG, false);
if (context_p->token.type == LEXER_LEFT_BRACE)
{
parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL);
scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME;
if (context_p->token.type != LEXER_ASSIGN)
{
break;
}
if (argument_literal_p->type & SCANNER_LITERAL_IS_USED)
{
JERRY_ASSERT (argument_literal_p->type & SCANNER_LITERAL_EARLY_CREATE);
return;
}
scanner_binding_literal_t binding_literal;
binding_literal.literal_p = argument_literal_p;
parser_stack_push (context_p, &binding_literal, sizeof (scanner_binding_literal_t));
parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT);
return;
}
case LEXER_LEFT_SQUARE:
case LEXER_LEFT_BRACE:
{
scanner_append_hole (context_p, scanner_context_p);
scanner_push_destructuring_pattern (context_p, scanner_context_p, SCANNER_BINDING_ARROW_ARG, false);
parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL);
scanner_context_p->mode = SCAN_MODE_BINDING;
lexer_next_token (context_p);
return;
if (context_p->token.type == LEXER_LEFT_BRACE)
{
parser_stack_push_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL);
scanner_context_p->mode = SCAN_MODE_PROPERTY_NAME;
return;
}
parser_stack_push_uint8 (context_p, SCAN_STACK_ARRAY_LITERAL);
scanner_context_p->mode = SCAN_MODE_BINDING;
lexer_next_token (context_p);
return;
}
}
scanner_pop_literal_pool (context_p, scanner_context_p);
parser_stack_pop_uint8 (context_p);
if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC)
+26 -14
View File
@@ -2738,20 +2738,15 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
}
case SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS:
{
#endif /* ENABLED (JERRY_ESNEXT) */
if (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS)
{
#if ENABLED (JERRY_ESNEXT)
lexer_lit_location_t *argument_literal_p;
#endif /* ENABLED (JERRY_ESNEXT) */
while (true)
do
{
#if ENABLED (JERRY_ESNEXT)
if (context_p->token.type == LEXER_THREE_DOTS)
{
scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARGUMENTS_UNMAPPED;
lexer_next_token (context_p);
}
@@ -2760,7 +2755,6 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
argument_literal_p = NULL;
break;
}
#endif /* ENABLED (JERRY_ESNEXT) */
if (context_p->token.type != LEXER_LITERAL
|| context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
@@ -2768,22 +2762,18 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
scanner_raise_error (context_p);
}
#if ENABLED (JERRY_ESNEXT)
argument_literal_p = scanner_append_argument (context_p, &scanner_context);
#else /* !ENABLED (JERRY_ESNEXT) */
scanner_append_argument (context_p, &scanner_context);
#endif /* ENABLED (JERRY_ESNEXT) */
lexer_next_token (context_p);
if (context_p->token.type != LEXER_COMMA)
{
break;
}
lexer_next_token (context_p);
}
while (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS);
#if ENABLED (JERRY_ESNEXT)
if (argument_literal_p == NULL)
{
scanner_context.active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARGUMENTS_UNMAPPED;
@@ -2824,8 +2814,30 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
parser_stack_push_uint8 (context_p, SCAN_STACK_BINDING_INIT);
break;
}
#endif /* ENABLED (JERRY_ESNEXT) */
}
#else /* !ENABLED (JERRY_ESNEXT) */
if (context_p->token.type != LEXER_RIGHT_PAREN && context_p->token.type != LEXER_EOS)
{
while (true)
{
if (context_p->token.type != LEXER_LITERAL
|| context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
{
scanner_raise_error (context_p);
}
scanner_append_argument (context_p, &scanner_context);
lexer_next_token (context_p);
if (context_p->token.type != LEXER_COMMA)
{
break;
}
lexer_next_token (context_p);
}
}
#endif /* ENABLED (JERRY_ESNEXT) */
if (context_p->token.type == LEXER_EOS && stack_top == SCAN_STACK_SCRIPT_FUNCTION)
{