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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 // Even though we were passed ParseInfo, we should not store it in | 801 // Even though we were passed ParseInfo, we should not store it in |
802 // Parser - this makes sure that Isolate is not accidentally accessed via | 802 // Parser - this makes sure that Isolate is not accidentally accessed via |
803 // ParseInfo during background parsing. | 803 // ParseInfo during background parsing. |
804 DCHECK(!info->script().is_null() || info->source_stream() != NULL); | 804 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
805 set_allow_lazy(info->allow_lazy_parsing()); | 805 set_allow_lazy(info->allow_lazy_parsing()); |
806 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 806 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
807 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && | 807 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && |
808 info->isolate()->is_tail_call_elimination_enabled()); | 808 info->isolate()->is_tail_call_elimination_enabled()); |
809 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 809 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
810 set_allow_harmony_for_in(FLAG_harmony_for_in); | 810 set_allow_harmony_for_in(FLAG_harmony_for_in); |
811 set_allow_harmony_function_name(FLAG_harmony_function_name); | |
812 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 811 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
813 set_allow_harmony_restrictive_declarations( | 812 set_allow_harmony_restrictive_declarations( |
814 FLAG_harmony_restrictive_declarations); | 813 FLAG_harmony_restrictive_declarations); |
815 set_allow_harmony_exponentiation_operator( | 814 set_allow_harmony_exponentiation_operator( |
816 FLAG_harmony_exponentiation_operator); | 815 FLAG_harmony_exponentiation_operator); |
817 set_allow_harmony_async_await(FLAG_harmony_async_await); | 816 set_allow_harmony_async_await(FLAG_harmony_async_await); |
818 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); | 817 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); |
819 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 818 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
820 ++feature) { | 819 ++feature) { |
821 use_counts_[feature] = 0; | 820 use_counts_[feature] = 0; |
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2437 // Don't infer if it is "a = function(){...}();"-like expression. | 2436 // Don't infer if it is "a = function(){...}();"-like expression. |
2438 if (single_name) { | 2437 if (single_name) { |
2439 if (fni_ != NULL && value->AsCall() == NULL && | 2438 if (fni_ != NULL && value->AsCall() == NULL && |
2440 value->AsCallNew() == NULL) { | 2439 value->AsCallNew() == NULL) { |
2441 fni_->Infer(); | 2440 fni_->Infer(); |
2442 } else { | 2441 } else { |
2443 fni_->RemoveLastFunction(); | 2442 fni_->RemoveLastFunction(); |
2444 } | 2443 } |
2445 } | 2444 } |
2446 | 2445 |
2447 if (allow_harmony_function_name()) { | 2446 ParserTraits::SetFunctionNameFromIdentifierRef(value, pattern); |
2448 ParserTraits::SetFunctionNameFromIdentifierRef(value, pattern); | |
2449 } | |
2450 | 2447 |
2451 // End position of the initializer is after the assignment expression. | 2448 // End position of the initializer is after the assignment expression. |
2452 initializer_position = scanner()->location().end_pos; | 2449 initializer_position = scanner()->location().end_pos; |
2453 } else { | 2450 } else { |
2454 // Initializers may be either required or implied unless this is a | 2451 // Initializers may be either required or implied unless this is a |
2455 // for-in/of iteration variable. | 2452 // for-in/of iteration variable. |
2456 if (var_context != kForStatement || !PeekInOrOf()) { | 2453 if (var_context != kForStatement || !PeekInOrOf()) { |
2457 // ES6 'const' and binding patterns require initializers. | 2454 // ES6 'const' and binding patterns require initializers. |
2458 if (parsing_result->descriptor.mode == CONST || | 2455 if (parsing_result->descriptor.mode == CONST || |
2459 !pattern->IsVariableProxy()) { | 2456 !pattern->IsVariableProxy()) { |
(...skipping 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4868 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 4865 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
4869 | 4866 |
4870 if (reusable_preparser_ == NULL) { | 4867 if (reusable_preparser_ == NULL) { |
4871 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), | 4868 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), |
4872 NULL, stack_limit_); | 4869 NULL, stack_limit_); |
4873 reusable_preparser_->set_allow_lazy(true); | 4870 reusable_preparser_->set_allow_lazy(true); |
4874 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 4871 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
4875 SET_ALLOW(natives); | 4872 SET_ALLOW(natives); |
4876 SET_ALLOW(harmony_do_expressions); | 4873 SET_ALLOW(harmony_do_expressions); |
4877 SET_ALLOW(harmony_for_in); | 4874 SET_ALLOW(harmony_for_in); |
4878 SET_ALLOW(harmony_function_name); | |
4879 SET_ALLOW(harmony_function_sent); | 4875 SET_ALLOW(harmony_function_sent); |
4880 SET_ALLOW(harmony_exponentiation_operator); | 4876 SET_ALLOW(harmony_exponentiation_operator); |
4881 SET_ALLOW(harmony_restrictive_declarations); | 4877 SET_ALLOW(harmony_restrictive_declarations); |
4882 SET_ALLOW(harmony_async_await); | 4878 SET_ALLOW(harmony_async_await); |
4883 #undef SET_ALLOW | 4879 #undef SET_ALLOW |
4884 } | 4880 } |
4885 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4881 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4886 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), | 4882 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), |
4887 parsing_module_, logger, bookmark, use_counts_); | 4883 parsing_module_, logger, bookmark, use_counts_); |
4888 if (pre_parse_timer_ != NULL) { | 4884 if (pre_parse_timer_ != NULL) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4967 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4963 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
4968 DCHECK_NOT_NULL(constructor); | 4964 DCHECK_NOT_NULL(constructor); |
4969 constructor->set_raw_name( | 4965 constructor->set_raw_name( |
4970 name != nullptr ? name : ast_value_factory()->empty_string()); | 4966 name != nullptr ? name : ast_value_factory()->empty_string()); |
4971 } else { | 4967 } else { |
4972 properties->Add(property, zone()); | 4968 properties->Add(property, zone()); |
4973 } | 4969 } |
4974 | 4970 |
4975 if (fni_ != NULL) fni_->Infer(); | 4971 if (fni_ != NULL) fni_->Infer(); |
4976 | 4972 |
4977 if (allow_harmony_function_name() && | 4973 if (property_name != ast_value_factory()->constructor_string()) { |
4978 property_name != ast_value_factory()->constructor_string()) { | |
4979 SetFunctionNameFromPropertyName(property, property_name); | 4974 SetFunctionNameFromPropertyName(property, property_name); |
4980 } | 4975 } |
4981 } | 4976 } |
4982 | 4977 |
4983 Expect(Token::RBRACE, CHECK_OK); | 4978 Expect(Token::RBRACE, CHECK_OK); |
4984 int end_pos = scanner()->location().end_pos; | 4979 int end_pos = scanner()->location().end_pos; |
4985 | 4980 |
4986 if (constructor == NULL) { | 4981 if (constructor == NULL) { |
4987 constructor = DefaultConstructor(name, has_extends, block_scope, pos, | 4982 constructor = DefaultConstructor(name, has_extends, block_scope, pos, |
4988 end_pos, block_scope->language_mode()); | 4983 end_pos, block_scope->language_mode()); |
(...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6564 | 6559 |
6565 statements->Add(get_return, zone); | 6560 statements->Add(get_return, zone); |
6566 statements->Add(check_return, zone); | 6561 statements->Add(check_return, zone); |
6567 statements->Add(call_return, zone); | 6562 statements->Add(call_return, zone); |
6568 statements->Add(validate_output, zone); | 6563 statements->Add(validate_output, zone); |
6569 } | 6564 } |
6570 | 6565 |
6571 void ParserTraits::FinalizeIteratorUse(Variable* completion, | 6566 void ParserTraits::FinalizeIteratorUse(Variable* completion, |
6572 Expression* condition, Variable* iter, | 6567 Expression* condition, Variable* iter, |
6573 Block* iterator_use, Block* target) { | 6568 Block* iterator_use, Block* target) { |
6574 if (!FLAG_harmony_iterator_close) return; | |
6575 | |
6576 // | 6569 // |
6577 // This function adds two statements to [target], corresponding to the | 6570 // This function adds two statements to [target], corresponding to the |
6578 // following code: | 6571 // following code: |
6579 // | 6572 // |
6580 // completion = kNormalCompletion; | 6573 // completion = kNormalCompletion; |
6581 // try { | 6574 // try { |
6582 // try { | 6575 // try { |
6583 // iterator_use | 6576 // iterator_use |
6584 // } catch(e) { | 6577 // } catch(e) { |
6585 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 6578 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6848 call_return_carefully, nopos); | 6841 call_return_carefully, nopos); |
6849 } | 6842 } |
6850 | 6843 |
6851 | 6844 |
6852 statements->Add(get_return, zone); | 6845 statements->Add(get_return, zone); |
6853 statements->Add(maybe_call_return, zone); | 6846 statements->Add(maybe_call_return, zone); |
6854 } | 6847 } |
6855 | 6848 |
6856 | 6849 |
6857 Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop, int pos) { | 6850 Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop, int pos) { |
6858 if (!FLAG_harmony_iterator_close) return loop; | |
6859 | |
6860 // | 6851 // |
6861 // This function replaces the loop with the following wrapping: | 6852 // This function replaces the loop with the following wrapping: |
6862 // | 6853 // |
6863 // let each; | 6854 // let each; |
6864 // let completion = kNormalCompletion; | 6855 // let completion = kNormalCompletion; |
6865 // try { | 6856 // try { |
6866 // try { | 6857 // try { |
6867 // #loop; | 6858 // #loop; |
6868 // } catch(e) { | 6859 // } catch(e) { |
6869 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 6860 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6985 try_block, target); | 6976 try_block, target); |
6986 final_loop = target; | 6977 final_loop = target; |
6987 } | 6978 } |
6988 | 6979 |
6989 return final_loop; | 6980 return final_loop; |
6990 } | 6981 } |
6991 | 6982 |
6992 | 6983 |
6993 } // namespace internal | 6984 } // namespace internal |
6994 } // namespace v8 | 6985 } // namespace v8 |
OLD | NEW |