Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JSC]
let [
sequence cannot appear in ExpressionStatement context
https://bugs.webkit.org/show_bug.cgi?id=215977 Reviewed by Ross Kirsling. JSTests: * stress/let-and-open-bracket.js: Added. (testSyntax): (testSyntaxError): * test262/expectations.yaml: Source/JavaScriptCore: Because of ambiguity between destructuring assignment and member access (let IDENTIFIER), ECMA262 does not allow `let [` sequence in ExpressionStatement context[1]. We should throw SyntaxError when we see something like this. if (false) let [ok] = [42]; [1]: https://tc39.es/ecma262/#sec-expression-statement * parser/Parser.cpp: (JSC::Parser<LexerType>::parseStatement): Canonical link: https://commits.webkit.org/228763@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266327 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
41c992a
commit d116fc7
Showing
5 changed files
with
73 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function testSyntax(script) { | ||
try { | ||
eval(script); | ||
} catch (error) { | ||
if (error instanceof SyntaxError) | ||
throw new Error("Bad error: " + String(error)); | ||
} | ||
} | ||
|
||
function testSyntaxError(script, message) { | ||
var error = null; | ||
try { | ||
eval(script); | ||
} catch (e) { | ||
error = e; | ||
} | ||
if (!error) | ||
throw new Error("Expected syntax error not thrown"); | ||
|
||
if (String(error) !== message) | ||
throw new Error("Bad error: " + String(error)); | ||
} | ||
|
||
testSyntaxError(` | ||
if (false) let [ok] = 40; | ||
`, `SyntaxError: Unexpected token '['. Cannot use lexical declaration in single-statement context.`); | ||
|
||
testSyntaxError(` | ||
if (false) let | ||
[ok] = 40; | ||
`, `SyntaxError: Unexpected token '['. Cannot use lexical declaration in single-statement context.`); | ||
|
||
testSyntax(` | ||
if (false) { | ||
let [ok] = 40; | ||
} | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters