Skip to content

Fix parsing function statements containing invalid tokens #3838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dbatyai
Copy link
Member

@dbatyai dbatyai commented Jun 3, 2020

Fixes #3821.

@dbatyai dbatyai added bug Undesired behaviour pre-scanner Related to the JavaScript pre-scanner labels Jun 3, 2020
@dbatyai dbatyai requested review from zherczeg and rerobika June 3, 2020 12:06
Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the problem is there is no scanner info. Just detect that it is not available and do nothing. There is an assert somewhere for "there must be a parse error later", that can be set. Maybe it is specialized for for statements, but can be extended to cover more cases.

@@ -710,9 +710,8 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);

#if ENABLED (JERRY_ES2015)
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way it should work. If you check the type, but not the source_p, it might refer to something detected later in the source code.

@@ -1418,6 +1418,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
#endif /* ENABLED (JERRY_ES2015) */

scanner_push_literal_pool (context_p, scanner_context_p, status_flags);
scanner_context_p->active_literal_pool_p->source_p = context_p->source_p;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function arguments should set this.

@dbatyai dbatyai force-pushed the func_stmt_invalid_token branch 2 times, most recently from 97b04cc to 8c316c7 Compare June 3, 2020 13:11
Copy link
Contributor

@ossy-szeged ossy-szeged left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: parsig -> parsing

@dbatyai dbatyai force-pushed the func_stmt_invalid_token branch from 8c316c7 to 6effd1c Compare June 3, 2020 13:34
@dbatyai dbatyai changed the title Fix parsig function statements containing invalid tokens Fix parsing function statements containing invalid tokens Jun 3, 2020
@@ -730,7 +730,10 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
status_flags |= PARSER_HAS_NON_STRICT_ARG;
}

JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION);
if (context_p->next_scanner_info_p->type != SCANNER_TYPE_FUNCTION)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which test triggers this? At this point the ( should be parsed where the scanner info is attached to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is early. Perhaps simply removing this assertion is enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be triggered by function a"b. The scanner will call lexer_next_token to consume the left paren, however the unterminated string literal will throw. Since the scanner info would be created after consuming the opening paren, there will be no scanner info for the function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. I think this assert is unnecessary, since no info is created if there will be a parse error before the (. I think there is another assert later which should cover this as well.

@dbatyai dbatyai force-pushed the func_stmt_invalid_token branch from 6effd1c to 14dd68a Compare June 3, 2020 14:23
Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@rerobika rerobika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rerobika rerobika requested a review from ossy-szeged June 4, 2020 09:08
Copy link
Contributor

@ossy-szeged ossy-szeged left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (informal)

@rerobika rerobika merged commit 1322e08 into jerryscript-project:master Jun 4, 2020
@dbatyai dbatyai deleted the func_stmt_invalid_token branch June 10, 2020 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Undesired behaviour pre-scanner Related to the JavaScript pre-scanner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion 'context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION' in parser_parse_function_statement
4 participants