OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 return PreParserIdentifier::Undefined(); | 63 return PreParserIdentifier::Undefined(); |
64 if (scanner()->LiteralMatches("prototype", 9)) | 64 if (scanner()->LiteralMatches("prototype", 9)) |
65 return PreParserIdentifier::Prototype(); | 65 return PreParserIdentifier::Prototype(); |
66 if (scanner()->LiteralMatches("constructor", 11)) | 66 if (scanner()->LiteralMatches("constructor", 11)) |
67 return PreParserIdentifier::Constructor(); | 67 return PreParserIdentifier::Constructor(); |
68 return PreParserIdentifier::Default(); | 68 return PreParserIdentifier::Default(); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 72 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
73 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 73 DeclarationScope* function_scope, bool parsing_module, ParserRecorder* log, |
74 bool parsing_module, ParserRecorder* log, bool may_abort, int* use_counts) { | 74 bool may_abort, int* use_counts) { |
75 DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type()); | |
75 parsing_module_ = parsing_module; | 76 parsing_module_ = parsing_module; |
76 log_ = log; | 77 log_ = log; |
77 use_counts_ = use_counts; | 78 use_counts_ = use_counts; |
78 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 79 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
79 DCHECK_NULL(scope_state_); | 80 DCHECK_NULL(scope_state_); |
80 DeclarationScope* top_scope = NewScriptScope(); | |
81 FunctionState top_state(&function_state_, &scope_state_, top_scope, | |
82 kNormalFunction); | |
83 scope()->SetLanguageMode(language_mode); | |
84 DeclarationScope* function_scope = NewFunctionScope(kind); | |
85 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); | |
86 FunctionState function_state(&function_state_, &scope_state_, function_scope, | 81 FunctionState function_state(&function_state_, &scope_state_, function_scope, |
87 kind); | 82 function_scope->function_kind()); |
88 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 83 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
89 bool ok = true; | 84 bool ok = true; |
90 int start_position = peek_position(); | 85 int start_position = peek_position(); |
91 LazyParsingResult result = ParseLazyFunctionLiteralBody(may_abort, &ok); | 86 LazyParsingResult result = ParseLazyFunctionLiteralBody(may_abort, &ok); |
92 use_counts_ = nullptr; | 87 use_counts_ = nullptr; |
88 function_scope->ResetAfterPreparsing(); | |
93 if (result == kLazyParsingAborted) { | 89 if (result == kLazyParsingAborted) { |
94 return kPreParseAbort; | 90 return kPreParseAbort; |
95 } else if (stack_overflow()) { | 91 } else if (stack_overflow()) { |
96 return kPreParseStackOverflow; | 92 return kPreParseStackOverflow; |
97 } else if (!ok) { | 93 } else if (!ok) { |
98 ReportUnexpectedToken(scanner()->current_token()); | 94 ReportUnexpectedToken(scanner()->current_token()); |
99 } else { | 95 } else { |
100 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 96 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
101 if (is_strict(scope()->language_mode())) { | 97 if (is_strict(function_scope->language_mode())) { |
marja
2016/09/26 12:38:27
Here we have already reset the function scope, and
| |
102 int end_pos = scanner()->location().end_pos; | 98 int end_pos = scanner()->location().end_pos; |
103 CheckStrictOctalLiteral(start_position, end_pos, &ok); | 99 CheckStrictOctalLiteral(start_position, end_pos, &ok); |
104 CheckDecimalLiteralWithLeadingZero(start_position, end_pos); | 100 CheckDecimalLiteralWithLeadingZero(start_position, end_pos); |
105 } | 101 } |
106 } | 102 } |
107 return kPreParseSuccess; | 103 return kPreParseSuccess; |
108 } | 104 } |
109 | 105 |
110 | 106 |
111 // Preparsing checks a JavaScript program and emits preparse-data that helps | 107 // Preparsing checks a JavaScript program and emits preparse-data that helps |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 335 |
340 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); | 336 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
341 } | 337 } |
342 | 338 |
343 #undef CHECK_OK | 339 #undef CHECK_OK |
344 #undef CHECK_OK_CUSTOM | 340 #undef CHECK_OK_CUSTOM |
345 | 341 |
346 | 342 |
347 } // namespace internal | 343 } // namespace internal |
348 } // namespace v8 | 344 } // namespace v8 |
OLD | NEW |