| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 3813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3824 } | 3824 } |
| 3825 | 3825 |
| 3826 | 3826 |
| 3827 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, | 3827 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, |
| 3828 int* materialized_literal_count, | 3828 int* materialized_literal_count, |
| 3829 int* expected_property_count, | 3829 int* expected_property_count, |
| 3830 bool* ok) { | 3830 bool* ok) { |
| 3831 if (produce_cached_parse_data()) CHECK(log_); | 3831 if (produce_cached_parse_data()) CHECK(log_); |
| 3832 | 3832 |
| 3833 int function_block_pos = position(); | 3833 int function_block_pos = position(); |
| 3834 if (consume_cached_parse_data()) { | 3834 if (consume_cached_parse_data() && !cached_parse_data_->rejected()) { |
| 3835 // If we have cached data, we use it to skip parsing the function body. The | 3835 // If we have cached data, we use it to skip parsing the function body. The |
| 3836 // data contains the information we need to construct the lazy function. | 3836 // data contains the information we need to construct the lazy function. |
| 3837 FunctionEntry entry = | 3837 FunctionEntry entry = |
| 3838 cached_parse_data_->GetFunctionEntry(function_block_pos); | 3838 cached_parse_data_->GetFunctionEntry(function_block_pos); |
| 3839 // Check that cached data is valid. | 3839 // Check that cached data is valid. If not, mark it as invalid (the embedder |
| 3840 CHECK(entry.is_valid()); | 3840 // handles it). Note that end position greater than end of stream is safe, |
| 3841 // End position greater than end of stream is safe, and hard to check. | 3841 // and hard to check. |
| 3842 CHECK(entry.end_pos() > function_block_pos); | 3842 if (entry.is_valid() && entry.end_pos() > function_block_pos) { |
| 3843 scanner()->SeekForward(entry.end_pos() - 1); | 3843 scanner()->SeekForward(entry.end_pos() - 1); |
| 3844 | 3844 |
| 3845 scope_->set_end_position(entry.end_pos()); | 3845 scope_->set_end_position(entry.end_pos()); |
| 3846 Expect(Token::RBRACE, ok); | 3846 Expect(Token::RBRACE, ok); |
| 3847 if (!*ok) { | 3847 if (!*ok) { |
| 3848 return; |
| 3849 } |
| 3850 total_preparse_skipped_ += scope_->end_position() - function_block_pos; |
| 3851 *materialized_literal_count = entry.literal_count(); |
| 3852 *expected_property_count = entry.property_count(); |
| 3853 scope_->SetStrictMode(entry.strict_mode()); |
| 3848 return; | 3854 return; |
| 3849 } | 3855 } |
| 3850 total_preparse_skipped_ += scope_->end_position() - function_block_pos; | 3856 cached_parse_data_->Reject(); |
| 3851 *materialized_literal_count = entry.literal_count(); | 3857 } |
| 3852 *expected_property_count = entry.property_count(); | 3858 // With no cached data, we partially parse the function, without building an |
| 3853 scope_->SetStrictMode(entry.strict_mode()); | 3859 // AST. This gathers the data needed to build a lazy function. |
| 3854 } else { | 3860 SingletonLogger logger; |
| 3855 // With no cached data, we partially parse the function, without building an | 3861 PreParser::PreParseResult result = |
| 3856 // AST. This gathers the data needed to build a lazy function. | 3862 ParseLazyFunctionBodyWithPreParser(&logger); |
| 3857 SingletonLogger logger; | 3863 if (result == PreParser::kPreParseStackOverflow) { |
| 3858 PreParser::PreParseResult result = | 3864 // Propagate stack overflow. |
| 3859 ParseLazyFunctionBodyWithPreParser(&logger); | 3865 set_stack_overflow(); |
| 3860 if (result == PreParser::kPreParseStackOverflow) { | 3866 *ok = false; |
| 3861 // Propagate stack overflow. | 3867 return; |
| 3862 set_stack_overflow(); | 3868 } |
| 3863 *ok = false; | 3869 if (logger.has_error()) { |
| 3864 return; | 3870 ParserTraits::ReportMessageAt( |
| 3865 } | 3871 Scanner::Location(logger.start(), logger.end()), logger.message(), |
| 3866 if (logger.has_error()) { | 3872 logger.argument_opt(), logger.is_reference_error()); |
| 3867 ParserTraits::ReportMessageAt( | 3873 *ok = false; |
| 3868 Scanner::Location(logger.start(), logger.end()), | 3874 return; |
| 3869 logger.message(), logger.argument_opt(), logger.is_reference_error()); | 3875 } |
| 3870 *ok = false; | 3876 scope_->set_end_position(logger.end()); |
| 3871 return; | 3877 Expect(Token::RBRACE, ok); |
| 3872 } | 3878 if (!*ok) { |
| 3873 scope_->set_end_position(logger.end()); | 3879 return; |
| 3874 Expect(Token::RBRACE, ok); | 3880 } |
| 3875 if (!*ok) { | 3881 total_preparse_skipped_ += scope_->end_position() - function_block_pos; |
| 3876 return; | 3882 *materialized_literal_count = logger.literals(); |
| 3877 } | 3883 *expected_property_count = logger.properties(); |
| 3878 total_preparse_skipped_ += scope_->end_position() - function_block_pos; | 3884 scope_->SetStrictMode(logger.strict_mode()); |
| 3879 *materialized_literal_count = logger.literals(); | 3885 if (produce_cached_parse_data()) { |
| 3880 *expected_property_count = logger.properties(); | 3886 DCHECK(log_); |
| 3881 scope_->SetStrictMode(logger.strict_mode()); | 3887 // Position right after terminal '}'. |
| 3882 if (produce_cached_parse_data()) { | 3888 int body_end = scanner()->location().end_pos; |
| 3883 DCHECK(log_); | 3889 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, |
| 3884 // Position right after terminal '}'. | 3890 *expected_property_count, scope_->strict_mode()); |
| 3885 int body_end = scanner()->location().end_pos; | |
| 3886 log_->LogFunction(function_block_pos, body_end, | |
| 3887 *materialized_literal_count, | |
| 3888 *expected_property_count, | |
| 3889 scope_->strict_mode()); | |
| 3890 } | |
| 3891 } | 3891 } |
| 3892 } | 3892 } |
| 3893 | 3893 |
| 3894 | 3894 |
| 3895 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 3895 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
| 3896 const AstRawString* function_name, int pos, Variable* fvar, | 3896 const AstRawString* function_name, int pos, Variable* fvar, |
| 3897 Token::Value fvar_init_op, bool is_generator, bool* ok) { | 3897 Token::Value fvar_init_op, bool is_generator, bool* ok) { |
| 3898 // Everything inside an eagerly parsed function will be parsed eagerly | 3898 // Everything inside an eagerly parsed function will be parsed eagerly |
| 3899 // (see comment above). | 3899 // (see comment above). |
| 3900 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 3900 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5291 } else { | 5291 } else { |
| 5292 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5292 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
| 5293 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5293 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
| 5294 raw_string->length()); | 5294 raw_string->length()); |
| 5295 } | 5295 } |
| 5296 } | 5296 } |
| 5297 | 5297 |
| 5298 return running_hash; | 5298 return running_hash; |
| 5299 } | 5299 } |
| 5300 } } // namespace v8::internal | 5300 } } // namespace v8::internal |
| OLD | NEW |