Skip to content
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

Chakra should throw an exception when evaluate an invalid "for" statement #5128

Closed
igor-simoes opened this issue May 10, 2018 · 4 comments · Fixed by #6854
Closed

Chakra should throw an exception when evaluate an invalid "for" statement #5128

igor-simoes opened this issue May 10, 2018 · 4 comments · Fixed by #6854

Comments

@igor-simoes
Copy link

igor-simoes commented May 10, 2018

Hi everyone,
I found an inconsistency when try to evaluate a "for" statement without the body statement.

OS: Ubuntu 16.04 x64
Chakra: 1.10.0.0-beta

Step to reproduce:

first = "for (i = 0; i < 3; i++);"
print (eval ( first ) )

second = "for (i = 0; i < 3; i++)"
print (eval ( second ) )

Actual results:

undefined
undefined

Expected results:

undefined
SyntaxError: Unexpected end of input

I ran the second statement without eval function and Chakra passes without throw an Exception also.

for (i = 0; i < 3; i++)

V8, SpiderMonkey and JavascriptCore works as expected.

cinfuzz

@fatcerberus
Copy link
Contributor

Sounds like overzealous ASI.

@infinnie
Copy link

Reproduced on Edge.
OS: Windows
User agent:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134

@rhuanjl
Copy link
Collaborator

rhuanjl commented May 17, 2018

Was thinking of trying to fix this but first I took a quick look at it with eshost:
Firstly without eval none of the 4 throw an error:

# Source
for(var i = 0; i < 10; ++i)

#### Chakra, JavaScriptCore, SpiderMonkey, V8 --harmony

Then with eval CC still throws no error but the others do throw errors:

## Source
eval("for(var i = 0; i < 10; ++i)");

#### Chakra


#### V8 --harmony
SyntaxError: Unexpected end of input

#### SpiderMonkey
SyntaxError: expected expression, got end of script:

#### JavaScriptCore
SyntaxError: Unexpected end of script

It seems that with no eval present all 4 engines happily apply ASI whereas without an eval only CC applies ASI - IMO CC's behaviour seems more logical than the other 3 engines here. I don't know the correct answer per spec though; but for now I won't try to submit a "fix" as not confident that current behaviour is wrong.

@fatcerberus
Copy link
Contributor

I don’t think ASI should apply here at all: if you put the offending code into a function block then all engines will produce a syntax error.

@liminzhu liminzhu added this to the vNext milestone Jun 5, 2018
rhuanjl pushed a commit that referenced this issue Oct 15, 2022
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"

Fix #6351
Fix #6553 (Closed as duplicate)
Fix #5128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants