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-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 Declaration* Parser::DeclareVariable(const AstRawString* name, | 1478 Declaration* Parser::DeclareVariable(const AstRawString* name, |
1479 VariableMode mode, int pos, bool* ok) { | 1479 VariableMode mode, int pos, bool* ok) { |
1480 return DeclareVariable(name, mode, Variable::DefaultInitializationFlag(mode), | 1480 return DeclareVariable(name, mode, Variable::DefaultInitializationFlag(mode), |
1481 pos, ok); | 1481 pos, ok); |
1482 } | 1482 } |
1483 | 1483 |
1484 Declaration* Parser::DeclareVariable(const AstRawString* name, | 1484 Declaration* Parser::DeclareVariable(const AstRawString* name, |
1485 VariableMode mode, InitializationFlag init, | 1485 VariableMode mode, InitializationFlag init, |
1486 int pos, bool* ok) { | 1486 int pos, bool* ok) { |
1487 DCHECK_NOT_NULL(name); | 1487 DCHECK_NOT_NULL(name); |
1488 Scope* scope = | 1488 VariableProxy* proxy = factory()->NewVariableProxy( |
1489 IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope(); | 1489 name, NORMAL_VARIABLE, scanner()->location().beg_pos, |
1490 VariableProxy* proxy = | 1490 scanner()->location().end_pos); |
1491 scope->NewUnresolved(factory(), name, scanner()->location().beg_pos, | |
1492 scanner()->location().end_pos); | |
1493 Declaration* declaration = | 1491 Declaration* declaration = |
1494 factory()->NewVariableDeclaration(proxy, this->scope(), pos); | 1492 factory()->NewVariableDeclaration(proxy, this->scope(), pos); |
1495 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); | 1493 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); |
1496 return declaration; | 1494 return declaration; |
1497 } | 1495 } |
1498 | 1496 |
1499 Variable* Parser::Declare(Declaration* declaration, | 1497 Variable* Parser::Declare(Declaration* declaration, |
1500 DeclarationDescriptor::Kind declaration_kind, | 1498 DeclarationDescriptor::Kind declaration_kind, |
1501 VariableMode mode, InitializationFlag init, bool* ok, | 1499 VariableMode mode, InitializationFlag init, bool* ok, |
1502 Scope* scope) { | 1500 Scope* scope) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 Statement* Parser::DeclareFunction(const AstRawString* variable_name, | 1647 Statement* Parser::DeclareFunction(const AstRawString* variable_name, |
1650 FunctionLiteral* function, int pos, | 1648 FunctionLiteral* function, int pos, |
1651 bool is_generator, bool is_async, | 1649 bool is_generator, bool is_async, |
1652 ZoneList<const AstRawString*>* names, | 1650 ZoneList<const AstRawString*>* names, |
1653 bool* ok) { | 1651 bool* ok) { |
1654 // In ES6, a function behaves as a lexical binding, except in | 1652 // In ES6, a function behaves as a lexical binding, except in |
1655 // a script scope, or the initial scope of eval or another function. | 1653 // a script scope, or the initial scope of eval or another function. |
1656 VariableMode mode = | 1654 VariableMode mode = |
1657 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET | 1655 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET |
1658 : VAR; | 1656 : VAR; |
1659 VariableProxy* proxy = NewUnresolved(variable_name); | 1657 VariableProxy* proxy = |
| 1658 factory()->NewVariableProxy(variable_name, NORMAL_VARIABLE); |
1660 Declaration* declaration = | 1659 Declaration* declaration = |
1661 factory()->NewFunctionDeclaration(proxy, function, scope(), pos); | 1660 factory()->NewFunctionDeclaration(proxy, function, scope(), pos); |
1662 Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized, | 1661 Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized, |
1663 CHECK_OK); | 1662 CHECK_OK); |
1664 if (names) names->Add(variable_name, zone()); | 1663 if (names) names->Add(variable_name, zone()); |
1665 // Async functions don't undergo sloppy mode block scoped hoisting, and don't | 1664 // Async functions don't undergo sloppy mode block scoped hoisting, and don't |
1666 // allow duplicates in a block. Both are represented by the | 1665 // allow duplicates in a block. Both are represented by the |
1667 // sloppy_block_function_map. Don't add them to the map for async functions. | 1666 // sloppy_block_function_map. Don't add them to the map for async functions. |
1668 // Generators are also supposed to be prohibited; currently doing this behind | 1667 // Generators are also supposed to be prohibited; currently doing this behind |
1669 // a flag and UseCounting violations to assess web compatibility. | 1668 // a flag and UseCounting violations to assess web compatibility. |
(...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3850 } | 3849 } |
3851 | 3850 |
3852 BlockState block_state(&scope_state_); | 3851 BlockState block_state(&scope_state_); |
3853 RaiseLanguageMode(STRICT); | 3852 RaiseLanguageMode(STRICT); |
3854 #ifdef DEBUG | 3853 #ifdef DEBUG |
3855 scope()->SetScopeName(name); | 3854 scope()->SetScopeName(name); |
3856 #endif | 3855 #endif |
3857 | 3856 |
3858 VariableProxy* proxy = nullptr; | 3857 VariableProxy* proxy = nullptr; |
3859 if (name != nullptr) { | 3858 if (name != nullptr) { |
3860 proxy = NewUnresolved(name); | 3859 proxy = factory()->NewVariableProxy(name, NORMAL_VARIABLE); |
3861 // TODO(verwaest): declare via block_state. | 3860 // TODO(verwaest): declare via block_state. |
3862 Declaration* declaration = | 3861 Declaration* declaration = |
3863 factory()->NewVariableDeclaration(proxy, block_state.scope(), pos); | 3862 factory()->NewVariableDeclaration(proxy, block_state.scope(), pos); |
3864 Declare(declaration, DeclarationDescriptor::NORMAL, CONST, | 3863 Declare(declaration, DeclarationDescriptor::NORMAL, CONST, |
3865 Variable::DefaultInitializationFlag(CONST), CHECK_OK); | 3864 Variable::DefaultInitializationFlag(CONST), CHECK_OK); |
3866 } | 3865 } |
3867 | 3866 |
3868 Expression* extends = nullptr; | 3867 Expression* extends = nullptr; |
3869 if (Check(Token::EXTENDS)) { | 3868 if (Check(Token::EXTENDS)) { |
3870 block_state.set_start_position(scanner()->location().end_pos); | 3869 block_state.set_start_position(scanner()->location().end_pos); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3934 // if (is_computed_name) { // TODO(bakkot) figure out why this is | 3933 // if (is_computed_name) { // TODO(bakkot) figure out why this is |
3935 // necessary for non-computed names in full-codegen | 3934 // necessary for non-computed names in full-codegen |
3936 ZoneList<Expression*>* to_name_args = | 3935 ZoneList<Expression*>* to_name_args = |
3937 new (zone()) ZoneList<Expression*>(1, zone()); | 3936 new (zone()) ZoneList<Expression*>(1, zone()); |
3938 to_name_args->Add(property->key(), zone()); | 3937 to_name_args->Add(property->key(), zone()); |
3939 property->set_key(factory()->NewCallRuntime( | 3938 property->set_key(factory()->NewCallRuntime( |
3940 Runtime::kToName, to_name_args, kNoSourcePosition)); | 3939 Runtime::kToName, to_name_args, kNoSourcePosition)); |
3941 //} | 3940 //} |
3942 const AstRawString* name = ClassFieldVariableName( | 3941 const AstRawString* name = ClassFieldVariableName( |
3943 true, ast_value_factory(), instance_field_initializers->length()); | 3942 true, ast_value_factory(), instance_field_initializers->length()); |
3944 VariableProxy* name_proxy = NewUnresolved(name); | 3943 VariableProxy* name_proxy = |
| 3944 factory()->NewVariableProxy(name, NORMAL_VARIABLE); |
3945 Declaration* name_declaration = factory()->NewVariableDeclaration( | 3945 Declaration* name_declaration = factory()->NewVariableDeclaration( |
3946 name_proxy, scope(), kNoSourcePosition); | 3946 name_proxy, scope(), kNoSourcePosition); |
3947 Variable* name_var = | 3947 Variable* name_var = |
3948 Declare(name_declaration, DeclarationDescriptor::NORMAL, CONST, | 3948 Declare(name_declaration, DeclarationDescriptor::NORMAL, CONST, |
3949 kNeedsInitialization, ok, scope()); | 3949 kNeedsInitialization, ok, scope()); |
3950 DCHECK(ok); | 3950 DCHECK(ok); |
3951 if (!ok) return nullptr; | 3951 if (!ok) return nullptr; |
3952 instance_field_initializers->Add(property->value(), zone()); | 3952 instance_field_initializers->Add(property->value(), zone()); |
3953 property->set_value(factory()->NewVariableProxy(name_var)); | 3953 property->set_value(factory()->NewVariableProxy(name_var)); |
3954 } | 3954 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4015 Assignment* assignment = factory()->NewAssignment( | 4015 Assignment* assignment = factory()->NewAssignment( |
4016 Token::INIT, factory()->NewVariableProxy(init_fn_var), initializer, | 4016 Token::INIT, factory()->NewVariableProxy(init_fn_var), initializer, |
4017 kNoSourcePosition); | 4017 kNoSourcePosition); |
4018 do_block->statements()->Add( | 4018 do_block->statements()->Add( |
4019 factory()->NewExpressionStatement(assignment, kNoSourcePosition), | 4019 factory()->NewExpressionStatement(assignment, kNoSourcePosition), |
4020 zone()); | 4020 zone()); |
4021 } | 4021 } |
4022 for (int i = 0; i < instance_field_initializers->length(); ++i) { | 4022 for (int i = 0; i < instance_field_initializers->length(); ++i) { |
4023 const AstRawString* function_name = | 4023 const AstRawString* function_name = |
4024 ClassFieldVariableName(false, ast_value_factory(), i); | 4024 ClassFieldVariableName(false, ast_value_factory(), i); |
4025 VariableProxy* function_proxy = NewUnresolved(function_name); | 4025 VariableProxy* function_proxy = |
| 4026 factory()->NewVariableProxy(function_name, NORMAL_VARIABLE); |
4026 Declaration* function_declaration = factory()->NewVariableDeclaration( | 4027 Declaration* function_declaration = factory()->NewVariableDeclaration( |
4027 function_proxy, scope(), kNoSourcePosition); | 4028 function_proxy, scope(), kNoSourcePosition); |
4028 Variable* function_var = | 4029 Variable* function_var = |
4029 Declare(function_declaration, DeclarationDescriptor::NORMAL, CONST, | 4030 Declare(function_declaration, DeclarationDescriptor::NORMAL, CONST, |
4030 kNeedsInitialization, ok, scope()); | 4031 kNeedsInitialization, ok, scope()); |
4031 DCHECK(ok); | 4032 DCHECK(ok); |
4032 if (!ok) return nullptr; | 4033 if (!ok) return nullptr; |
4033 Property* prototype_property = factory()->NewProperty( | 4034 Property* prototype_property = factory()->NewProperty( |
4034 factory()->NewVariableProxy(result_var), | 4035 factory()->NewVariableProxy(result_var), |
4035 factory()->NewStringLiteral(ast_value_factory()->prototype_string(), | 4036 factory()->NewStringLiteral(ast_value_factory()->prototype_string(), |
(...skipping 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5808 node->Print(Isolate::Current()); | 5809 node->Print(Isolate::Current()); |
5809 } | 5810 } |
5810 #endif // DEBUG | 5811 #endif // DEBUG |
5811 | 5812 |
5812 #undef CHECK_OK | 5813 #undef CHECK_OK |
5813 #undef CHECK_OK_VOID | 5814 #undef CHECK_OK_VOID |
5814 #undef CHECK_FAILED | 5815 #undef CHECK_FAILED |
5815 | 5816 |
5816 } // namespace internal | 5817 } // namespace internal |
5817 } // namespace v8 | 5818 } // namespace v8 |
OLD | NEW |