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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 fni_->PushEnclosingName(raw_name); | 922 fni_->PushEnclosingName(raw_name); |
923 | 923 |
924 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 924 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
925 | 925 |
926 // Place holder for the result. | 926 // Place holder for the result. |
927 FunctionLiteral* result = nullptr; | 927 FunctionLiteral* result = nullptr; |
928 | 928 |
929 { | 929 { |
930 // Parse the function literal. | 930 // Parse the function literal. |
931 Scope* outer = original_scope_; | 931 Scope* outer = original_scope_; |
932 DeclarationScope* outer_function = outer->GetClosureScope(); | |
933 DCHECK(outer); | 932 DCHECK(outer); |
934 FunctionState function_state(&function_state_, &scope_state_, | 933 FunctionState function_state(&function_state_, &scope_state_, outer, |
935 outer_function, | 934 info->function_kind()); |
936 outer_function->function_kind()); | |
937 BlockState block_state(&scope_state_, outer); | |
938 DCHECK(is_sloppy(outer->language_mode()) || | 935 DCHECK(is_sloppy(outer->language_mode()) || |
939 is_strict(info->language_mode())); | 936 is_strict(info->language_mode())); |
940 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); | 937 FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); |
941 bool ok = true; | 938 bool ok = true; |
942 | 939 |
943 if (info->is_arrow()) { | 940 if (info->is_arrow()) { |
944 bool is_async = allow_harmony_async_await() && info->is_async(); | 941 bool is_async = allow_harmony_async_await() && info->is_async(); |
945 if (is_async) { | 942 if (is_async) { |
946 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); | 943 DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); |
947 if (!Check(Token::ASYNC)) { | 944 if (!Check(Token::ASYNC)) { |
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2936 FunctionKind::kAsyncFunction, pos, type, | 2933 FunctionKind::kAsyncFunction, pos, type, |
2937 language_mode(), CHECK_OK); | 2934 language_mode(), CHECK_OK); |
2938 } | 2935 } |
2939 | 2936 |
2940 Parser::LazyParsingResult Parser::SkipLazyFunctionBody( | 2937 Parser::LazyParsingResult Parser::SkipLazyFunctionBody( |
2941 int* materialized_literal_count, int* expected_property_count, | 2938 int* materialized_literal_count, int* expected_property_count, |
2942 bool is_inner_function, bool may_abort, bool* ok) { | 2939 bool is_inner_function, bool may_abort, bool* ok) { |
2943 if (produce_cached_parse_data()) CHECK(log_); | 2940 if (produce_cached_parse_data()) CHECK(log_); |
2944 | 2941 |
2945 int function_block_pos = position(); | 2942 int function_block_pos = position(); |
2946 DeclarationScope* scope = function_state_->scope(); | 2943 DeclarationScope* scope = this->scope()->AsDeclarationScope(); |
2947 DCHECK(scope->is_function_scope()); | 2944 DCHECK(scope->is_function_scope()); |
2948 scope->set_is_lazily_parsed(true); | 2945 scope->set_is_lazily_parsed(true); |
2949 // Inner functions are not part of the cached data. | 2946 // Inner functions are not part of the cached data. |
2950 if (!is_inner_function && consume_cached_parse_data() && | 2947 if (!is_inner_function && consume_cached_parse_data() && |
2951 !cached_parse_data_->rejected()) { | 2948 !cached_parse_data_->rejected()) { |
2952 // If we have cached data, we use it to skip parsing the function body. The | 2949 // If we have cached data, we use it to skip parsing the function body. The |
2953 // data contains the information we need to construct the lazy function. | 2950 // data contains the information we need to construct the lazy function. |
2954 FunctionEntry entry = | 2951 FunctionEntry entry = |
2955 cached_parse_data_->GetFunctionEntry(function_block_pos); | 2952 cached_parse_data_->GetFunctionEntry(function_block_pos); |
2956 // Check that cached data is valid. If not, mark it as invalid (the embedder | 2953 // Check that cached data is valid. If not, mark it as invalid (the embedder |
(...skipping 12 matching lines...) Expand all Loading... |
2969 if (entry.calls_eval()) scope->RecordEvalCall(); | 2966 if (entry.calls_eval()) scope->RecordEvalCall(); |
2970 return kLazyParsingComplete; | 2967 return kLazyParsingComplete; |
2971 } | 2968 } |
2972 cached_parse_data_->Reject(); | 2969 cached_parse_data_->Reject(); |
2973 } | 2970 } |
2974 // With no cached data, we partially parse the function, without building an | 2971 // With no cached data, we partially parse the function, without building an |
2975 // AST. This gathers the data needed to build a lazy function. | 2972 // AST. This gathers the data needed to build a lazy function. |
2976 SingletonLogger logger; | 2973 SingletonLogger logger; |
2977 PreParser::PreParseResult result = | 2974 PreParser::PreParseResult result = |
2978 ParseLazyFunctionBodyWithPreParser(&logger, is_inner_function, may_abort); | 2975 ParseLazyFunctionBodyWithPreParser(&logger, is_inner_function, may_abort); |
2979 | |
2980 // Return immediately if pre-parser decided to abort parsing. | 2976 // Return immediately if pre-parser decided to abort parsing. |
2981 if (result == PreParser::kPreParseAbort) { | 2977 if (result == PreParser::kPreParseAbort) { |
2982 scope->set_is_lazily_parsed(false); | 2978 scope->set_is_lazily_parsed(false); |
2983 return kLazyParsingAborted; | 2979 return kLazyParsingAborted; |
2984 } | 2980 } |
2985 if (result == PreParser::kPreParseStackOverflow) { | 2981 if (result == PreParser::kPreParseStackOverflow) { |
2986 // Propagate stack overflow. | 2982 // Propagate stack overflow. |
2987 set_stack_overflow(); | 2983 set_stack_overflow(); |
2988 *ok = false; | 2984 *ok = false; |
2989 return kLazyParsingComplete; | 2985 return kLazyParsingComplete; |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3471 SET_ALLOW(harmony_restrictive_declarations); | 3467 SET_ALLOW(harmony_restrictive_declarations); |
3472 SET_ALLOW(harmony_async_await); | 3468 SET_ALLOW(harmony_async_await); |
3473 SET_ALLOW(harmony_trailing_commas); | 3469 SET_ALLOW(harmony_trailing_commas); |
3474 SET_ALLOW(harmony_class_fields); | 3470 SET_ALLOW(harmony_class_fields); |
3475 #undef SET_ALLOW | 3471 #undef SET_ALLOW |
3476 } | 3472 } |
3477 // Aborting inner function preparsing would leave scopes in an inconsistent | 3473 // Aborting inner function preparsing would leave scopes in an inconsistent |
3478 // state; we don't parse inner functions in the abortable mode anyway. | 3474 // state; we don't parse inner functions in the abortable mode anyway. |
3479 DCHECK(!is_inner_function || !may_abort); | 3475 DCHECK(!is_inner_function || !may_abort); |
3480 | 3476 |
3481 DeclarationScope* function_scope = function_state_->scope(); | 3477 FunctionKind kind = function_state_->kind(); |
3482 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 3478 PreParser::PreParseResult result; |
3483 function_scope, parsing_module_, logger, is_inner_function, may_abort, | 3479 if (!is_inner_function) { |
3484 use_counts_); | 3480 // If we don't need to look at the scope, construct a dummy scope chain |
3485 // Detaching the scopes created by PreParser from the Scope chain must be done | 3481 // which is not connected to the real scope chain. |
3486 // above (see ParseFunctionLiteral & AnalyzePartially). | 3482 LanguageMode mode = language_mode(); |
3487 if (!is_inner_function) function_scope->ResetAfterPreparsing(); | 3483 bool has_simple_parameters = |
| 3484 scope()->AsDeclarationScope()->has_simple_parameters(); |
| 3485 DeclarationScope* top_scope = NewScriptScope(); |
| 3486 top_scope->SetLanguageMode(mode); |
| 3487 FunctionState top_state(&function_state_, &scope_state_, top_scope, |
| 3488 kNormalFunction); |
| 3489 DeclarationScope* function_scope = NewFunctionScope(kind); |
| 3490 if (!has_simple_parameters) { |
| 3491 function_scope->SetHasNonSimpleParameters(); |
| 3492 } |
| 3493 result = reusable_preparser_->PreParseLazyFunction( |
| 3494 kind, function_scope, parsing_module_, logger, is_inner_function, |
| 3495 may_abort, use_counts_); |
| 3496 } else { |
| 3497 // Detaching the scopes created by PreParser from the Scope chain must be |
| 3498 // done above (see ParseFunctionLiteral & AnalyzePartially). |
| 3499 result = reusable_preparser_->PreParseLazyFunction( |
| 3500 kind, scope()->AsDeclarationScope(), parsing_module_, logger, |
| 3501 is_inner_function, may_abort, use_counts_); |
| 3502 } |
3488 if (pre_parse_timer_ != NULL) { | 3503 if (pre_parse_timer_ != NULL) { |
3489 pre_parse_timer_->Stop(); | 3504 pre_parse_timer_->Stop(); |
3490 } | 3505 } |
3491 return result; | 3506 return result; |
3492 } | 3507 } |
3493 | 3508 |
3494 Expression* Parser::InstallHomeObject(Expression* function_literal, | 3509 Expression* Parser::InstallHomeObject(Expression* function_literal, |
3495 Expression* home_object) { | 3510 Expression* home_object) { |
3496 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); | 3511 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); |
3497 Variable* result_var = | 3512 Variable* result_var = |
(...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5601 | 5616 |
5602 return final_loop; | 5617 return final_loop; |
5603 } | 5618 } |
5604 | 5619 |
5605 #undef CHECK_OK | 5620 #undef CHECK_OK |
5606 #undef CHECK_OK_VOID | 5621 #undef CHECK_OK_VOID |
5607 #undef CHECK_FAILED | 5622 #undef CHECK_FAILED |
5608 | 5623 |
5609 } // namespace internal | 5624 } // namespace internal |
5610 } // namespace v8 | 5625 } // namespace v8 |
OLD | NEW |