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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 | 62 |
63 bool ParseData::IsSane() { | 63 bool ParseData::IsSane() { |
64 if (!IsAligned(script_data_->length(), sizeof(unsigned))) return false; | 64 if (!IsAligned(script_data_->length(), sizeof(unsigned))) return false; |
65 // Check that the header data is valid and doesn't specify | 65 // Check that the header data is valid and doesn't specify |
66 // point to positions outside the store. | 66 // point to positions outside the store. |
67 int data_length = Length(); | 67 int data_length = Length(); |
68 if (data_length < PreparseDataConstants::kHeaderSize) return false; | 68 if (data_length < PreparseDataConstants::kHeaderSize) return false; |
69 if (Magic() != PreparseDataConstants::kMagicNumber) return false; | 69 if (Magic() != PreparseDataConstants::kMagicNumber) return false; |
70 if (Version() != PreparseDataConstants::kCurrentVersion) return false; | 70 if (Version() != PreparseDataConstants::kCurrentVersion) return false; |
71 if (HasError()) return false; | |
72 // Check that the space allocated for function entries is sane. | 71 // Check that the space allocated for function entries is sane. |
73 int functions_size = FunctionsSize(); | 72 int functions_size = FunctionsSize(); |
74 if (functions_size < 0) return false; | 73 if (functions_size < 0) return false; |
75 if (functions_size % FunctionEntry::kSize != 0) return false; | 74 if (functions_size % FunctionEntry::kSize != 0) return false; |
76 // Check that the total size has room for header and function entries. | 75 // Check that the total size has room for header and function entries. |
77 int minimum_size = | 76 int minimum_size = |
78 PreparseDataConstants::kHeaderSize + functions_size; | 77 PreparseDataConstants::kHeaderSize + functions_size; |
79 if (data_length < minimum_size) return false; | 78 if (data_length < minimum_size) return false; |
80 return true; | 79 return true; |
81 } | 80 } |
82 | 81 |
83 | 82 |
84 void ParseData::Initialize() { | 83 void ParseData::Initialize() { |
85 // Prepares state for use. | 84 // Prepares state for use. |
86 int data_length = Length(); | 85 int data_length = Length(); |
87 if (data_length >= PreparseDataConstants::kHeaderSize) { | 86 if (data_length >= PreparseDataConstants::kHeaderSize) { |
88 function_index_ = PreparseDataConstants::kHeaderSize; | 87 function_index_ = PreparseDataConstants::kHeaderSize; |
89 } | 88 } |
90 } | 89 } |
91 | 90 |
92 | 91 |
93 bool ParseData::HasError() { | |
94 return Data()[PreparseDataConstants::kHasErrorOffset]; | |
95 } | |
96 | |
97 | |
98 unsigned ParseData::Magic() { | 92 unsigned ParseData::Magic() { |
99 return Data()[PreparseDataConstants::kMagicOffset]; | 93 return Data()[PreparseDataConstants::kMagicOffset]; |
100 } | 94 } |
101 | 95 |
102 | 96 |
103 unsigned ParseData::Version() { | 97 unsigned ParseData::Version() { |
104 return Data()[PreparseDataConstants::kVersionOffset]; | 98 return Data()[PreparseDataConstants::kVersionOffset]; |
105 } | 99 } |
106 | 100 |
107 | 101 |
(...skipping 2673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2781 kind, function_scope, is_inner_function, may_abort); | 2775 kind, function_scope, is_inner_function, may_abort); |
2782 | 2776 |
2783 // Return immediately if pre-parser decided to abort parsing. | 2777 // Return immediately if pre-parser decided to abort parsing. |
2784 if (result == PreParser::kPreParseAbort) return kLazyParsingAborted; | 2778 if (result == PreParser::kPreParseAbort) return kLazyParsingAborted; |
2785 if (result == PreParser::kPreParseStackOverflow) { | 2779 if (result == PreParser::kPreParseStackOverflow) { |
2786 // Propagate stack overflow. | 2780 // Propagate stack overflow. |
2787 set_stack_overflow(); | 2781 set_stack_overflow(); |
2788 *ok = false; | 2782 *ok = false; |
2789 return kLazyParsingComplete; | 2783 return kLazyParsingComplete; |
2790 } | 2784 } |
| 2785 if (pending_error_handler_.has_pending_error()) { |
| 2786 *ok = false; |
| 2787 return kLazyParsingComplete; |
| 2788 } |
2791 PreParserLogger* logger = reusable_preparser_->logger(); | 2789 PreParserLogger* logger = reusable_preparser_->logger(); |
2792 if (logger->has_error()) { | |
2793 ReportMessageAt(Scanner::Location(logger->start(), logger->end()), | |
2794 logger->message(), logger->argument_opt(), | |
2795 logger->error_type()); | |
2796 *ok = false; | |
2797 return kLazyParsingComplete; | |
2798 } | |
2799 function_scope->set_end_position(logger->end()); | 2790 function_scope->set_end_position(logger->end()); |
2800 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); | 2791 Expect(Token::RBRACE, CHECK_OK_VALUE(kLazyParsingComplete)); |
2801 total_preparse_skipped_ += | 2792 total_preparse_skipped_ += |
2802 function_scope->end_position() - function_scope->start_position(); | 2793 function_scope->end_position() - function_scope->start_position(); |
2803 *num_parameters = logger->num_parameters(); | 2794 *num_parameters = logger->num_parameters(); |
2804 *function_length = logger->function_length(); | 2795 *function_length = logger->function_length(); |
2805 *has_duplicate_parameters = logger->has_duplicate_parameters(); | 2796 *has_duplicate_parameters = logger->has_duplicate_parameters(); |
2806 *materialized_literal_count = logger->literals(); | 2797 *materialized_literal_count = logger->literals(); |
2807 *expected_property_count = logger->properties(); | 2798 *expected_property_count = logger->properties(); |
2808 if (!is_inner_function && produce_cached_parse_data()) { | 2799 if (!is_inner_function && produce_cached_parse_data()) { |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 MarkCollectedTailCallExpressions(); | 3276 MarkCollectedTailCallExpressions(); |
3286 return result; | 3277 return result; |
3287 } | 3278 } |
3288 | 3279 |
3289 PreParser::PreParseResult Parser::ParseFunctionWithPreParser( | 3280 PreParser::PreParseResult Parser::ParseFunctionWithPreParser( |
3290 FunctionKind kind, DeclarationScope* function_scope, bool is_inner_function, | 3281 FunctionKind kind, DeclarationScope* function_scope, bool is_inner_function, |
3291 bool may_abort) { | 3282 bool may_abort) { |
3292 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); | 3283 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); |
3293 | 3284 |
3294 if (reusable_preparser_ == NULL) { | 3285 if (reusable_preparser_ == NULL) { |
3295 reusable_preparser_ = | 3286 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), |
3296 new PreParser(zone(), &scanner_, ast_value_factory(), stack_limit_); | 3287 &pending_error_handler_, stack_limit_); |
3297 reusable_preparser_->set_allow_lazy(true); | 3288 reusable_preparser_->set_allow_lazy(true); |
3298 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 3289 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
3299 SET_ALLOW(natives); | 3290 SET_ALLOW(natives); |
3300 SET_ALLOW(harmony_do_expressions); | 3291 SET_ALLOW(harmony_do_expressions); |
3301 SET_ALLOW(harmony_function_sent); | 3292 SET_ALLOW(harmony_function_sent); |
3302 SET_ALLOW(harmony_async_await); | 3293 SET_ALLOW(harmony_async_await); |
3303 SET_ALLOW(harmony_trailing_commas); | 3294 SET_ALLOW(harmony_trailing_commas); |
3304 SET_ALLOW(harmony_class_fields); | 3295 SET_ALLOW(harmony_class_fields); |
3305 #undef SET_ALLOW | 3296 #undef SET_ALLOW |
3306 } | 3297 } |
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5421 | 5412 |
5422 return final_loop; | 5413 return final_loop; |
5423 } | 5414 } |
5424 | 5415 |
5425 #undef CHECK_OK | 5416 #undef CHECK_OK |
5426 #undef CHECK_OK_VOID | 5417 #undef CHECK_OK_VOID |
5427 #undef CHECK_FAILED | 5418 #undef CHECK_FAILED |
5428 | 5419 |
5429 } // namespace internal | 5420 } // namespace internal |
5430 } // namespace v8 | 5421 } // namespace v8 |
OLD | NEW |