Changeset 258861 in webkit
- Timestamp:
- Mar 23, 2020 11:23:50 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r258801 r258861 1 2020-03-23 Ross Kirsling <ross.kirsling@sony.com> 2 3 Catch parameters must not be lexically redeclared 4 https://bugs.webkit.org/show_bug.cgi?id=208976 5 6 Reviewed by Keith Miller. 7 8 * test262/expectations.yaml: 9 Mark four test cases as passing. 10 1 11 2020-03-20 Ross Kirsling <ross.kirsling@sony.com> 2 12 -
trunk/JSTests/test262/expectations.yaml
r258801 r258861 3680 3680 default: 'Test262: This statement should not be evaluated.' 3681 3681 strict mode: 'Test262: This statement should not be evaluated.' 3682 test/language/statements/try/early-catch-function.js:3683 default: 'Test262: This statement should not be evaluated.'3684 strict mode: 'Test262: This statement should not be evaluated.'3685 test/language/statements/try/early-catch-lex.js:3686 default: 'Test262: This statement should not be evaluated.'3687 strict mode: 'Test262: This statement should not be evaluated.'3688 3682 test/language/statements/while/let-array-with-newline.js: 3689 3683 default: 'Test262: This statement should not be evaluated.' -
trunk/Source/JavaScriptCore/ChangeLog
r258857 r258861 1 2020-03-23 Ross Kirsling <ross.kirsling@sony.com> 2 3 Catch parameters must not be lexically redeclared 4 https://bugs.webkit.org/show_bug.cgi?id=208976 5 6 Reviewed by Keith Miller. 7 8 From https://tc39.es/ecma262/#sec-try-statement-static-semantics-early-errors: 9 Catch : catch ( CatchParameter ) Block 10 It is a Syntax Error if any element of the BoundNames of CatchParameter 11 also occurs in the LexicallyDeclaredNames of Block. 12 13 In other words, let/const/class/function declarations in the immediate catch block scope 14 must not shadow catch parameters. 15 16 * parser/Parser.cpp: 17 (JSC::Parser<LexerType>::parseTryStatement): 18 (JSC::Parser<LexerType>::parseBlockStatement): 19 * parser/Parser.h: 20 (JSC::Scope::Scope): 21 (JSC::Scope::setIsCatchBlockScope): Added. 22 (JSC::Scope::isCatchBlockScope): Added. 23 (JSC::Parser::declareVariable): 24 (JSC::Parser::declareFunction): 25 1 26 2020-03-23 Michael Catanzaro <mcatanzaro@gnome.org> 2 27 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r258531 r258861 1780 1780 handleProductionOrFail(CLOSEPAREN, ")", "end", "'catch' target"); 1781 1781 matchOrFail(OPENBRACE, "Expected exception handler to be a block statement"); 1782 catchBlock = parseBlockStatement(context); 1782 constexpr bool isCatchBlock = true; 1783 catchBlock = parseBlockStatement(context, isCatchBlock); 1783 1784 failIfFalse(catchBlock, "Unable to parse 'catch' block"); 1784 1785 catchEnvironment = catchScope->finalizeLexicalEnvironment(); … … 1813 1814 1814 1815 template <typename LexerType> 1815 template <class TreeBuilder> TreeStatement Parser<LexerType>::parseBlockStatement(TreeBuilder& context )1816 template <class TreeBuilder> TreeStatement Parser<LexerType>::parseBlockStatement(TreeBuilder& context, bool isCatchBlock) 1816 1817 { 1817 1818 ASSERT(match(OPENBRACE)); … … 1825 1826 newScope->setIsLexicalScope(); 1826 1827 newScope->preventVarDeclarations(); 1828 if (isCatchBlock) 1829 newScope->setIsCatchBlockScope(); 1827 1830 lexicalScope.setIsValid(newScope, this); 1828 1831 } -
trunk/Source/JavaScriptCore/parser/Parser.h
r255449 r258861 177 177 , m_isGlobalCodeScope(false) 178 178 , m_isSimpleCatchParameterScope(false) 179 , m_isCatchBlockScope(false) 179 180 , m_isFunctionBoundary(false) 180 181 , m_isValidStrictMode(true) … … 299 300 void setIsSimpleCatchParameterScope() { m_isSimpleCatchParameterScope = true; } 300 301 bool isSimpleCatchParameterScope() { return m_isSimpleCatchParameterScope; } 302 303 void setIsCatchBlockScope() { m_isCatchBlockScope = true; } 304 bool isCatchBlockScope() { return m_isCatchBlockScope; } 301 305 302 306 void setIsLexicalScope() … … 830 834 bool m_isGlobalCodeScope; 831 835 bool m_isSimpleCatchParameterScope; 836 bool m_isCatchBlockScope; 832 837 bool m_isFunctionBoundary; 833 838 bool m_isValidStrictMode; … … 1281 1286 return DeclarationResult::InvalidDuplicateDeclaration; 1282 1287 1283 return currentLexicalDeclarationScope()->declareLexicalVariable(ident, type == DeclarationType::ConstDeclaration, importType); 1288 ScopeRef scope = currentLexicalDeclarationScope(); 1289 if (scope->isCatchBlockScope() && scope.containingScope()->hasLexicallyDeclaredVariable(*ident)) 1290 return DeclarationResult::InvalidDuplicateDeclaration; 1291 1292 return scope->declareLexicalVariable(ident, type == DeclarationType::ConstDeclaration, importType); 1284 1293 } 1285 1294 … … 1296 1305 } 1297 1306 1307 bool declareAsVar = false; 1308 ScopeRef lexicalVariableScope = currentLexicalDeclarationScope(); 1309 if (lexicalVariableScope->isCatchBlockScope() && lexicalVariableScope.containingScope()->hasLexicallyDeclaredVariable(*ident)) 1310 return std::make_pair(DeclarationResult::InvalidDuplicateDeclaration, lexicalVariableScope); 1311 1298 1312 if (!strictMode()) { 1299 1313 ASSERT(currentScope()->isFunction() || closestParentOrdinaryFunctionNonLexicalScope()->isEvalContext()); … … 1307 1321 // binding if the block evaluates. For example, this means we wont won't perform the binding if it's inside 1308 1322 // the untaken branch of an if statement. 1309 bool declareAsVar = false;1310 1323 bool isSloppyModeHoistingCandidate = true; 1311 ScopeRef lexicalVariableScope = currentLexicalDeclarationScope();1312 1324 ScopeRef varScope = currentVariableScope(); 1313 1325 varScope->addSloppyModeHoistableFunctionCandidate(ident); … … 1316 1328 } 1317 1329 1318 bool declareAsVar = false;1319 1330 bool isSloppyModeHoistingCandidate = false; 1320 ScopeRef lexicalVariableScope = currentLexicalDeclarationScope();1321 1331 return std::make_pair(lexicalVariableScope->declareFunction(ident, declareAsVar, isSloppyModeHoistingCandidate), lexicalVariableScope); 1322 1332 } … … 1636 1646 template <class TreeBuilder> TreeStatement parseExpressionOrLabelStatement(TreeBuilder&, bool allowFunctionDeclarationAsStatement); 1637 1647 template <class TreeBuilder> TreeStatement parseIfStatement(TreeBuilder&); 1638 template <class TreeBuilder> TreeStatement parseBlockStatement(TreeBuilder& );1648 template <class TreeBuilder> TreeStatement parseBlockStatement(TreeBuilder&, bool isCatchBlock = false); 1639 1649 template <class TreeBuilder> TreeExpression parseExpression(TreeBuilder&); 1640 1650 template <class TreeBuilder> TreeExpression parseAssignmentExpression(TreeBuilder&, ExpressionErrorClassifier&);
Note: See TracChangeset
for help on using the changeset viewer.