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-visitor.h" | 9 #include "src/ast/ast-expression-visitor.h" |
10 #include "src/ast/ast-literal-reindexer.h" | 10 #include "src/ast/ast-literal-reindexer.h" |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); | 927 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); |
928 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); | 928 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); |
929 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); | 929 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); |
930 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); | 930 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); |
931 set_allow_harmony_destructuring_bind(FLAG_harmony_destructuring_bind); | 931 set_allow_harmony_destructuring_bind(FLAG_harmony_destructuring_bind); |
932 set_allow_harmony_destructuring_assignment( | 932 set_allow_harmony_destructuring_assignment( |
933 FLAG_harmony_destructuring_assignment); | 933 FLAG_harmony_destructuring_assignment); |
934 set_allow_strong_mode(FLAG_strong_mode); | 934 set_allow_strong_mode(FLAG_strong_mode); |
935 set_allow_legacy_const(FLAG_legacy_const); | 935 set_allow_legacy_const(FLAG_legacy_const); |
936 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 936 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
| 937 set_allow_harmony_function_name(FLAG_harmony_function_name); |
937 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 938 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
938 ++feature) { | 939 ++feature) { |
939 use_counts_[feature] = 0; | 940 use_counts_[feature] = 0; |
940 } | 941 } |
941 if (info->ast_value_factory() == NULL) { | 942 if (info->ast_value_factory() == NULL) { |
942 // info takes ownership of AstValueFactory. | 943 // info takes ownership of AstValueFactory. |
943 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); | 944 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
944 info->set_ast_value_factory_owned(); | 945 info->set_ast_value_factory_owned(); |
945 ast_value_factory_ = info->ast_value_factory(); | 946 ast_value_factory_ = info->ast_value_factory(); |
946 } | 947 } |
(...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2559 | 2560 |
2560 // Don't infer if it is "a = function(){...}();"-like expression. | 2561 // Don't infer if it is "a = function(){...}();"-like expression. |
2561 if (single_name) { | 2562 if (single_name) { |
2562 if (fni_ != NULL && value->AsCall() == NULL && | 2563 if (fni_ != NULL && value->AsCall() == NULL && |
2563 value->AsCallNew() == NULL) { | 2564 value->AsCallNew() == NULL) { |
2564 fni_->Infer(); | 2565 fni_->Infer(); |
2565 } else { | 2566 } else { |
2566 fni_->RemoveLastFunction(); | 2567 fni_->RemoveLastFunction(); |
2567 } | 2568 } |
2568 } | 2569 } |
| 2570 |
| 2571 if (allow_harmony_function_name() && single_name) { |
| 2572 if (value->IsFunctionLiteral()) { |
| 2573 auto function_literal = value->AsFunctionLiteral(); |
| 2574 if (function_literal->is_anonymous()) { |
| 2575 function_literal->set_raw_name(single_name); |
| 2576 } |
| 2577 } else if (value->IsClassLiteral()) { |
| 2578 auto class_literal = value->AsClassLiteral(); |
| 2579 if (class_literal->raw_name() == nullptr) { |
| 2580 class_literal->set_raw_name(single_name); |
| 2581 } |
| 2582 } |
| 2583 } |
| 2584 |
2569 // End position of the initializer is after the assignment expression. | 2585 // End position of the initializer is after the assignment expression. |
2570 initializer_position = scanner()->location().end_pos; | 2586 initializer_position = scanner()->location().end_pos; |
2571 } else { | 2587 } else { |
2572 if ((parsing_result->descriptor.mode == CONST || is_pattern) && | 2588 if ((parsing_result->descriptor.mode == CONST || is_pattern) && |
2573 !is_for_iteration_variable) { | 2589 !is_for_iteration_variable) { |
2574 ParserTraits::ReportMessageAt( | 2590 ParserTraits::ReportMessageAt( |
2575 Scanner::Location(decl_pos, scanner()->location().end_pos), | 2591 Scanner::Location(decl_pos, scanner()->location().end_pos), |
2576 MessageTemplate::kDeclarationMissingInitializer, | 2592 MessageTemplate::kDeclarationMissingInitializer, |
2577 is_pattern ? "destructuring" : "const"); | 2593 is_pattern ? "destructuring" : "const"); |
2578 *ok = false; | 2594 *ok = false; |
(...skipping 2324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4903 reusable_preparser_->set_allow_lazy(true); | 4919 reusable_preparser_->set_allow_lazy(true); |
4904 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 4920 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
4905 SET_ALLOW(natives); | 4921 SET_ALLOW(natives); |
4906 SET_ALLOW(harmony_sloppy); | 4922 SET_ALLOW(harmony_sloppy); |
4907 SET_ALLOW(harmony_sloppy_let); | 4923 SET_ALLOW(harmony_sloppy_let); |
4908 SET_ALLOW(harmony_rest_parameters); | 4924 SET_ALLOW(harmony_rest_parameters); |
4909 SET_ALLOW(harmony_default_parameters); | 4925 SET_ALLOW(harmony_default_parameters); |
4910 SET_ALLOW(harmony_destructuring_bind); | 4926 SET_ALLOW(harmony_destructuring_bind); |
4911 SET_ALLOW(strong_mode); | 4927 SET_ALLOW(strong_mode); |
4912 SET_ALLOW(harmony_do_expressions); | 4928 SET_ALLOW(harmony_do_expressions); |
| 4929 SET_ALLOW(harmony_function_name); |
4913 #undef SET_ALLOW | 4930 #undef SET_ALLOW |
4914 } | 4931 } |
4915 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4932 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4916 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), | 4933 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), |
4917 logger, bookmark); | 4934 logger, bookmark); |
4918 if (pre_parse_timer_ != NULL) { | 4935 if (pre_parse_timer_ != NULL) { |
4919 pre_parse_timer_->Stop(); | 4936 pre_parse_timer_->Stop(); |
4920 } | 4937 } |
4921 return result; | 4938 return result; |
4922 } | 4939 } |
(...skipping 1650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6573 | 6590 |
6574 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { | 6591 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { |
6575 DCHECK(expr->IsRewritableAssignmentExpression()); | 6592 DCHECK(expr->IsRewritableAssignmentExpression()); |
6576 parser_->function_state_->AddDestructuringAssignment( | 6593 parser_->function_state_->AddDestructuringAssignment( |
6577 Parser::DestructuringAssignment(expr, parser_->scope_)); | 6594 Parser::DestructuringAssignment(expr, parser_->scope_)); |
6578 } | 6595 } |
6579 | 6596 |
6580 | 6597 |
6581 } // namespace internal | 6598 } // namespace internal |
6582 } // namespace v8 | 6599 } // namespace v8 |
OLD | NEW |