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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 ReportMessage(MessageTemplate::kNotDefined, name); | 579 ReportMessage(MessageTemplate::kNotDefined, name); |
580 *ok = false; | 580 *ok = false; |
581 return nullptr; | 581 return nullptr; |
582 } | 582 } |
583 | 583 |
584 return factory()->NewCallRuntime(context_index, args, pos); | 584 return factory()->NewCallRuntime(context_index, args, pos); |
585 } | 585 } |
586 | 586 |
587 Parser::Parser(ParseInfo* info) | 587 Parser::Parser(ParseInfo* info) |
588 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), | 588 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), |
589 info->extension(), info->ast_value_factory(), NULL), | 589 info->extension(), info->ast_value_factory()), |
590 scanner_(info->unicode_cache()), | 590 scanner_(info->unicode_cache()), |
591 reusable_preparser_(NULL), | 591 reusable_preparser_(nullptr), |
592 original_scope_(NULL), | 592 original_scope_(nullptr), |
593 target_stack_(NULL), | 593 target_stack_(nullptr), |
594 compile_options_(info->compile_options()), | 594 compile_options_(info->compile_options()), |
595 cached_parse_data_(nullptr), | 595 cached_parse_data_(nullptr), |
596 total_preparse_skipped_(0), | 596 total_preparse_skipped_(0), |
597 parsing_on_main_thread_(true) { | 597 parsing_on_main_thread_(true), |
598 log_(nullptr) { | |
598 // Even though we were passed ParseInfo, we should not store it in | 599 // Even though we were passed ParseInfo, we should not store it in |
599 // Parser - this makes sure that Isolate is not accidentally accessed via | 600 // Parser - this makes sure that Isolate is not accidentally accessed via |
600 // ParseInfo during background parsing. | 601 // ParseInfo during background parsing. |
601 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 602 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
602 info->character_stream() != nullptr); | 603 info->character_stream() != nullptr); |
603 // Determine if functions can be lazily compiled. This is necessary to | 604 // Determine if functions can be lazily compiled. This is necessary to |
604 // allow some of our builtin JS files to be lazily compiled. These | 605 // allow some of our builtin JS files to be lazily compiled. These |
605 // builtins cannot be handled lazily by the parser, since we have to know | 606 // builtins cannot be handled lazily by the parser, since we have to know |
606 // if a function uses the special natives syntax, which is something the | 607 // if a function uses the special natives syntax, which is something the |
607 // parser records. | 608 // parser records. |
(...skipping 2161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2769 SetLanguageMode(function_scope, entry.language_mode()); | 2770 SetLanguageMode(function_scope, entry.language_mode()); |
2770 if (entry.uses_super_property()) | 2771 if (entry.uses_super_property()) |
2771 function_scope->RecordSuperPropertyUsage(); | 2772 function_scope->RecordSuperPropertyUsage(); |
2772 if (entry.calls_eval()) function_scope->RecordEvalCall(); | 2773 if (entry.calls_eval()) function_scope->RecordEvalCall(); |
2773 return kLazyParsingComplete; | 2774 return kLazyParsingComplete; |
2774 } | 2775 } |
2775 cached_parse_data_->Reject(); | 2776 cached_parse_data_->Reject(); |
2776 } | 2777 } |
2777 // With no cached data, we partially parse the function, without building an | 2778 // With no cached data, we partially parse the function, without building an |
2778 // AST. This gathers the data needed to build a lazy function. | 2779 // AST. This gathers the data needed to build a lazy function. |
2779 SingletonLogger logger; | |
2780 PreParser::PreParseResult result = ParseFunctionWithPreParser( | 2780 PreParser::PreParseResult result = ParseFunctionWithPreParser( |
2781 kind, function_scope, &logger, is_inner_function, may_abort); | 2781 kind, function_scope, is_inner_function, may_abort); |
2782 | 2782 |
2783 // Return immediately if pre-parser decided to abort parsing. | 2783 // Return immediately if pre-parser decided to abort parsing. |
2784 if (result == PreParser::kPreParseAbort) return kLazyParsingAborted; | 2784 if (result == PreParser::kPreParseAbort) return kLazyParsingAborted; |
2785 if (result == PreParser::kPreParseStackOverflow) { | 2785 if (result == PreParser::kPreParseStackOverflow) { |
2786 // Propagate stack overflow. | 2786 // Propagate stack overflow. |
2787 set_stack_overflow(); | 2787 set_stack_overflow(); |
2788 *ok = false; | 2788 *ok = false; |
2789 return kLazyParsingComplete; | 2789 return kLazyParsingComplete; |
2790 } | 2790 } |
2791 if (logger.has_error()) { | 2791 SingletonLogger* logger = reusable_preparser_->logger(); |
marja
2016/11/04 14:47:06
It's kinda meh that we now don't pass the logger i
| |
2792 ReportMessageAt(Scanner::Location(logger.start(), logger.end()), | 2792 if (logger->has_error()) { |
2793 logger.message(), logger.argument_opt(), | 2793 ReportMessageAt(Scanner::Location(logger->start(), logger->end()), |
2794 logger.error_type()); | 2794 logger->message(), logger->argument_opt(), |
2795 logger->error_type()); | |
2795 *ok = false; | 2796 *ok = false; |
2796 return kLazyParsingComplete; | 2797 return kLazyParsingComplete; |
2797 } | 2798 } |
2798 function_scope->set_end_position(logger.end()); | 2799 function_scope->set_end_position(logger->end()); |
2799 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); | 2800 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); |
2800 total_preparse_skipped_ += | 2801 total_preparse_skipped_ += |
2801 function_scope->end_position() - function_scope->start_position(); | 2802 function_scope->end_position() - function_scope->start_position(); |
2802 *num_parameters = logger.num_parameters(); | 2803 *num_parameters = logger->num_parameters(); |
2803 *function_length = logger.function_length(); | 2804 *function_length = logger->function_length(); |
2804 *has_duplicate_parameters = logger.has_duplicate_parameters(); | 2805 *has_duplicate_parameters = logger->has_duplicate_parameters(); |
2805 *materialized_literal_count = logger.literals(); | 2806 *materialized_literal_count = logger->literals(); |
2806 *expected_property_count = logger.properties(); | 2807 *expected_property_count = logger->properties(); |
2807 SetLanguageMode(function_scope, logger.language_mode()); | 2808 SetLanguageMode(function_scope, logger->language_mode()); |
2808 if (logger.uses_super_property()) function_scope->RecordSuperPropertyUsage(); | 2809 if (logger->uses_super_property()) function_scope->RecordSuperPropertyUsage(); |
2809 if (logger.calls_eval()) function_scope->RecordEvalCall(); | 2810 if (logger->calls_eval()) function_scope->RecordEvalCall(); |
2810 if (!is_inner_function && produce_cached_parse_data()) { | 2811 if (!is_inner_function && produce_cached_parse_data()) { |
2811 DCHECK(log_); | 2812 DCHECK(log_); |
2812 log_->LogFunction( | 2813 log_->LogFunction( |
2813 function_scope->start_position(), function_scope->end_position(), | 2814 function_scope->start_position(), function_scope->end_position(), |
2814 *num_parameters, *function_length, *has_duplicate_parameters, | 2815 *num_parameters, *function_length, *has_duplicate_parameters, |
2815 *materialized_literal_count, *expected_property_count, language_mode(), | 2816 *materialized_literal_count, *expected_property_count, language_mode(), |
2816 function_scope->uses_super_property(), function_scope->calls_eval()); | 2817 function_scope->uses_super_property(), function_scope->calls_eval()); |
2817 } | 2818 } |
2818 return kLazyParsingComplete; | 2819 return kLazyParsingComplete; |
2819 } | 2820 } |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3282 statement = factory()->NewEmptyStatement(kNoSourcePosition); | 3283 statement = factory()->NewEmptyStatement(kNoSourcePosition); |
3283 } | 3284 } |
3284 result->Set(kFunctionNameAssignmentIndex, statement); | 3285 result->Set(kFunctionNameAssignmentIndex, statement); |
3285 } | 3286 } |
3286 | 3287 |
3287 MarkCollectedTailCallExpressions(); | 3288 MarkCollectedTailCallExpressions(); |
3288 return result; | 3289 return result; |
3289 } | 3290 } |
3290 | 3291 |
3291 PreParser::PreParseResult Parser::ParseFunctionWithPreParser( | 3292 PreParser::PreParseResult Parser::ParseFunctionWithPreParser( |
3292 FunctionKind kind, DeclarationScope* function_scope, | 3293 FunctionKind kind, DeclarationScope* function_scope, bool is_inner_function, |
3293 SingletonLogger* logger, bool is_inner_function, bool may_abort) { | 3294 bool may_abort) { |
3294 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); | 3295 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); |
3295 | 3296 |
3296 if (reusable_preparser_ == NULL) { | 3297 if (reusable_preparser_ == NULL) { |
3297 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), | 3298 reusable_preparser_ = |
3298 NULL, stack_limit_); | 3299 new PreParser(zone(), &scanner_, ast_value_factory(), stack_limit_); |
3299 reusable_preparser_->set_allow_lazy(true); | 3300 reusable_preparser_->set_allow_lazy(true); |
3300 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 3301 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
3301 SET_ALLOW(natives); | 3302 SET_ALLOW(natives); |
3302 SET_ALLOW(harmony_do_expressions); | 3303 SET_ALLOW(harmony_do_expressions); |
3303 SET_ALLOW(harmony_function_sent); | 3304 SET_ALLOW(harmony_function_sent); |
3304 SET_ALLOW(harmony_restrictive_declarations); | 3305 SET_ALLOW(harmony_restrictive_declarations); |
3305 SET_ALLOW(harmony_async_await); | 3306 SET_ALLOW(harmony_async_await); |
3306 SET_ALLOW(harmony_trailing_commas); | 3307 SET_ALLOW(harmony_trailing_commas); |
3307 SET_ALLOW(harmony_class_fields); | 3308 SET_ALLOW(harmony_class_fields); |
3308 #undef SET_ALLOW | 3309 #undef SET_ALLOW |
3309 } | 3310 } |
3310 // Aborting inner function preparsing would leave scopes in an inconsistent | 3311 // Aborting inner function preparsing would leave scopes in an inconsistent |
3311 // state; we don't parse inner functions in the abortable mode anyway. | 3312 // state; we don't parse inner functions in the abortable mode anyway. |
3312 DCHECK(!is_inner_function || !may_abort); | 3313 DCHECK(!is_inner_function || !may_abort); |
3313 | 3314 |
3314 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( | 3315 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( |
3315 kind, function_scope, parsing_module_, logger, is_inner_function, | 3316 kind, function_scope, parsing_module_, is_inner_function, may_abort, |
3316 may_abort, use_counts_); | 3317 use_counts_); |
3317 return result; | 3318 return result; |
3318 } | 3319 } |
3319 | 3320 |
3320 Expression* Parser::InstallHomeObject(Expression* function_literal, | 3321 Expression* Parser::InstallHomeObject(Expression* function_literal, |
3321 Expression* home_object) { | 3322 Expression* home_object) { |
3322 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); | 3323 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); |
3323 Variable* result_var = | 3324 Variable* result_var = |
3324 scope()->NewTemporary(ast_value_factory()->empty_string()); | 3325 scope()->NewTemporary(ast_value_factory()->empty_string()); |
3325 DoExpression* do_expr = | 3326 DoExpression* do_expr = |
3326 factory()->NewDoExpression(do_block, result_var, kNoSourcePosition); | 3327 factory()->NewDoExpression(do_block, result_var, kNoSourcePosition); |
(...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5423 | 5424 |
5424 return final_loop; | 5425 return final_loop; |
5425 } | 5426 } |
5426 | 5427 |
5427 #undef CHECK_OK | 5428 #undef CHECK_OK |
5428 #undef CHECK_OK_VOID | 5429 #undef CHECK_OK_VOID |
5429 #undef CHECK_FAILED | 5430 #undef CHECK_FAILED |
5430 | 5431 |
5431 } // namespace internal | 5432 } // namespace internal |
5432 } // namespace v8 | 5433 } // namespace v8 |
OLD | NEW |