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 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 variable_name = ast_value_factory()->star_default_star_string(); | 1772 variable_name = ast_value_factory()->star_default_star_string(); |
1773 } else { | 1773 } else { |
1774 bool is_strict_reserved; | 1774 bool is_strict_reserved; |
1775 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 1775 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
1776 name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved | 1776 name_validity = is_strict_reserved ? kFunctionNameIsStrictReserved |
1777 : kFunctionNameValidityUnknown; | 1777 : kFunctionNameValidityUnknown; |
1778 variable_name = name; | 1778 variable_name = name; |
1779 } | 1779 } |
1780 | 1780 |
1781 FuncNameInferrer::State fni_state(fni_); | 1781 FuncNameInferrer::State fni_state(fni_); |
1782 if (fni_ != NULL) fni_->PushEnclosingName(name); | 1782 DCHECK_NOT_NULL(fni_); |
| 1783 fni_->PushEnclosingName(name); |
1783 FunctionLiteral* fun = ParseFunctionLiteral( | 1784 FunctionLiteral* fun = ParseFunctionLiteral( |
1784 name, scanner()->location(), name_validity, | 1785 name, scanner()->location(), name_validity, |
1785 is_generator ? FunctionKind::kGeneratorFunction | 1786 is_generator ? FunctionKind::kGeneratorFunction |
1786 : is_async ? FunctionKind::kAsyncFunction | 1787 : is_async ? FunctionKind::kAsyncFunction |
1787 : FunctionKind::kNormalFunction, | 1788 : FunctionKind::kNormalFunction, |
1788 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); | 1789 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
1789 | 1790 |
1790 // In ES6, a function behaves as a lexical binding, except in | 1791 // In ES6, a function behaves as a lexical binding, except in |
1791 // a script scope, or the initial scope of eval or another function. | 1792 // a script scope, or the initial scope of eval or another function. |
1792 VariableMode mode = | 1793 VariableMode mode = |
(...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3898 | 3899 |
3899 // Note that the FunctionLiteral needs to be created in the main Zone again. | 3900 // Note that the FunctionLiteral needs to be created in the main Zone again. |
3900 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 3901 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
3901 function_name, main_scope, body, materialized_literal_count, | 3902 function_name, main_scope, body, materialized_literal_count, |
3902 expected_property_count, arity, duplicate_parameters, function_type, | 3903 expected_property_count, arity, duplicate_parameters, function_type, |
3903 eager_compile_hint, kind, pos); | 3904 eager_compile_hint, kind, pos); |
3904 function_literal->set_function_token_position(function_token_pos); | 3905 function_literal->set_function_token_position(function_token_pos); |
3905 if (should_be_used_once_hint) | 3906 if (should_be_used_once_hint) |
3906 function_literal->set_should_be_used_once_hint(); | 3907 function_literal->set_should_be_used_once_hint(); |
3907 | 3908 |
3908 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 3909 if (should_infer_name) { |
| 3910 DCHECK_NOT_NULL(fni_); |
| 3911 fni_->AddFunction(function_literal); |
| 3912 } |
3909 return function_literal; | 3913 return function_literal; |
3910 } | 3914 } |
3911 | 3915 |
3912 Expression* Parser::ParseAsyncFunctionExpression(bool* ok) { | 3916 Expression* Parser::ParseAsyncFunctionExpression(bool* ok) { |
3913 // AsyncFunctionDeclaration :: | 3917 // AsyncFunctionDeclaration :: |
3914 // async [no LineTerminator here] function ( FormalParameters[Await] ) | 3918 // async [no LineTerminator here] function ( FormalParameters[Await] ) |
3915 // { AsyncFunctionBody } | 3919 // { AsyncFunctionBody } |
3916 // | 3920 // |
3917 // async [no LineTerminator here] function BindingIdentifier[Await] | 3921 // async [no LineTerminator here] function BindingIdentifier[Await] |
3918 // ( FormalParameters[Await] ) { AsyncFunctionBody } | 3922 // ( FormalParameters[Await] ) { AsyncFunctionBody } |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4561 | 4565 |
4562 if (has_seen_constructor && constructor == nullptr) { | 4566 if (has_seen_constructor && constructor == nullptr) { |
4563 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4567 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
4564 DCHECK_NOT_NULL(constructor); | 4568 DCHECK_NOT_NULL(constructor); |
4565 constructor->set_raw_name( | 4569 constructor->set_raw_name( |
4566 name != nullptr ? name : ast_value_factory()->empty_string()); | 4570 name != nullptr ? name : ast_value_factory()->empty_string()); |
4567 } else { | 4571 } else { |
4568 properties->Add(property, zone()); | 4572 properties->Add(property, zone()); |
4569 } | 4573 } |
4570 | 4574 |
4571 if (fni_ != nullptr) fni_->Infer(); | 4575 DCHECK_NOT_NULL(fni_); |
| 4576 fni_->Infer(); |
4572 | 4577 |
4573 if (property_name != ast_value_factory()->constructor_string()) { | 4578 if (property_name != ast_value_factory()->constructor_string()) { |
4574 SetFunctionNameFromPropertyName(property, property_name); | 4579 SetFunctionNameFromPropertyName(property, property_name); |
4575 } | 4580 } |
4576 } | 4581 } |
4577 | 4582 |
4578 Expect(Token::RBRACE, CHECK_OK); | 4583 Expect(Token::RBRACE, CHECK_OK); |
4579 int end_pos = scanner()->location().end_pos; | 4584 int end_pos = scanner()->location().end_pos; |
4580 | 4585 |
4581 if (constructor == nullptr) { | 4586 if (constructor == nullptr) { |
(...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6490 node->Print(Isolate::Current()); | 6495 node->Print(Isolate::Current()); |
6491 } | 6496 } |
6492 #endif // DEBUG | 6497 #endif // DEBUG |
6493 | 6498 |
6494 #undef CHECK_OK | 6499 #undef CHECK_OK |
6495 #undef CHECK_OK_VOID | 6500 #undef CHECK_OK_VOID |
6496 #undef CHECK_FAILED | 6501 #undef CHECK_FAILED |
6497 | 6502 |
6498 } // namespace internal | 6503 } // namespace internal |
6499 } // namespace v8 | 6504 } // namespace v8 |
OLD | NEW |