| 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 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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()), | 589 info->extension(), info->ast_value_factory()), |
| 590 scanner_(info->unicode_cache()), | 590 scanner_(info->unicode_cache()), |
| 591 reusable_preparser_(nullptr), | 591 reusable_preparser_(nullptr), |
| 592 original_scope_(nullptr), | 592 original_scope_(nullptr), |
| 593 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
| 593 target_stack_(nullptr), | 594 target_stack_(nullptr), |
| 594 compile_options_(info->compile_options()), | 595 compile_options_(info->compile_options()), |
| 595 cached_parse_data_(nullptr), | 596 cached_parse_data_(nullptr), |
| 596 total_preparse_skipped_(0), | 597 total_preparse_skipped_(0), |
| 597 parsing_on_main_thread_(true), | 598 parsing_on_main_thread_(true), |
| 598 log_(nullptr) { | 599 log_(nullptr) { |
| 599 // Even though we were passed ParseInfo, we should not store it in | 600 // Even though we were passed ParseInfo, we should not store it in |
| 600 // Parser - this makes sure that Isolate is not accidentally accessed via | 601 // Parser - this makes sure that Isolate is not accidentally accessed via |
| 601 // ParseInfo during background parsing. | 602 // ParseInfo during background parsing. |
| 602 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || | 603 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || |
| (...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2562 // and | 2563 // and |
| 2563 // (function foo() { | 2564 // (function foo() { |
| 2564 // var a = 1; | 2565 // var a = 1; |
| 2565 // bar = function() { return a; } | 2566 // bar = function() { return a; } |
| 2566 // })(); | 2567 // })(); |
| 2567 | 2568 |
| 2568 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume | 2569 // Now foo will be parsed eagerly and compiled eagerly (optimization: assume |
| 2569 // parenthesis before the function means that it will be called | 2570 // parenthesis before the function means that it will be called |
| 2570 // immediately). bar can be parsed lazily, but we need to parse it in a mode | 2571 // immediately). bar can be parsed lazily, but we need to parse it in a mode |
| 2571 // that tracks unresolved variables. | 2572 // that tracks unresolved variables. |
| 2572 DCHECK_IMPLIES(mode() == PARSE_LAZILY, FLAG_lazy); | 2573 DCHECK_IMPLIES(parse_lazily(), FLAG_lazy); |
| 2573 DCHECK_IMPLIES(mode() == PARSE_LAZILY, allow_lazy()); | 2574 DCHECK_IMPLIES(parse_lazily(), allow_lazy()); |
| 2574 DCHECK_IMPLIES(mode() == PARSE_LAZILY, extension_ == nullptr); | 2575 DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr); |
| 2575 | 2576 |
| 2576 bool can_preparse = mode() == PARSE_LAZILY && | 2577 bool can_preparse = parse_lazily() && |
| 2577 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; | 2578 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; |
| 2578 | 2579 |
| 2579 bool is_lazy_top_level_function = | 2580 bool is_lazy_top_level_function = |
| 2580 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); | 2581 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); |
| 2581 | 2582 |
| 2582 // Determine whether we can still lazy parse the inner function. | 2583 // Determine whether we can still lazy parse the inner function. |
| 2583 // The preconditions are: | 2584 // The preconditions are: |
| 2584 // - Lazy compilation has to be enabled. | 2585 // - Lazy compilation has to be enabled. |
| 2585 // - Neither V8 natives nor native function declarations can be allowed, | 2586 // - Neither V8 natives nor native function declarations can be allowed, |
| 2586 // since parsing one would retroactively force the function to be | 2587 // since parsing one would retroactively force the function to be |
| (...skipping 2831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5418 | 5419 |
| 5419 return final_loop; | 5420 return final_loop; |
| 5420 } | 5421 } |
| 5421 | 5422 |
| 5422 #undef CHECK_OK | 5423 #undef CHECK_OK |
| 5423 #undef CHECK_OK_VOID | 5424 #undef CHECK_OK_VOID |
| 5424 #undef CHECK_FAILED | 5425 #undef CHECK_FAILED |
| 5425 | 5426 |
| 5426 } // namespace internal | 5427 } // namespace internal |
| 5427 } // namespace v8 | 5428 } // namespace v8 |
| OLD | NEW |