Skip to content

SyntaxError on statement without body#6854

Merged
rhuanjl merged 5 commits intochakra-core:masterfrom
ShortDevelopment:syntax-error-missing-block-statement
Oct 15, 2022
Merged

SyntaxError on statement without body#6854
rhuanjl merged 5 commits intochakra-core:masterfrom
ShortDevelopment:syntax-error-missing-block-statement

Conversation

@ShortDevelopment
Copy link
Copy Markdown
Contributor

According to the Rules of Automatic Semicolon Insertion:

a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement

Therefore, a poc like in #6351 should throw (inside eval and outside).
But CC didn't handle the (unexpected) "end of the input stream" as a SyntaxError.
This applies to if, for, while, do, ...


The parser retrieves the body of such a statement like so:

ParseNodePtr pnodeBody = ParseStatement<buildAST>();

The tkEOF case (inside Parser::ParseStatement) is only hit, if it is unexpected:

ChakraCore/lib/Parser/Parse.cpp

Lines 10169 to 10180 in 0a9c082

switch (tok)
{
case tkEOF:
if (labelledStatement)
{
Error(ERRLabelFollowedByEOF);
}
if (buildAST)
{
pnode = nullptr;
}
break;

In such a case, CC should always throw, even if labelledStatement == false.


@rhuanjl

Fix #6351
Fix #6553 (Closed as duplicate)
Fix #5128

Report to tc39: tc39/test262#2661

@rhuanjl rhuanjl merged commit 0cfe82d into chakra-core:master Oct 15, 2022
@ShortDevelopment ShortDevelopment deleted the syntax-error-missing-block-statement branch October 15, 2022 11:22
@ShortDevelopment ShortDevelopment restored the syntax-error-missing-block-statement branch October 15, 2022 11:22
@ShortDevelopment ShortDevelopment deleted the syntax-error-missing-block-statement branch October 15, 2022 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants