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 "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 } | 1409 } |
1410 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false)) { | 1410 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false)) { |
1411 *ok = false; | 1411 *ok = false; |
1412 ReportMessage(MessageTemplate::kUnexpectedReserved); | 1412 ReportMessage(MessageTemplate::kUnexpectedReserved); |
1413 return NULL; | 1413 return NULL; |
1414 } else if (IsEvalOrArguments(local_name)) { | 1414 } else if (IsEvalOrArguments(local_name)) { |
1415 *ok = false; | 1415 *ok = false; |
1416 ReportMessage(MessageTemplate::kStrictEvalArguments); | 1416 ReportMessage(MessageTemplate::kStrictEvalArguments); |
1417 return NULL; | 1417 return NULL; |
1418 } | 1418 } |
1419 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); | 1419 VariableProxy* proxy = NewUnresolved(local_name, CONST); |
1420 ImportDeclaration* declaration = | 1420 ImportDeclaration* declaration = |
1421 factory()->NewImportDeclaration(proxy, import_name, NULL, scope_, pos); | 1421 factory()->NewImportDeclaration(proxy, import_name, NULL, scope_, pos); |
1422 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 1422 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
1423 result->Add(declaration, zone()); | 1423 result->Add(declaration, zone()); |
1424 if (peek() == Token::RBRACE) break; | 1424 if (peek() == Token::RBRACE) break; |
1425 Expect(Token::COMMA, CHECK_OK); | 1425 Expect(Token::COMMA, CHECK_OK); |
1426 } | 1426 } |
1427 | 1427 |
1428 Expect(Token::RBRACE, CHECK_OK); | 1428 Expect(Token::RBRACE, CHECK_OK); |
1429 | 1429 |
(...skipping 27 matching lines...) Expand all Loading... |
1457 scope_->module()->AddModuleRequest(module_specifier, zone()); | 1457 scope_->module()->AddModuleRequest(module_specifier, zone()); |
1458 ExpectSemicolon(CHECK_OK); | 1458 ExpectSemicolon(CHECK_OK); |
1459 return factory()->NewEmptyStatement(pos); | 1459 return factory()->NewEmptyStatement(pos); |
1460 } | 1460 } |
1461 | 1461 |
1462 // Parse ImportedDefaultBinding if present. | 1462 // Parse ImportedDefaultBinding if present. |
1463 ImportDeclaration* import_default_declaration = NULL; | 1463 ImportDeclaration* import_default_declaration = NULL; |
1464 if (tok != Token::MUL && tok != Token::LBRACE) { | 1464 if (tok != Token::MUL && tok != Token::LBRACE) { |
1465 const AstRawString* local_name = | 1465 const AstRawString* local_name = |
1466 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 1466 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); |
1467 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); | 1467 VariableProxy* proxy = NewUnresolved(local_name, CONST); |
1468 import_default_declaration = factory()->NewImportDeclaration( | 1468 import_default_declaration = factory()->NewImportDeclaration( |
1469 proxy, ast_value_factory()->default_string(), NULL, scope_, pos); | 1469 proxy, ast_value_factory()->default_string(), NULL, scope_, pos); |
1470 Declare(import_default_declaration, DeclarationDescriptor::NORMAL, true, | 1470 Declare(import_default_declaration, DeclarationDescriptor::NORMAL, true, |
1471 CHECK_OK); | 1471 CHECK_OK); |
1472 } | 1472 } |
1473 | 1473 |
1474 const AstRawString* module_instance_binding = NULL; | 1474 const AstRawString* module_instance_binding = NULL; |
1475 ZoneList<ImportDeclaration*>* named_declarations = NULL; | 1475 ZoneList<ImportDeclaration*>* named_declarations = NULL; |
1476 if (import_default_declaration == NULL || Check(Token::COMMA)) { | 1476 if (import_default_declaration == NULL || Check(Token::COMMA)) { |
1477 switch (peek()) { | 1477 switch (peek()) { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 } | 1863 } |
1864 | 1864 |
1865 | 1865 |
1866 Variable* Parser::Declare(Declaration* declaration, | 1866 Variable* Parser::Declare(Declaration* declaration, |
1867 DeclarationDescriptor::Kind declaration_kind, | 1867 DeclarationDescriptor::Kind declaration_kind, |
1868 bool resolve, bool* ok, Scope* scope) { | 1868 bool resolve, bool* ok, Scope* scope) { |
1869 VariableProxy* proxy = declaration->proxy(); | 1869 VariableProxy* proxy = declaration->proxy(); |
1870 DCHECK(proxy->raw_name() != NULL); | 1870 DCHECK(proxy->raw_name() != NULL); |
1871 const AstRawString* name = proxy->raw_name(); | 1871 const AstRawString* name = proxy->raw_name(); |
1872 VariableMode mode = declaration->mode(); | 1872 VariableMode mode = declaration->mode(); |
| 1873 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); |
1873 bool is_function_declaration = declaration->IsFunctionDeclaration(); | 1874 bool is_function_declaration = declaration->IsFunctionDeclaration(); |
1874 if (scope == nullptr) scope = scope_; | 1875 if (scope == nullptr) scope = scope_; |
1875 Scope* declaration_scope = | 1876 Scope* declaration_scope = |
1876 IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope(); | 1877 IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope(); |
1877 Variable* var = NULL; | 1878 Variable* var = NULL; |
1878 | 1879 |
1879 // If a suitable scope exists, then we can statically declare this | 1880 // If a suitable scope exists, then we can statically declare this |
1880 // variable and also set its mode. In any case, a Declaration node | 1881 // variable and also set its mode. In any case, a Declaration node |
1881 // will be added to the scope so that the declaration can be added | 1882 // will be added to the scope so that the declaration can be added |
1882 // to the corresponding activation frame at runtime if necessary. | 1883 // to the corresponding activation frame at runtime if necessary. |
(...skipping 4899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6782 try_block, target); | 6783 try_block, target); |
6783 final_loop = target; | 6784 final_loop = target; |
6784 } | 6785 } |
6785 | 6786 |
6786 return final_loop; | 6787 return final_loop; |
6787 } | 6788 } |
6788 | 6789 |
6789 | 6790 |
6790 } // namespace internal | 6791 } // namespace internal |
6791 } // namespace v8 | 6792 } // namespace v8 |
OLD | NEW |