| 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 905 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 916   fni_->PushEnclosingName(raw_name); | 916   fni_->PushEnclosingName(raw_name); | 
| 917 | 917 | 
| 918   ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 918   ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 
| 919 | 919 | 
| 920   // Place holder for the result. | 920   // Place holder for the result. | 
| 921   FunctionLiteral* result = nullptr; | 921   FunctionLiteral* result = nullptr; | 
| 922 | 922 | 
| 923   { | 923   { | 
| 924     // Parse the function literal. | 924     // Parse the function literal. | 
| 925     Scope* outer = original_scope_; | 925     Scope* outer = original_scope_; | 
|  | 926     DeclarationScope* outer_function = outer->GetClosureScope(); | 
| 926     DCHECK(outer); | 927     DCHECK(outer); | 
| 927     FunctionState function_state(&function_state_, &scope_state_, outer, | 928     FunctionState function_state(&function_state_, &scope_state_, | 
| 928                                  info->function_kind()); | 929                                  outer_function, | 
|  | 930                                  outer_function->function_kind()); | 
|  | 931     BlockState block_state(&scope_state_, outer); | 
| 929     DCHECK(is_sloppy(outer->language_mode()) || | 932     DCHECK(is_sloppy(outer->language_mode()) || | 
| 930            is_strict(info->language_mode())); | 933            is_strict(info->language_mode())); | 
| 931     FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); | 934     FunctionLiteral::FunctionType function_type = ComputeFunctionType(info); | 
| 932     bool ok = true; | 935     bool ok = true; | 
| 933 | 936 | 
| 934     if (info->is_arrow()) { | 937     if (info->is_arrow()) { | 
| 935       bool is_async = allow_harmony_async_await() && info->is_async(); | 938       bool is_async = allow_harmony_async_await() && info->is_async(); | 
| 936       if (is_async) { | 939       if (is_async) { | 
| 937         DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); | 940         DCHECK(!scanner()->HasAnyLineTerminatorAfterNext()); | 
| 938         if (!Check(Token::ASYNC)) { | 941         if (!Check(Token::ASYNC)) { | 
| (...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2919                               FunctionKind::kAsyncFunction, pos, type, | 2922                               FunctionKind::kAsyncFunction, pos, type, | 
| 2920                               language_mode(), CHECK_OK); | 2923                               language_mode(), CHECK_OK); | 
| 2921 } | 2924 } | 
| 2922 | 2925 | 
| 2923 Parser::LazyParsingResult Parser::SkipLazyFunctionBody( | 2926 Parser::LazyParsingResult Parser::SkipLazyFunctionBody( | 
| 2924     int* materialized_literal_count, int* expected_property_count, | 2927     int* materialized_literal_count, int* expected_property_count, | 
| 2925     bool may_abort, bool* ok) { | 2928     bool may_abort, bool* ok) { | 
| 2926   if (produce_cached_parse_data()) CHECK(log_); | 2929   if (produce_cached_parse_data()) CHECK(log_); | 
| 2927 | 2930 | 
| 2928   int function_block_pos = position(); | 2931   int function_block_pos = position(); | 
| 2929   DeclarationScope* scope = this->scope()->AsDeclarationScope(); | 2932   DeclarationScope* scope = function_state_->scope(); | 
| 2930   DCHECK(scope->is_function_scope()); | 2933   DCHECK(scope->is_function_scope()); | 
| 2931   scope->set_is_lazily_parsed(true); | 2934   scope->set_is_lazily_parsed(true); | 
| 2932   if (consume_cached_parse_data() && !cached_parse_data_->rejected()) { | 2935   if (consume_cached_parse_data() && !cached_parse_data_->rejected()) { | 
| 2933     // If we have cached data, we use it to skip parsing the function body. The | 2936     // If we have cached data, we use it to skip parsing the function body. The | 
| 2934     // data contains the information we need to construct the lazy function. | 2937     // data contains the information we need to construct the lazy function. | 
| 2935     FunctionEntry entry = | 2938     FunctionEntry entry = | 
| 2936         cached_parse_data_->GetFunctionEntry(function_block_pos); | 2939         cached_parse_data_->GetFunctionEntry(function_block_pos); | 
| 2937     // Check that cached data is valid. If not, mark it as invalid (the embedder | 2940     // Check that cached data is valid. If not, mark it as invalid (the embedder | 
| 2938     // handles it). Note that end position greater than end of stream is safe, | 2941     // handles it). Note that end position greater than end of stream is safe, | 
| 2939     // and hard to check. | 2942     // and hard to check. | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 2950       if (entry.calls_eval()) scope->RecordEvalCall(); | 2953       if (entry.calls_eval()) scope->RecordEvalCall(); | 
| 2951       return kLazyParsingComplete; | 2954       return kLazyParsingComplete; | 
| 2952     } | 2955     } | 
| 2953     cached_parse_data_->Reject(); | 2956     cached_parse_data_->Reject(); | 
| 2954   } | 2957   } | 
| 2955   // With no cached data, we partially parse the function, without building an | 2958   // With no cached data, we partially parse the function, without building an | 
| 2956   // AST. This gathers the data needed to build a lazy function. | 2959   // AST. This gathers the data needed to build a lazy function. | 
| 2957   SingletonLogger logger; | 2960   SingletonLogger logger; | 
| 2958   PreParser::PreParseResult result = | 2961   PreParser::PreParseResult result = | 
| 2959       ParseLazyFunctionBodyWithPreParser(&logger, may_abort); | 2962       ParseLazyFunctionBodyWithPreParser(&logger, may_abort); | 
|  | 2963 | 
| 2960   // Return immediately if pre-parser decided to abort parsing. | 2964   // Return immediately if pre-parser decided to abort parsing. | 
| 2961   if (result == PreParser::kPreParseAbort) { | 2965   if (result == PreParser::kPreParseAbort) { | 
| 2962     scope->set_is_lazily_parsed(false); | 2966     scope->set_is_lazily_parsed(false); | 
| 2963     return kLazyParsingAborted; | 2967     return kLazyParsingAborted; | 
| 2964   } | 2968   } | 
| 2965   if (result == PreParser::kPreParseStackOverflow) { | 2969   if (result == PreParser::kPreParseStackOverflow) { | 
| 2966     // Propagate stack overflow. | 2970     // Propagate stack overflow. | 
| 2967     set_stack_overflow(); | 2971     set_stack_overflow(); | 
| 2968     *ok = false; | 2972     *ok = false; | 
| 2969     return kLazyParsingComplete; | 2973     return kLazyParsingComplete; | 
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3446     SET_ALLOW(harmony_do_expressions); | 3450     SET_ALLOW(harmony_do_expressions); | 
| 3447     SET_ALLOW(harmony_for_in); | 3451     SET_ALLOW(harmony_for_in); | 
| 3448     SET_ALLOW(harmony_function_sent); | 3452     SET_ALLOW(harmony_function_sent); | 
| 3449     SET_ALLOW(harmony_restrictive_declarations); | 3453     SET_ALLOW(harmony_restrictive_declarations); | 
| 3450     SET_ALLOW(harmony_async_await); | 3454     SET_ALLOW(harmony_async_await); | 
| 3451     SET_ALLOW(harmony_trailing_commas); | 3455     SET_ALLOW(harmony_trailing_commas); | 
| 3452     SET_ALLOW(harmony_class_fields); | 3456     SET_ALLOW(harmony_class_fields); | 
| 3453 #undef SET_ALLOW | 3457 #undef SET_ALLOW | 
| 3454   } | 3458   } | 
| 3455   PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 3459   PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 
| 3456       language_mode(), function_state_->kind(), | 3460       function_state_->scope(), parsing_module_, logger, may_abort, | 
| 3457       scope()->AsDeclarationScope()->has_simple_parameters(), parsing_module_, | 3461       use_counts_); | 
| 3458       logger, may_abort, use_counts_); |  | 
| 3459   if (pre_parse_timer_ != NULL) { | 3462   if (pre_parse_timer_ != NULL) { | 
| 3460     pre_parse_timer_->Stop(); | 3463     pre_parse_timer_->Stop(); | 
| 3461   } | 3464   } | 
| 3462   return result; | 3465   return result; | 
| 3463 } | 3466 } | 
| 3464 | 3467 | 
| 3465 Expression* Parser::InstallHomeObject(Expression* function_literal, | 3468 Expression* Parser::InstallHomeObject(Expression* function_literal, | 
| 3466                                       Expression* home_object) { | 3469                                       Expression* home_object) { | 
| 3467   Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); | 3470   Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); | 
| 3468   Variable* result_var = | 3471   Variable* result_var = | 
| (...skipping 2103 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5572 | 5575 | 
| 5573   return final_loop; | 5576   return final_loop; | 
| 5574 } | 5577 } | 
| 5575 | 5578 | 
| 5576 #undef CHECK_OK | 5579 #undef CHECK_OK | 
| 5577 #undef CHECK_OK_VOID | 5580 #undef CHECK_OK_VOID | 
| 5578 #undef CHECK_FAILED | 5581 #undef CHECK_FAILED | 
| 5579 | 5582 | 
| 5580 }  // namespace internal | 5583 }  // namespace internal | 
| 5581 }  // namespace v8 | 5584 }  // namespace v8 | 
| OLD | NEW | 
|---|