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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 | 278 |
279 materialized_literal_count = function_state.materialized_literal_count(); | 279 materialized_literal_count = function_state.materialized_literal_count(); |
280 expected_property_count = function_state.expected_property_count(); | 280 expected_property_count = function_state.expected_property_count(); |
281 } | 281 } |
282 | 282 |
283 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 283 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
284 name, function_scope, body, materialized_literal_count, | 284 name, function_scope, body, materialized_literal_count, |
285 expected_property_count, parameter_count, | 285 expected_property_count, parameter_count, |
286 FunctionLiteral::kNoDuplicateParameters, | 286 FunctionLiteral::kNoDuplicateParameters, |
287 FunctionLiteral::kAnonymousExpression, | 287 FunctionLiteral::kAnonymousExpression, default_eager_compile_hint(), pos); |
288 FunctionLiteral::kShouldLazyCompile, pos); | |
289 | 288 |
290 function_literal->set_requires_class_field_init(requires_class_field_init); | 289 function_literal->set_requires_class_field_init(requires_class_field_init); |
291 | 290 |
292 return function_literal; | 291 return function_literal; |
293 } | 292 } |
294 | 293 |
295 | 294 |
296 // ---------------------------------------------------------------------------- | 295 // ---------------------------------------------------------------------------- |
297 // Target is a support class to facilitate manipulation of the | 296 // Target is a support class to facilitate manipulation of the |
298 // Parser's target_stack_ (the stack of potential 'break' and | 297 // Parser's target_stack_ (the stack of potential 'break' and |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 compile_options_(info->compile_options()), | 638 compile_options_(info->compile_options()), |
640 cached_parse_data_(NULL), | 639 cached_parse_data_(NULL), |
641 total_preparse_skipped_(0), | 640 total_preparse_skipped_(0), |
642 pre_parse_timer_(NULL), | 641 pre_parse_timer_(NULL), |
643 parsing_on_main_thread_(true) { | 642 parsing_on_main_thread_(true) { |
644 // Even though we were passed ParseInfo, we should not store it in | 643 // Even though we were passed ParseInfo, we should not store it in |
645 // Parser - this makes sure that Isolate is not accidentally accessed via | 644 // Parser - this makes sure that Isolate is not accidentally accessed via |
646 // ParseInfo during background parsing. | 645 // ParseInfo during background parsing. |
647 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 646 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
648 info->character_stream() != nullptr); | 647 info->character_stream() != nullptr); |
| 648 // Determine if functions can be lazily compiled. This is necessary to |
| 649 // allow some of our builtin JS files to be lazily compiled. These |
| 650 // builtins cannot be handled lazily by the parser, since we have to know |
| 651 // if a function uses the special natives syntax, which is something the |
| 652 // parser records. |
| 653 // If the debugger requests compilation for break points, we cannot be |
| 654 // aggressive about lazy compilation, because it might trigger compilation |
| 655 // of functions without an outer context when setting a breakpoint through |
| 656 // Debug::FindSharedFunctionInfoInScript |
| 657 bool can_compile_lazily = FLAG_lazy && !info->is_debug(); |
| 658 |
| 659 // Consider compiling eagerly when targeting the code cache. |
| 660 can_compile_lazily &= !(FLAG_serialize_eager && info->will_serialize()); |
| 661 |
| 662 // Consider compiling eagerly when compiling bytecode for Ignition. |
| 663 can_compile_lazily &= !(FLAG_ignition && FLAG_ignition_eager && |
| 664 info->isolate()->serializer_enabled()); |
| 665 |
| 666 set_default_eager_compile_hint(can_compile_lazily |
| 667 ? FunctionLiteral::kShouldLazyCompile |
| 668 : FunctionLiteral::kShouldEagerCompile); |
649 set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && | 669 set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && |
650 !info->is_native() && info->extension() == nullptr); | 670 !info->is_native() && info->extension() == nullptr); |
651 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 671 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
652 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && | 672 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && |
653 info->isolate()->is_tail_call_elimination_enabled()); | 673 info->isolate()->is_tail_call_elimination_enabled()); |
654 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 674 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
655 set_allow_harmony_for_in(FLAG_harmony_for_in); | 675 set_allow_harmony_for_in(FLAG_harmony_for_in); |
656 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 676 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
657 set_allow_harmony_restrictive_declarations( | 677 set_allow_harmony_restrictive_declarations( |
658 FLAG_harmony_restrictive_declarations); | 678 FLAG_harmony_restrictive_declarations); |
(...skipping 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2559 bool should_infer_name = function_name == NULL; | 2579 bool should_infer_name = function_name == NULL; |
2560 | 2580 |
2561 // We want a non-null handle as the function name. | 2581 // We want a non-null handle as the function name. |
2562 if (should_infer_name) { | 2582 if (should_infer_name) { |
2563 function_name = ast_value_factory()->empty_string(); | 2583 function_name = ast_value_factory()->empty_string(); |
2564 } | 2584 } |
2565 | 2585 |
2566 FunctionLiteral::EagerCompileHint eager_compile_hint = | 2586 FunctionLiteral::EagerCompileHint eager_compile_hint = |
2567 function_state_->next_function_is_parenthesized() | 2587 function_state_->next_function_is_parenthesized() |
2568 ? FunctionLiteral::kShouldEagerCompile | 2588 ? FunctionLiteral::kShouldEagerCompile |
2569 : FunctionLiteral::kShouldLazyCompile; | 2589 : default_eager_compile_hint(); |
2570 | 2590 |
2571 // Determine if the function can be parsed lazily. Lazy parsing is | 2591 // Determine if the function can be parsed lazily. Lazy parsing is |
2572 // different from lazy compilation; we need to parse more eagerly than we | 2592 // different from lazy compilation; we need to parse more eagerly than we |
2573 // compile. | 2593 // compile. |
2574 | 2594 |
2575 // We can only parse lazily if we also compile lazily. The heuristics for lazy | 2595 // We can only parse lazily if we also compile lazily. The heuristics for lazy |
2576 // compilation are: | 2596 // compilation are: |
2577 // - It must not have been prohibited by the caller to Parse (some callers | 2597 // - It must not have been prohibited by the caller to Parse (some callers |
2578 // need a full AST). | 2598 // need a full AST). |
2579 // - The outer scope must allow lazy compilation of inner functions. | 2599 // - The outer scope must allow lazy compilation of inner functions. |
(...skipping 2862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5442 | 5462 |
5443 return final_loop; | 5463 return final_loop; |
5444 } | 5464 } |
5445 | 5465 |
5446 #undef CHECK_OK | 5466 #undef CHECK_OK |
5447 #undef CHECK_OK_VOID | 5467 #undef CHECK_OK_VOID |
5448 #undef CHECK_FAILED | 5468 #undef CHECK_FAILED |
5449 | 5469 |
5450 } // namespace internal | 5470 } // namespace internal |
5451 } // namespace v8 | 5471 } // namespace v8 |
OLD | NEW |