- Revision
- 196545
- Author
- [email protected]
- Date
- 2016-02-12 20:52:01 -0800 (Fri, 12 Feb 2016)
Log Message
[ES6] we have an incorrect syntax error when a callee of a function _expression_ has the same name as a top-level lexical declaration
https://bugs.webkit.org/show_bug.cgi?id=154143
Reviewed by Benjamin Poulain.
Source/_javascript_Core:
We were raising syntax errors on the following type of programs when
we shouldn't have been.
```
(function foo() { const foo = 20; });
```
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseFunctionInfo):
* parser/Parser.h:
(JSC::Scope::computeLexicallyCapturedVariablesAndPurgeCandidates):
(JSC::Scope::declareCallee):
(JSC::Scope::declareVariable):
(JSC::Scope::hasDeclaredVariable):
(JSC::Scope::hasLexicallyDeclaredVariable):
(JSC::Scope::hasDeclaredParameter):
(JSC::Scope::declareWrite):
(JSC::Scope::getCapturedVars):
LayoutTests:
* js/basic-strict-mode-expected.txt:
* js/let-syntax-expected.txt:
* js/script-tests/let-syntax.js:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (196544 => 196545)
--- trunk/LayoutTests/ChangeLog 2016-02-13 04:48:40 UTC (rev 196544)
+++ trunk/LayoutTests/ChangeLog 2016-02-13 04:52:01 UTC (rev 196545)
@@ -1,3 +1,14 @@
+2016-02-12 Saam barati <[email protected]>
+
+ [ES6] we have an incorrect syntax error when a callee of a function _expression_ has the same name as a top-level lexical declaration
+ https://bugs.webkit.org/show_bug.cgi?id=154143
+
+ Reviewed by Benjamin Poulain.
+
+ * js/basic-strict-mode-expected.txt:
+ * js/let-syntax-expected.txt:
+ * js/script-tests/let-syntax.js:
+
2016-02-12 Jiewen Tan <[email protected]>
Unreviewed, build fix after r196520
Modified: trunk/LayoutTests/js/basic-strict-mode-expected.txt (196544 => 196545)
--- trunk/LayoutTests/js/basic-strict-mode-expected.txt 2016-02-13 04:48:40 UTC (rev 196544)
+++ trunk/LayoutTests/js/basic-strict-mode-expected.txt 2016-02-13 04:52:01 UTC (rev 196545)
@@ -30,14 +30,14 @@
PASS testThis.apply() is undefined
PASS testThis.call(undefined) is undefined
PASS testThis.apply(undefined) is undefined
-PASS (function eval(){'use strict';}) threw exception SyntaxError: Cannot declare a variable named 'eval' in strict mode..
-PASS (function(){(function eval(){'use strict';})}) threw exception SyntaxError: Cannot declare a variable named 'eval' in strict mode..
-PASS (function (eval){'use strict';}) threw exception SyntaxError: Cannot declare a variable named 'eval' in strict mode..
-PASS (function(){(function (eval){'use strict';})}) threw exception SyntaxError: Cannot declare a variable named 'eval' in strict mode..
-PASS (function arguments(){'use strict';}) threw exception SyntaxError: Cannot declare a variable named 'arguments' in strict mode..
-PASS (function(){(function arguments(){'use strict';})}) threw exception SyntaxError: Cannot declare a variable named 'arguments' in strict mode..
-PASS (function (arguments){'use strict';}) threw exception SyntaxError: Cannot declare a variable named 'arguments' in strict mode..
-PASS (function(){(function (arguments){'use strict';})}) threw exception SyntaxError: Cannot declare a variable named 'arguments' in strict mode..
+PASS (function eval(){'use strict';}) threw exception SyntaxError: 'eval' is not a valid function name in strict mode..
+PASS (function(){(function eval(){'use strict';})}) threw exception SyntaxError: 'eval' is not a valid function name in strict mode..
+PASS (function (eval){'use strict';}) threw exception SyntaxError: Invalid parameters or function name in strict mode..
+PASS (function(){(function (eval){'use strict';})}) threw exception SyntaxError: Invalid parameters or function name in strict mode..
+PASS (function arguments(){'use strict';}) threw exception SyntaxError: 'arguments' is not a valid function name in strict mode..
+PASS (function(){(function arguments(){'use strict';})}) threw exception SyntaxError: 'arguments' is not a valid function name in strict mode..
+PASS (function (arguments){'use strict';}) threw exception SyntaxError: Invalid parameters or function name in strict mode..
+PASS (function(){(function (arguments){'use strict';})}) threw exception SyntaxError: Invalid parameters or function name in strict mode..
PASS (function (){'use strict'; var eval;}) threw exception SyntaxError: Cannot declare a variable named eval in strict mode..
PASS (function(){(function (){'use strict'; var eval;})}) threw exception SyntaxError: Cannot declare a variable named eval in strict mode..
PASS (function (){'use strict'; var arguments;}) threw exception SyntaxError: Cannot declare a variable named arguments in strict mode..
Modified: trunk/LayoutTests/js/let-syntax-expected.txt (196544 => 196545)
--- trunk/LayoutTests/js/let-syntax-expected.txt 2016-02-13 04:48:40 UTC (rev 196544)
+++ trunk/LayoutTests/js/let-syntax-expected.txt 2016-02-13 04:52:01 UTC (rev 196545)
@@ -33,6 +33,42 @@
PASS Does not have syntax error: ''use strict'; ;({ get let() { return 50; }, set let(x) { return 50;} });'
PASS Does not have syntax error: 'function foo() { { let x; } var x; }'
PASS Does not have syntax error: ''use strict'; function foo() { { let x; } var x; }'
+PASS Does not have syntax error: 'var x = (function foo() { const foo = 20; });'
+PASS Does not have syntax error: ''use strict'; var x = (function foo() { const foo = 20; });'
+PASS Does not have syntax error: 'var x = (function foo() { let foo = 20; });'
+PASS Does not have syntax error: ''use strict'; var x = (function foo() { let foo = 20; });'
+PASS Does not have syntax error: 'var x = (function foo() { class foo { } });'
+PASS Does not have syntax error: ''use strict'; var x = (function foo() { class foo { } });'
+PASS Does not have syntax error: ';(function foo() { const foo = 20; });'
+PASS Does not have syntax error: ''use strict'; ;(function foo() { const foo = 20; });'
+PASS Does not have syntax error: ';(function foo() { let foo = 20; });'
+PASS Does not have syntax error: ''use strict'; ;(function foo() { let foo = 20; });'
+PASS Does not have syntax error: ';(function foo() { class foo { } });'
+PASS Does not have syntax error: ''use strict'; ;(function foo() { class foo { } });'
+PASS Does not have syntax error: 'let x = {f: function foo() { const foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = {f: function foo() { const foo = 20; } };'
+PASS Does not have syntax error: 'let x = {f: function foo() { let foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = {f: function foo() { let foo = 20; } };'
+PASS Does not have syntax error: 'let x = {f: function foo() { class foo { } } };'
+PASS Does not have syntax error: ''use strict'; let x = {f: function foo() { class foo { } } };'
+PASS Does not have syntax error: 'let x = { foo() { const foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = { foo() { const foo = 20; } };'
+PASS Does not have syntax error: 'let x = { foo() { let foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = { foo() { let foo = 20; } };'
+PASS Does not have syntax error: 'let x = { foo() { class foo { } } };'
+PASS Does not have syntax error: ''use strict'; let x = { foo() { class foo { } } };'
+PASS Does not have syntax error: 'let x = { set foo(x) { const foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = { set foo(x) { const foo = 20; } };'
+PASS Does not have syntax error: 'let x = { set foo(x) { let foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = { set foo(x) { let foo = 20; } };'
+PASS Does not have syntax error: 'let x = { set foo(x) { class foo { } } };'
+PASS Does not have syntax error: ''use strict'; let x = { set foo(x) { class foo { } } };'
+PASS Does not have syntax error: 'let x = { get foo() { const foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = { get foo() { const foo = 20; } };'
+PASS Does not have syntax error: 'let x = { get foo() { let foo = 20; } };'
+PASS Does not have syntax error: ''use strict'; let x = { get foo() { let foo = 20; } };'
+PASS Does not have syntax error: 'let x = { get foo() { class foo { } } };'
+PASS Does not have syntax error: ''use strict'; let x = { get foo() { class foo { } } };'
SyntaxError: Unexpected keyword 'let'. Can't use 'let' as an identifier name for a LexicalDeclaration.
SyntaxError: Unexpected keyword 'let'. Can't use 'let' as an identifier name for a LexicalDeclaration.
PASS Has syntax error: 'let let;'
Modified: trunk/LayoutTests/js/script-tests/let-syntax.js (196544 => 196545)
--- trunk/LayoutTests/js/script-tests/let-syntax.js 2016-02-13 04:48:40 UTC (rev 196544)
+++ trunk/LayoutTests/js/script-tests/let-syntax.js 2016-02-13 04:52:01 UTC (rev 196545)
@@ -68,6 +68,24 @@
shouldNotHaveSyntaxError("function foo() { var bar; if (truth()) { let bar; } }");
shouldNotHaveSyntaxError(";({ get let() { return 50; }, set let(x) { return 50;} });");
shouldNotHaveSyntaxError("function foo() { { let x; } var x; }");
+shouldNotHaveSyntaxError("var x = (function foo() { const foo = 20; });");
+shouldNotHaveSyntaxError("var x = (function foo() { let foo = 20; });");
+shouldNotHaveSyntaxError("var x = (function foo() { class foo { } });");
+shouldNotHaveSyntaxError(";(function foo() { const foo = 20; });");
+shouldNotHaveSyntaxError(";(function foo() { let foo = 20; });");
+shouldNotHaveSyntaxError(";(function foo() { class foo { } });");
+shouldNotHaveSyntaxError("let x = {f: function foo() { const foo = 20; } };");
+shouldNotHaveSyntaxError("let x = {f: function foo() { let foo = 20; } };");
+shouldNotHaveSyntaxError("let x = {f: function foo() { class foo { } } };");
+shouldNotHaveSyntaxError("let x = { foo() { const foo = 20; } };");
+shouldNotHaveSyntaxError("let x = { foo() { let foo = 20; } };");
+shouldNotHaveSyntaxError("let x = { foo() { class foo { } } };");
+shouldNotHaveSyntaxError("let x = { set foo(x) { const foo = 20; } };");
+shouldNotHaveSyntaxError("let x = { set foo(x) { let foo = 20; } };");
+shouldNotHaveSyntaxError("let x = { set foo(x) { class foo { } } };");
+shouldNotHaveSyntaxError("let x = { get foo() { const foo = 20; } };");
+shouldNotHaveSyntaxError("let x = { get foo() { let foo = 20; } };");
+shouldNotHaveSyntaxError("let x = { get foo() { class foo { } } };");
shouldHaveSyntaxError("let let;");
shouldHaveSyntaxError("const let;");
Modified: trunk/Source/_javascript_Core/ChangeLog (196544 => 196545)
--- trunk/Source/_javascript_Core/ChangeLog 2016-02-13 04:48:40 UTC (rev 196544)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-02-13 04:52:01 UTC (rev 196545)
@@ -1,3 +1,28 @@
+2016-02-12 Saam barati <[email protected]>
+
+ [ES6] we have an incorrect syntax error when a callee of a function _expression_ has the same name as a top-level lexical declaration
+ https://bugs.webkit.org/show_bug.cgi?id=154143
+
+ Reviewed by Benjamin Poulain.
+
+ We were raising syntax errors on the following type of programs when
+ we shouldn't have been.
+ ```
+ (function foo() { const foo = 20; });
+ ```
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseFunctionInfo):
+ * parser/Parser.h:
+ (JSC::Scope::computeLexicallyCapturedVariablesAndPurgeCandidates):
+ (JSC::Scope::declareCallee):
+ (JSC::Scope::declareVariable):
+ (JSC::Scope::hasDeclaredVariable):
+ (JSC::Scope::hasLexicallyDeclaredVariable):
+ (JSC::Scope::hasDeclaredParameter):
+ (JSC::Scope::declareWrite):
+ (JSC::Scope::getCapturedVars):
+
2016-02-12 Benjamin Poulain <[email protected]>
[JSC] ZeroExtend and SignExtend use incorrect addressing on ARM64
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (196544 => 196545)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2016-02-13 04:48:40 UTC (rev 196544)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2016-02-13 04:52:01 UTC (rev 196545)
@@ -1932,7 +1932,7 @@
m_parserState.lastFunctionName = functionInfo.name;
next();
if (!nameIsInContainingScope)
- failIfTrueIfStrict(functionScope->declareVariable(functionInfo.name) & DeclarationResult::InvalidStrictMode, "'", functionInfo.name->impl(), "' is not a valid ", stringForFunctionMode(mode), " name in strict mode");
+ failIfTrueIfStrict(functionScope->declareCallee(functionInfo.name) & DeclarationResult::InvalidStrictMode, "'", functionInfo.name->impl(), "' is not a valid ", stringForFunctionMode(mode), " name in strict mode");
} else if (requirements == FunctionNeedsName) {
if (match(OPENPAREN) && mode == SourceParseMode::NormalFunctionMode)
semanticFail("Function statements must have a name");
Modified: trunk/Source/_javascript_Core/parser/Parser.h (196544 => 196545)
--- trunk/Source/_javascript_Core/parser/Parser.h 2016-02-13 04:48:40 UTC (rev 196544)
+++ trunk/Source/_javascript_Core/parser/Parser.h 2016-02-13 04:52:01 UTC (rev 196545)
@@ -333,12 +333,17 @@
}
}
- void declareCallee(const Identifier* ident)
+ DeclarationResultMask declareCallee(const Identifier* ident)
{
auto addResult = m_declaredVariables.add(ident->impl());
// We want to track if callee is captured, but we don't want to act like it's a 'var'
// because that would cause the BytecodeGenerator to emit bad code.
addResult.iterator->value.clearIsVar();
+
+ DeclarationResultMask result = DeclarationResult::Valid;
+ if (isEvalOrArgumentsIdentifier(m_vm, ident))
+ result |= DeclarationResult::InvalidStrictMode;
+ return result;
}
DeclarationResultMask declareVariable(const Identifier* ident)
@@ -390,7 +395,11 @@
bool hasDeclaredVariable(const RefPtr<UniquedStringImpl>& ident)
{
- return m_declaredVariables.contains(ident.get());
+ auto iter = m_declaredVariables.find(ident.get());
+ if (iter == m_declaredVariables.end())
+ return false;
+ VariableEnvironmentEntry entry = iter->value;
+ return entry.isVar(); // The callee isn't a "var".
}
bool hasLexicallyDeclaredVariable(const RefPtr<UniquedStringImpl>& ident) const
@@ -405,7 +414,7 @@
bool hasDeclaredParameter(const RefPtr<UniquedStringImpl>& ident)
{
- return m_declaredParameters.contains(ident) || m_declaredVariables.contains(ident.get());
+ return m_declaredParameters.contains(ident) || hasDeclaredVariable(ident);
}
void declareWrite(const Identifier* ident)
@@ -518,7 +527,8 @@
return;
}
for (IdentifierSet::iterator ptr = m_closedVariableCandidates.begin(); ptr != m_closedVariableCandidates.end(); ++ptr) {
- if (!m_declaredVariables.contains(*ptr))
+ // We refer to m_declaredVariables here directly instead of a hasDeclaredVariable because we want to mark the callee as captured.
+ if (!m_declaredVariables.contains(*ptr))
continue;
capturedVariables.add(*ptr);
}