OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 parsing_module_)) { | 1507 parsing_module_)) { |
1508 *ok = false; | 1508 *ok = false; |
1509 ReportMessage(MessageTemplate::kUnexpectedReserved); | 1509 ReportMessage(MessageTemplate::kUnexpectedReserved); |
1510 return nullptr; | 1510 return nullptr; |
1511 } else if (IsEvalOrArguments(local_name)) { | 1511 } else if (IsEvalOrArguments(local_name)) { |
1512 *ok = false; | 1512 *ok = false; |
1513 ReportMessage(MessageTemplate::kStrictEvalArguments); | 1513 ReportMessage(MessageTemplate::kStrictEvalArguments); |
1514 return nullptr; | 1514 return nullptr; |
1515 } | 1515 } |
1516 | 1516 |
1517 DeclareConstVariable(local_name, kNeedsInitialization, position(), | 1517 DeclareVariable(local_name, CONST, kNeedsInitialization, position(), |
1518 CHECK_OK); | 1518 CHECK_OK); |
1519 | 1519 |
1520 NamedImport* import = new (zone()) NamedImport( | 1520 NamedImport* import = new (zone()) NamedImport( |
1521 import_name, local_name, scanner()->location()); | 1521 import_name, local_name, scanner()->location()); |
1522 result->Add(import, zone()); | 1522 result->Add(import, zone()); |
1523 | 1523 |
1524 if (peek() == Token::RBRACE) break; | 1524 if (peek() == Token::RBRACE) break; |
1525 Expect(Token::COMMA, CHECK_OK); | 1525 Expect(Token::COMMA, CHECK_OK); |
1526 } | 1526 } |
1527 | 1527 |
1528 Expect(Token::RBRACE, CHECK_OK); | 1528 Expect(Token::RBRACE, CHECK_OK); |
(...skipping 29 matching lines...) Expand all Loading... |
1558 return; | 1558 return; |
1559 } | 1559 } |
1560 | 1560 |
1561 // Parse ImportedDefaultBinding if present. | 1561 // Parse ImportedDefaultBinding if present. |
1562 const AstRawString* import_default_binding = nullptr; | 1562 const AstRawString* import_default_binding = nullptr; |
1563 Scanner::Location import_default_binding_loc; | 1563 Scanner::Location import_default_binding_loc; |
1564 if (tok != Token::MUL && tok != Token::LBRACE) { | 1564 if (tok != Token::MUL && tok != Token::LBRACE) { |
1565 import_default_binding = | 1565 import_default_binding = |
1566 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); | 1566 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1567 import_default_binding_loc = scanner()->location(); | 1567 import_default_binding_loc = scanner()->location(); |
1568 DeclareConstVariable(import_default_binding, kNeedsInitialization, pos, | 1568 DeclareVariable(import_default_binding, CONST, kNeedsInitialization, pos, |
1569 CHECK_OK_VOID); | 1569 CHECK_OK_VOID); |
1570 } | 1570 } |
1571 | 1571 |
1572 // Parse NameSpaceImport or NamedImports if present. | 1572 // Parse NameSpaceImport or NamedImports if present. |
1573 const AstRawString* module_namespace_binding = nullptr; | 1573 const AstRawString* module_namespace_binding = nullptr; |
1574 Scanner::Location module_namespace_binding_loc; | 1574 Scanner::Location module_namespace_binding_loc; |
1575 const ZoneList<const NamedImport*>* named_imports = nullptr; | 1575 const ZoneList<const NamedImport*>* named_imports = nullptr; |
1576 if (import_default_binding == nullptr || Check(Token::COMMA)) { | 1576 if (import_default_binding == nullptr || Check(Token::COMMA)) { |
1577 switch (peek()) { | 1577 switch (peek()) { |
1578 case Token::MUL: { | 1578 case Token::MUL: { |
1579 Consume(Token::MUL); | 1579 Consume(Token::MUL); |
1580 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); | 1580 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); |
1581 module_namespace_binding = | 1581 module_namespace_binding = |
1582 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); | 1582 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1583 module_namespace_binding_loc = scanner()->location(); | 1583 module_namespace_binding_loc = scanner()->location(); |
1584 DeclareConstVariable(module_namespace_binding, kCreatedInitialized, pos, | 1584 DeclareVariable(module_namespace_binding, CONST, kCreatedInitialized, |
1585 CHECK_OK_VOID); | 1585 pos, CHECK_OK_VOID); |
1586 break; | 1586 break; |
1587 } | 1587 } |
1588 | 1588 |
1589 case Token::LBRACE: | 1589 case Token::LBRACE: |
1590 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); | 1590 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); |
1591 break; | 1591 break; |
1592 | 1592 |
1593 default: | 1593 default: |
1594 *ok = false; | 1594 *ok = false; |
1595 ReportUnexpectedToken(scanner()->current_token()); | 1595 ReportUnexpectedToken(scanner()->current_token()); |
1596 return; | 1596 return; |
1597 } | 1597 } |
1598 } | 1598 } |
1599 | 1599 |
1600 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); | 1600 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); |
1601 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); | 1601 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); |
1602 ExpectSemicolon(CHECK_OK_VOID); | 1602 ExpectSemicolon(CHECK_OK_VOID); |
1603 | 1603 |
1604 // Now that we have all the information, we can make the appropriate | 1604 // Now that we have all the information, we can make the appropriate |
1605 // declarations. | 1605 // declarations. |
1606 | 1606 |
1607 // TODO(neis): Would prefer to call DeclareConstVariable for each case below | 1607 // TODO(neis): Would prefer to call DeclareVariable for each case below rather |
1608 // rather than above and in ParseNamedImports, but then a possible error | 1608 // than above and in ParseNamedImports, but then a possible error message |
1609 // message would point to the wrong location. Maybe have a DeclareAt version | 1609 // would point to the wrong location. Maybe have a DeclareAt version of |
1610 // of Declare that takes a location? | 1610 // Declare that takes a location? |
1611 | 1611 |
1612 if (module_namespace_binding != nullptr) { | 1612 if (module_namespace_binding != nullptr) { |
1613 module()->AddStarImport(module_namespace_binding, module_specifier, | 1613 module()->AddStarImport(module_namespace_binding, module_specifier, |
1614 module_namespace_binding_loc, zone()); | 1614 module_namespace_binding_loc, zone()); |
1615 } | 1615 } |
1616 | 1616 |
1617 if (import_default_binding != nullptr) { | 1617 if (import_default_binding != nullptr) { |
1618 module()->AddImport(ast_value_factory()->default_string(), | 1618 module()->AddImport(ast_value_factory()->default_string(), |
1619 import_default_binding, module_specifier, | 1619 import_default_binding, module_specifier, |
1620 import_default_binding_loc, zone()); | 1620 import_default_binding_loc, zone()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 1671 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
1672 RewriteNonPattern(&classifier, CHECK_OK); | 1672 RewriteNonPattern(&classifier, CHECK_OK); |
1673 SetFunctionName(value, ast_value_factory()->default_string()); | 1673 SetFunctionName(value, ast_value_factory()->default_string()); |
1674 | 1674 |
1675 const AstRawString* local_name = | 1675 const AstRawString* local_name = |
1676 ast_value_factory()->star_default_star_string(); | 1676 ast_value_factory()->star_default_star_string(); |
1677 local_names.Add(local_name, zone()); | 1677 local_names.Add(local_name, zone()); |
1678 | 1678 |
1679 // It's fine to declare this as CONST because the user has no way of | 1679 // It's fine to declare this as CONST because the user has no way of |
1680 // writing to it. | 1680 // writing to it. |
1681 VariableProxy* proxy = NewUnresolved(local_name, CONST); | 1681 Declaration* decl = DeclareVariable(local_name, CONST, pos, CHECK_OK); |
1682 Declaration* declaration = | 1682 decl->proxy()->var()->set_initializer_position(position()); |
1683 factory()->NewVariableDeclaration(proxy, CONST, scope(), pos); | |
1684 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK); | |
1685 proxy->var()->set_initializer_position(position()); | |
1686 | 1683 |
1687 Assignment* assignment = factory()->NewAssignment( | 1684 Assignment* assignment = factory()->NewAssignment( |
1688 Token::INIT, proxy, value, kNoSourcePosition); | 1685 Token::INIT, decl->proxy(), value, kNoSourcePosition); |
1689 result = factory()->NewExpressionStatement(assignment, kNoSourcePosition); | 1686 result = factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
1690 | 1687 |
1691 ExpectSemicolon(CHECK_OK); | 1688 ExpectSemicolon(CHECK_OK); |
1692 break; | 1689 break; |
1693 } | 1690 } |
1694 } | 1691 } |
1695 | 1692 |
1696 DCHECK_EQ(local_names.length(), 1); | 1693 DCHECK_EQ(local_names.length(), 1); |
1697 module()->AddExport(local_names.first(), | 1694 module()->AddExport(local_names.first(), |
1698 ast_value_factory()->default_string(), default_loc, | 1695 ast_value_factory()->default_string(), default_loc, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 // scope. | 1955 // scope. |
1959 // Let/const variables are always added to the immediately enclosing scope. | 1956 // Let/const variables are always added to the immediately enclosing scope. |
1960 Scope* scope = IsLexicalVariableMode(mode) | 1957 Scope* scope = IsLexicalVariableMode(mode) |
1961 ? this->scope() | 1958 ? this->scope() |
1962 : this->scope()->GetDeclarationScope(); | 1959 : this->scope()->GetDeclarationScope(); |
1963 return scope->NewUnresolved(factory(), name, Variable::NORMAL, | 1960 return scope->NewUnresolved(factory(), name, Variable::NORMAL, |
1964 scanner()->location().beg_pos, | 1961 scanner()->location().beg_pos, |
1965 scanner()->location().end_pos); | 1962 scanner()->location().end_pos); |
1966 } | 1963 } |
1967 | 1964 |
1968 void Parser::DeclareConstVariable(const AstRawString* name, | 1965 InitializationFlag Parser::DefaultInitializationFlag(VariableMode mode) { |
1969 InitializationFlag init, int pos, bool* ok) { | 1966 DCHECK(IsDeclaredVariableMode(mode)); |
| 1967 return mode == VAR ? kCreatedInitialized : kNeedsInitialization; |
| 1968 } |
| 1969 |
| 1970 Declaration* Parser::DeclareVariable(const AstRawString* name, |
| 1971 VariableMode mode, int pos, bool* ok) { |
| 1972 return DeclareVariable(name, mode, DefaultInitializationFlag(mode), pos, ok); |
| 1973 } |
| 1974 |
| 1975 Declaration* Parser::DeclareVariable(const AstRawString* name, |
| 1976 VariableMode mode, InitializationFlag init, |
| 1977 int pos, bool* ok) { |
1970 DCHECK_NOT_NULL(name); | 1978 DCHECK_NOT_NULL(name); |
1971 VariableProxy* proxy = NewUnresolved(name, CONST); | 1979 VariableProxy* proxy = NewUnresolved(name, mode); |
1972 Declaration* declaration = | 1980 Declaration* declaration = |
1973 factory()->NewVariableDeclaration(proxy, CONST, scope(), init, pos); | 1981 factory()->NewVariableDeclaration(proxy, mode, scope(), pos); |
1974 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK_VOID); | 1982 Declare(declaration, DeclarationDescriptor::NORMAL, init, CHECK_OK); |
| 1983 return declaration; |
1975 } | 1984 } |
1976 | 1985 |
1977 Variable* Parser::Declare(Declaration* declaration, | 1986 Variable* Parser::Declare(Declaration* declaration, |
1978 DeclarationDescriptor::Kind declaration_kind, | 1987 DeclarationDescriptor::Kind declaration_kind, |
1979 bool* ok, Scope* scope) { | 1988 InitializationFlag init, bool* ok, Scope* scope) { |
1980 VariableProxy* proxy = declaration->proxy(); | 1989 VariableProxy* proxy = declaration->proxy(); |
1981 DCHECK(proxy->raw_name() != NULL); | 1990 DCHECK(proxy->raw_name() != NULL); |
1982 const AstRawString* name = proxy->raw_name(); | 1991 const AstRawString* name = proxy->raw_name(); |
1983 VariableMode mode = declaration->mode(); | 1992 VariableMode mode = declaration->mode(); |
1984 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); | 1993 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); |
1985 bool is_function_declaration = declaration->IsFunctionDeclaration(); | 1994 bool is_function_declaration = declaration->IsFunctionDeclaration(); |
1986 if (scope == nullptr) scope = this->scope(); | 1995 if (scope == nullptr) scope = this->scope(); |
1987 if (mode == VAR) scope = scope->GetDeclarationScope(); | 1996 if (mode == VAR) scope = scope->GetDeclarationScope(); |
1988 | 1997 |
1989 DCHECK(!scope->is_catch_scope()); | 1998 DCHECK(!scope->is_catch_scope()); |
1990 DCHECK(!scope->is_with_scope()); | 1999 DCHECK(!scope->is_with_scope()); |
1991 DCHECK(scope->is_declaration_scope() || | 2000 DCHECK(scope->is_declaration_scope() || |
1992 (IsLexicalVariableMode(mode) && scope->is_block_scope())); | 2001 (IsLexicalVariableMode(mode) && scope->is_block_scope())); |
1993 | 2002 |
1994 Variable* var = NULL; | 2003 Variable* var = NULL; |
1995 if (scope->is_eval_scope() && is_sloppy(scope->language_mode()) && | 2004 if (scope->is_eval_scope() && is_sloppy(scope->language_mode()) && |
1996 mode == VAR) { | 2005 mode == VAR) { |
1997 // In a var binding in a sloppy direct eval, pollute the enclosing scope | 2006 // In a var binding in a sloppy direct eval, pollute the enclosing scope |
1998 // with this new binding by doing the following: | 2007 // with this new binding by doing the following: |
1999 // The proxy is bound to a lookup variable to force a dynamic declaration | 2008 // The proxy is bound to a lookup variable to force a dynamic declaration |
2000 // using the DeclareEvalVar or DeclareEvalFunction runtime functions. | 2009 // using the DeclareEvalVar or DeclareEvalFunction runtime functions. |
2001 Variable::Kind kind = Variable::NORMAL; | 2010 Variable::Kind kind = Variable::NORMAL; |
2002 // TODO(sigurds) figure out if kNotAssigned is OK here | 2011 // TODO(sigurds) figure out if kNotAssigned is OK here |
2003 var = new (zone()) Variable(scope, name, mode, kind, | 2012 var = new (zone()) Variable(scope, name, mode, kind, init, kNotAssigned); |
2004 declaration->initialization(), kNotAssigned); | |
2005 var->AllocateTo(VariableLocation::LOOKUP, -1); | 2013 var->AllocateTo(VariableLocation::LOOKUP, -1); |
2006 } else { | 2014 } else { |
2007 // Declare the variable in the declaration scope. | 2015 // Declare the variable in the declaration scope. |
2008 var = scope->LookupLocal(name); | 2016 var = scope->LookupLocal(name); |
2009 if (var == NULL) { | 2017 if (var == NULL) { |
2010 // Declare the name. | 2018 // Declare the name. |
2011 Variable::Kind kind = Variable::NORMAL; | 2019 Variable::Kind kind = Variable::NORMAL; |
2012 if (is_function_declaration) { | 2020 if (is_function_declaration) { |
2013 kind = Variable::FUNCTION; | 2021 kind = Variable::FUNCTION; |
2014 } | 2022 } |
2015 var = scope->DeclareLocal(name, mode, declaration->initialization(), kind, | 2023 var = scope->DeclareLocal(name, mode, init, kind, kNotAssigned); |
2016 kNotAssigned); | |
2017 } else if (IsLexicalVariableMode(mode) || | 2024 } else if (IsLexicalVariableMode(mode) || |
2018 IsLexicalVariableMode(var->mode())) { | 2025 IsLexicalVariableMode(var->mode())) { |
2019 // Allow duplicate function decls for web compat, see bug 4693. | 2026 // Allow duplicate function decls for web compat, see bug 4693. |
2020 bool duplicate_allowed = false; | 2027 bool duplicate_allowed = false; |
2021 if (is_sloppy(scope->language_mode()) && is_function_declaration && | 2028 if (is_sloppy(scope->language_mode()) && is_function_declaration && |
2022 var->is_function()) { | 2029 var->is_function()) { |
2023 DCHECK(IsLexicalVariableMode(mode) && | 2030 DCHECK(IsLexicalVariableMode(mode) && |
2024 IsLexicalVariableMode(var->mode())); | 2031 IsLexicalVariableMode(var->mode())); |
2025 // If the duplication is allowed, then the var will show up | 2032 // If the duplication is allowed, then the var will show up |
2026 // in the SloppyBlockFunctionMap and the new FunctionKind | 2033 // in the SloppyBlockFunctionMap and the new FunctionKind |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2107 // Make sure that the function containing the native declaration | 2114 // Make sure that the function containing the native declaration |
2108 // isn't lazily compiled. The extension structures are only | 2115 // isn't lazily compiled. The extension structures are only |
2109 // accessible while parsing the first time not when reparsing | 2116 // accessible while parsing the first time not when reparsing |
2110 // because of lazy compilation. | 2117 // because of lazy compilation. |
2111 // TODO(adamk): Should this be GetClosureScope()? | 2118 // TODO(adamk): Should this be GetClosureScope()? |
2112 scope()->GetDeclarationScope()->ForceEagerCompilation(); | 2119 scope()->GetDeclarationScope()->ForceEagerCompilation(); |
2113 | 2120 |
2114 // TODO(1240846): It's weird that native function declarations are | 2121 // TODO(1240846): It's weird that native function declarations are |
2115 // introduced dynamically when we meet their declarations, whereas | 2122 // introduced dynamically when we meet their declarations, whereas |
2116 // other functions are set up when entering the surrounding scope. | 2123 // other functions are set up when entering the surrounding scope. |
2117 VariableProxy* proxy = NewUnresolved(name, VAR); | 2124 Declaration* decl = DeclareVariable(name, VAR, pos, CHECK_OK); |
2118 Declaration* declaration = | |
2119 factory()->NewVariableDeclaration(proxy, VAR, scope(), pos); | |
2120 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK); | |
2121 NativeFunctionLiteral* lit = | 2125 NativeFunctionLiteral* lit = |
2122 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition); | 2126 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition); |
2123 return factory()->NewExpressionStatement( | 2127 return factory()->NewExpressionStatement( |
2124 factory()->NewAssignment(Token::INIT, proxy, lit, kNoSourcePosition), | 2128 factory()->NewAssignment(Token::INIT, decl->proxy(), lit, |
| 2129 kNoSourcePosition), |
2125 pos); | 2130 pos); |
2126 } | 2131 } |
2127 | 2132 |
2128 Statement* Parser::ParseHoistableDeclaration( | 2133 Statement* Parser::ParseHoistableDeclaration( |
2129 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { | 2134 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { |
2130 Expect(Token::FUNCTION, CHECK_OK); | 2135 Expect(Token::FUNCTION, CHECK_OK); |
2131 int pos = position(); | 2136 int pos = position(); |
2132 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; | 2137 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
2133 if (Check(Token::MUL)) { | 2138 if (Check(Token::MUL)) { |
2134 flags |= ParseFunctionFlags::kIsGenerator; | 2139 flags |= ParseFunctionFlags::kIsGenerator; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2200 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); | 2205 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
2201 | 2206 |
2202 // In ES6, a function behaves as a lexical binding, except in | 2207 // In ES6, a function behaves as a lexical binding, except in |
2203 // a script scope, or the initial scope of eval or another function. | 2208 // a script scope, or the initial scope of eval or another function. |
2204 VariableMode mode = | 2209 VariableMode mode = |
2205 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET | 2210 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET |
2206 : VAR; | 2211 : VAR; |
2207 VariableProxy* proxy = NewUnresolved(variable_name, mode); | 2212 VariableProxy* proxy = NewUnresolved(variable_name, mode); |
2208 Declaration* declaration = | 2213 Declaration* declaration = |
2209 factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos); | 2214 factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos); |
2210 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK); | 2215 Declare(declaration, DeclarationDescriptor::NORMAL, kCreatedInitialized, |
| 2216 CHECK_OK); |
2211 if (names) names->Add(variable_name, zone()); | 2217 if (names) names->Add(variable_name, zone()); |
2212 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); | 2218 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); |
2213 // Async functions don't undergo sloppy mode block scoped hoisting, and don't | 2219 // Async functions don't undergo sloppy mode block scoped hoisting, and don't |
2214 // allow duplicates in a block. Both are represented by the | 2220 // allow duplicates in a block. Both are represented by the |
2215 // sloppy_block_function_map. Don't add them to the map for async functions. | 2221 // sloppy_block_function_map. Don't add them to the map for async functions. |
2216 // Generators are also supposed to be prohibited; currently doing this behind | 2222 // Generators are also supposed to be prohibited; currently doing this behind |
2217 // a flag and UseCounting violations to assess web compatibility. | 2223 // a flag and UseCounting violations to assess web compatibility. |
2218 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() && | 2224 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() && |
2219 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) { | 2225 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) { |
2220 SloppyBlockFunctionStatement* delegate = | 2226 SloppyBlockFunctionStatement* delegate = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2256 is_strict_reserved = false; | 2262 is_strict_reserved = false; |
2257 variable_name = ast_value_factory()->star_default_star_string(); | 2263 variable_name = ast_value_factory()->star_default_star_string(); |
2258 } else { | 2264 } else { |
2259 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2265 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
2260 variable_name = name; | 2266 variable_name = name; |
2261 } | 2267 } |
2262 | 2268 |
2263 Expression* value = ParseClassLiteral(nullptr, name, scanner()->location(), | 2269 Expression* value = ParseClassLiteral(nullptr, name, scanner()->location(), |
2264 is_strict_reserved, pos, CHECK_OK); | 2270 is_strict_reserved, pos, CHECK_OK); |
2265 | 2271 |
2266 VariableProxy* proxy = NewUnresolved(variable_name, LET); | 2272 Declaration* decl = DeclareVariable(variable_name, LET, pos, CHECK_OK); |
2267 Declaration* declaration = | 2273 decl->proxy()->var()->set_initializer_position(position()); |
2268 factory()->NewVariableDeclaration(proxy, LET, scope(), pos); | |
2269 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK); | |
2270 proxy->var()->set_initializer_position(position()); | |
2271 Assignment* assignment = | 2274 Assignment* assignment = |
2272 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 2275 factory()->NewAssignment(Token::INIT, decl->proxy(), value, pos); |
2273 Statement* assignment_statement = | 2276 Statement* assignment_statement = |
2274 factory()->NewExpressionStatement(assignment, kNoSourcePosition); | 2277 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
2275 if (names) names->Add(variable_name, zone()); | 2278 if (names) names->Add(variable_name, zone()); |
2276 return assignment_statement; | 2279 return assignment_statement; |
2277 } | 2280 } |
2278 | 2281 |
2279 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { | 2282 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { |
2280 // The harmony mode uses block elements instead of statements. | 2283 // The harmony mode uses block elements instead of statements. |
2281 // | 2284 // |
2282 // Block :: | 2285 // Block :: |
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3489 Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition); | 3492 Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition); |
3490 { | 3493 { |
3491 BlockState block_state(&scope_state_, inner_scope); | 3494 BlockState block_state(&scope_state_, inner_scope); |
3492 | 3495 |
3493 Block* ignore_completion_block = | 3496 Block* ignore_completion_block = |
3494 factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition); | 3497 factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition); |
3495 ZoneList<Variable*> inner_vars(names->length(), zone()); | 3498 ZoneList<Variable*> inner_vars(names->length(), zone()); |
3496 // For each let variable x: | 3499 // For each let variable x: |
3497 // make statement: let/const x = temp_x. | 3500 // make statement: let/const x = temp_x. |
3498 for (int i = 0; i < names->length(); i++) { | 3501 for (int i = 0; i < names->length(); i++) { |
3499 VariableProxy* proxy = NewUnresolved(names->at(i), mode); | 3502 Declaration* decl = |
3500 Declaration* declaration = factory()->NewVariableDeclaration( | 3503 DeclareVariable(names->at(i), mode, kNoSourcePosition, CHECK_OK); |
3501 proxy, mode, scope(), kNoSourcePosition); | 3504 inner_vars.Add(decl->proxy()->var(), zone()); |
3502 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK); | |
3503 inner_vars.Add(declaration->proxy()->var(), zone()); | |
3504 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); | 3505 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
3505 Assignment* assignment = factory()->NewAssignment( | 3506 Assignment* assignment = factory()->NewAssignment( |
3506 Token::INIT, proxy, temp_proxy, kNoSourcePosition); | 3507 Token::INIT, decl->proxy(), temp_proxy, kNoSourcePosition); |
3507 Statement* assignment_statement = | 3508 Statement* assignment_statement = |
3508 factory()->NewExpressionStatement(assignment, kNoSourcePosition); | 3509 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
3509 DCHECK(init->position() != kNoSourcePosition); | 3510 DCHECK(init->position() != kNoSourcePosition); |
3510 proxy->var()->set_initializer_position(init->position()); | 3511 decl->proxy()->var()->set_initializer_position(init->position()); |
3511 ignore_completion_block->statements()->Add(assignment_statement, zone()); | 3512 ignore_completion_block->statements()->Add(assignment_statement, zone()); |
3512 } | 3513 } |
3513 | 3514 |
3514 // Make statement: if (first == 1) { first = 0; } else { next; } | 3515 // Make statement: if (first == 1) { first = 0; } else { next; } |
3515 if (next) { | 3516 if (next) { |
3516 DCHECK(first); | 3517 DCHECK(first); |
3517 Expression* compare = NULL; | 3518 Expression* compare = NULL; |
3518 // Make compare expression: first == 1. | 3519 // Make compare expression: first == 1. |
3519 { | 3520 { |
3520 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); | 3521 Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3840 if (bound_names_are_lexical) { | 3841 if (bound_names_are_lexical) { |
3841 DCHECK_NULL(init_block); | 3842 DCHECK_NULL(init_block); |
3842 | 3843 |
3843 init_block = | 3844 init_block = |
3844 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); | 3845 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); |
3845 | 3846 |
3846 for (int i = 0; i < bound_names.length(); ++i) { | 3847 for (int i = 0; i < bound_names.length(); ++i) { |
3847 // TODO(adamk): This needs to be some sort of special | 3848 // TODO(adamk): This needs to be some sort of special |
3848 // INTERNAL variable that's invisible to the debugger | 3849 // INTERNAL variable that's invisible to the debugger |
3849 // but visible to everything else. | 3850 // but visible to everything else. |
3850 VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET); | 3851 Declaration* tdz_decl = DeclareVariable( |
3851 Declaration* tdz_decl = factory()->NewVariableDeclaration( | 3852 bound_names[i], LET, kNoSourcePosition, CHECK_OK); |
3852 tdz_proxy, LET, scope(), kNoSourcePosition); | 3853 tdz_decl->proxy()->var()->set_initializer_position(position()); |
3853 Variable* tdz_var = | |
3854 Declare(tdz_decl, DeclarationDescriptor::NORMAL, CHECK_OK); | |
3855 tdz_var->set_initializer_position(position()); | |
3856 } | 3854 } |
3857 } | 3855 } |
3858 | 3856 |
3859 for_state.set_end_position(scanner()->location().end_pos); | 3857 for_state.set_end_position(scanner()->location().end_pos); |
3860 Scope* for_scope = for_state.FinalizedBlockScope(); | 3858 Scope* for_scope = for_state.FinalizedBlockScope(); |
3861 // Parsed for-in loop w/ variable declarations. | 3859 // Parsed for-in loop w/ variable declarations. |
3862 if (init_block != nullptr) { | 3860 if (init_block != nullptr) { |
3863 init_block->statements()->Add(final_loop, zone()); | 3861 init_block->statements()->Add(final_loop, zone()); |
3864 init_block->set_scope(for_scope); | 3862 init_block->set_scope(for_scope); |
3865 return init_block; | 3863 return init_block; |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5023 #ifdef DEBUG | 5021 #ifdef DEBUG |
5024 scope()->SetScopeName(name); | 5022 scope()->SetScopeName(name); |
5025 #endif | 5023 #endif |
5026 | 5024 |
5027 VariableProxy* proxy = nullptr; | 5025 VariableProxy* proxy = nullptr; |
5028 if (name != nullptr) { | 5026 if (name != nullptr) { |
5029 proxy = NewUnresolved(name, CONST); | 5027 proxy = NewUnresolved(name, CONST); |
5030 // TODO(verwaest): declare via block_state. | 5028 // TODO(verwaest): declare via block_state. |
5031 Declaration* declaration = factory()->NewVariableDeclaration( | 5029 Declaration* declaration = factory()->NewVariableDeclaration( |
5032 proxy, CONST, block_state.scope(), pos); | 5030 proxy, CONST, block_state.scope(), pos); |
5033 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK); | 5031 Declare(declaration, DeclarationDescriptor::NORMAL, |
| 5032 DefaultInitializationFlag(CONST), CHECK_OK); |
5034 } | 5033 } |
5035 | 5034 |
5036 Expression* extends = nullptr; | 5035 Expression* extends = nullptr; |
5037 if (Check(Token::EXTENDS)) { | 5036 if (Check(Token::EXTENDS)) { |
5038 block_state.set_start_position(scanner()->location().end_pos); | 5037 block_state.set_start_position(scanner()->location().end_pos); |
5039 ExpressionClassifier extends_classifier(this); | 5038 ExpressionClassifier extends_classifier(this); |
5040 extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); | 5039 extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); |
5041 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); | 5040 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); |
5042 RewriteNonPattern(&extends_classifier, CHECK_OK); | 5041 RewriteNonPattern(&extends_classifier, CHECK_OK); |
5043 if (classifier != nullptr) { | 5042 if (classifier != nullptr) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5302 } while (query_scope != outer_scope); | 5301 } while (query_scope != outer_scope); |
5303 | 5302 |
5304 if (!should_hoist) continue; | 5303 if (!should_hoist) continue; |
5305 | 5304 |
5306 // Declare a var-style binding for the function in the outer scope | 5305 // Declare a var-style binding for the function in the outer scope |
5307 if (!var_created) { | 5306 if (!var_created) { |
5308 var_created = true; | 5307 var_created = true; |
5309 VariableProxy* proxy = scope->NewUnresolved(factory(), name); | 5308 VariableProxy* proxy = scope->NewUnresolved(factory(), name); |
5310 Declaration* declaration = factory()->NewVariableDeclaration( | 5309 Declaration* declaration = factory()->NewVariableDeclaration( |
5311 proxy, VAR, scope, kNoSourcePosition); | 5310 proxy, VAR, scope, kNoSourcePosition); |
5312 Declare(declaration, DeclarationDescriptor::NORMAL, ok, scope); | 5311 Declare(declaration, DeclarationDescriptor::NORMAL, |
| 5312 DefaultInitializationFlag(VAR), ok, scope); |
5313 DCHECK(ok); // Based on the preceding check, this should not fail | 5313 DCHECK(ok); // Based on the preceding check, this should not fail |
5314 if (!ok) return; | 5314 if (!ok) return; |
5315 } | 5315 } |
5316 | 5316 |
5317 // Read from the local lexical scope and write to the function scope | 5317 // Read from the local lexical scope and write to the function scope |
5318 VariableProxy* to = scope->NewUnresolved(factory(), name); | 5318 VariableProxy* to = scope->NewUnresolved(factory(), name); |
5319 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name); | 5319 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name); |
5320 Expression* assignment = | 5320 Expression* assignment = |
5321 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); | 5321 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); |
5322 Statement* statement = | 5322 Statement* statement = |
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7106 node->Print(Isolate::Current()); | 7106 node->Print(Isolate::Current()); |
7107 } | 7107 } |
7108 #endif // DEBUG | 7108 #endif // DEBUG |
7109 | 7109 |
7110 #undef CHECK_OK | 7110 #undef CHECK_OK |
7111 #undef CHECK_OK_VOID | 7111 #undef CHECK_OK_VOID |
7112 #undef CHECK_FAILED | 7112 #undef CHECK_FAILED |
7113 | 7113 |
7114 } // namespace internal | 7114 } // namespace internal |
7115 } // namespace v8 | 7115 } // namespace v8 |
OLD | NEW |