We incorrectly throw a syntax error when declaring a top level for-loop iteration...
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 May 2017 05:47:33 +0000 (05:47 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 May 2017 05:47:33 +0000 (05:47 +0000)
commitba6f353e8e17270f59e127a5baeeb02ec8695e6f
tree96c943dbaa2f0ba897a4854c5d7d529c485cd35c
parent1456b250afaf30d1e951872637ddb9221b4c4337
We incorrectly throw a syntax error when declaring a top level for-loop iteration variable the same as a parameter
https://bugs.webkit.org/show_bug.cgi?id=171041
<rdar://problem/32082516>

Reviewed by Yusuke Suzuki.

JSTests:

* stress/lexical-scoping-for-loop.js: Added.
(assert):
(test1):
(test2):
(test3):
(test4):
(test5):
(test6):
(let.test7):
(let.test8):
(let.test9):
(let.test10):
(let.test11):
(let.test12):

Source/JavaScriptCore:

We were treating a for-loop variable declaration potentially as a top
level statement, e.g, in a program like this:
```
function foo() {
    for (let variable of expr) { }
}
```
But we should not be. This had the consequence of making this type of program
throw a syntax error:
```
function foo(arg) {
    for (let arg of expr) { }
}
```
even though it should not. The fix is simple, we just need to increment the
statement depth before parsing anything inside the for loop.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseForStatement):

LayoutTests:

* js/parser-syntax-check-expected.txt:
* js/script-tests/parser-syntax-check.js:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@217200 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JSTests/ChangeLog
JSTests/stress/lexical-scoping-for-loop.js [new file with mode: 0644]
LayoutTests/ChangeLog
LayoutTests/js/parser-syntax-check-expected.txt
LayoutTests/js/script-tests/parser-syntax-check.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/parser/Parser.cpp