Chromium Code Reviews| 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 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2762 *materialized_literal_count = entry.literal_count(); | 2762 *materialized_literal_count = entry.literal_count(); |
| 2763 *expected_property_count = entry.property_count(); | 2763 *expected_property_count = entry.property_count(); |
| 2764 SetLanguageMode(function_scope, entry.language_mode()); | 2764 SetLanguageMode(function_scope, entry.language_mode()); |
| 2765 if (entry.uses_super_property()) | 2765 if (entry.uses_super_property()) |
| 2766 function_scope->RecordSuperPropertyUsage(); | 2766 function_scope->RecordSuperPropertyUsage(); |
| 2767 if (entry.calls_eval()) function_scope->RecordEvalCall(); | 2767 if (entry.calls_eval()) function_scope->RecordEvalCall(); |
| 2768 return kLazyParsingComplete; | 2768 return kLazyParsingComplete; |
| 2769 } | 2769 } |
| 2770 cached_parse_data_->Reject(); | 2770 cached_parse_data_->Reject(); |
| 2771 } | 2771 } |
| 2772 | |
| 2772 // With no cached data, we partially parse the function, without building an | 2773 // With no cached data, we partially parse the function, without building an |
| 2773 // AST. This gathers the data needed to build a lazy function. | 2774 // AST. This gathers the data needed to build a lazy function. |
| 2774 PreParser::PreParseResult result = ParseFunctionWithPreParser( | 2775 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); |
|
vogelheim
2016/11/15 16:14:10
This is a scope, and will now cover a somewhat lar
| |
| 2775 kind, function_scope, is_inner_function, may_abort); | 2776 |
| 2777 if (reusable_preparser_ == NULL) { | |
| 2778 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), | |
| 2779 &pending_error_handler_, stack_limit_); | |
| 2780 reusable_preparser_->set_allow_lazy(true); | |
| 2781 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | |
| 2782 SET_ALLOW(natives); | |
| 2783 SET_ALLOW(harmony_do_expressions); | |
| 2784 SET_ALLOW(harmony_function_sent); | |
| 2785 SET_ALLOW(harmony_async_await); | |
| 2786 SET_ALLOW(harmony_trailing_commas); | |
| 2787 SET_ALLOW(harmony_class_fields); | |
| 2788 #undef SET_ALLOW | |
| 2789 } | |
| 2790 // Aborting inner function preparsing would leave scopes in an inconsistent | |
| 2791 // state; we don't parse inner functions in the abortable mode anyway. | |
| 2792 DCHECK(!is_inner_function || !may_abort); | |
| 2793 | |
| 2794 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( | |
| 2795 kind, function_scope, parsing_module_, is_inner_function, may_abort, | |
| 2796 use_counts_); | |
| 2776 | 2797 |
| 2777 // Return immediately if pre-parser decided to abort parsing. | 2798 // Return immediately if pre-parser decided to abort parsing. |
| 2778 if (result == PreParser::kPreParseAbort) return kLazyParsingAborted; | 2799 if (result == PreParser::kPreParseAbort) return kLazyParsingAborted; |
| 2779 if (result == PreParser::kPreParseStackOverflow) { | 2800 if (result == PreParser::kPreParseStackOverflow) { |
| 2780 // Propagate stack overflow. | 2801 // Propagate stack overflow. |
| 2781 set_stack_overflow(); | 2802 set_stack_overflow(); |
| 2782 *ok = false; | 2803 *ok = false; |
| 2783 return kLazyParsingComplete; | 2804 return kLazyParsingComplete; |
| 2784 } | 2805 } |
| 2785 if (pending_error_handler_.has_pending_error()) { | 2806 if (pending_error_handler_.has_pending_error()) { |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3270 } else { | 3291 } else { |
| 3271 statement = factory()->NewEmptyStatement(kNoSourcePosition); | 3292 statement = factory()->NewEmptyStatement(kNoSourcePosition); |
| 3272 } | 3293 } |
| 3273 result->Set(kFunctionNameAssignmentIndex, statement); | 3294 result->Set(kFunctionNameAssignmentIndex, statement); |
| 3274 } | 3295 } |
| 3275 | 3296 |
| 3276 MarkCollectedTailCallExpressions(); | 3297 MarkCollectedTailCallExpressions(); |
| 3277 return result; | 3298 return result; |
| 3278 } | 3299 } |
| 3279 | 3300 |
| 3280 PreParser::PreParseResult Parser::ParseFunctionWithPreParser( | |
| 3281 FunctionKind kind, DeclarationScope* function_scope, bool is_inner_function, | |
| 3282 bool may_abort) { | |
| 3283 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); | |
| 3284 | |
| 3285 if (reusable_preparser_ == NULL) { | |
| 3286 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), | |
| 3287 &pending_error_handler_, stack_limit_); | |
| 3288 reusable_preparser_->set_allow_lazy(true); | |
| 3289 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | |
| 3290 SET_ALLOW(natives); | |
| 3291 SET_ALLOW(harmony_do_expressions); | |
| 3292 SET_ALLOW(harmony_function_sent); | |
| 3293 SET_ALLOW(harmony_async_await); | |
| 3294 SET_ALLOW(harmony_trailing_commas); | |
| 3295 SET_ALLOW(harmony_class_fields); | |
| 3296 #undef SET_ALLOW | |
| 3297 } | |
| 3298 // Aborting inner function preparsing would leave scopes in an inconsistent | |
| 3299 // state; we don't parse inner functions in the abortable mode anyway. | |
| 3300 DCHECK(!is_inner_function || !may_abort); | |
| 3301 | |
| 3302 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( | |
| 3303 kind, function_scope, parsing_module_, is_inner_function, may_abort, | |
| 3304 use_counts_); | |
| 3305 return result; | |
| 3306 } | |
| 3307 | |
| 3308 Expression* Parser::InstallHomeObject(Expression* function_literal, | 3301 Expression* Parser::InstallHomeObject(Expression* function_literal, |
| 3309 Expression* home_object) { | 3302 Expression* home_object) { |
| 3310 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); | 3303 Block* do_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); |
| 3311 Variable* result_var = | 3304 Variable* result_var = |
| 3312 scope()->NewTemporary(ast_value_factory()->empty_string()); | 3305 scope()->NewTemporary(ast_value_factory()->empty_string()); |
| 3313 DoExpression* do_expr = | 3306 DoExpression* do_expr = |
| 3314 factory()->NewDoExpression(do_block, result_var, kNoSourcePosition); | 3307 factory()->NewDoExpression(do_block, result_var, kNoSourcePosition); |
| 3315 Assignment* init = factory()->NewAssignment( | 3308 Assignment* init = factory()->NewAssignment( |
| 3316 Token::ASSIGN, factory()->NewVariableProxy(result_var), function_literal, | 3309 Token::ASSIGN, factory()->NewVariableProxy(result_var), function_literal, |
| 3317 kNoSourcePosition); | 3310 kNoSourcePosition); |
| (...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5412 | 5405 |
| 5413 return final_loop; | 5406 return final_loop; |
| 5414 } | 5407 } |
| 5415 | 5408 |
| 5416 #undef CHECK_OK | 5409 #undef CHECK_OK |
| 5417 #undef CHECK_OK_VOID | 5410 #undef CHECK_OK_VOID |
| 5418 #undef CHECK_FAILED | 5411 #undef CHECK_FAILED |
| 5419 | 5412 |
| 5420 } // namespace internal | 5413 } // namespace internal |
| 5421 } // namespace v8 | 5414 } // namespace v8 |
| OLD | NEW |