| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 &top_factory); | 114 &top_factory); |
| 115 scope_->SetLanguageMode(language_mode); | 115 scope_->SetLanguageMode(language_mode); |
| 116 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 116 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); |
| 117 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); | 117 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); |
| 118 PreParserFactory function_factory(NULL); | 118 PreParserFactory function_factory(NULL); |
| 119 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 119 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
| 120 &function_factory); | 120 &function_factory); |
| 121 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 121 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
| 122 bool ok = true; | 122 bool ok = true; |
| 123 int start_position = peek_position(); | 123 int start_position = peek_position(); |
| 124 function_state.set_parse_phase(FunctionParsePhase::FunctionBody); |
| 124 ParseLazyFunctionLiteralBody(&ok, bookmark); | 125 ParseLazyFunctionLiteralBody(&ok, bookmark); |
| 125 use_counts_ = nullptr; | 126 use_counts_ = nullptr; |
| 126 if (bookmark && bookmark->HasBeenReset()) { | 127 if (bookmark && bookmark->HasBeenReset()) { |
| 127 // Do nothing, as we've just aborted scanning this function. | 128 // Do nothing, as we've just aborted scanning this function. |
| 128 } else if (stack_overflow()) { | 129 } else if (stack_overflow()) { |
| 129 return kPreParseStackOverflow; | 130 return kPreParseStackOverflow; |
| 130 } else if (!ok) { | 131 } else if (!ok) { |
| 131 ReportUnexpectedToken(scanner()->current_token()); | 132 ReportUnexpectedToken(scanner()->current_token()); |
| 132 } else { | 133 } else { |
| 133 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 134 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| (...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 PreParserFactory factory(NULL); | 1099 PreParserFactory factory(NULL); |
| 1099 FunctionState function_state(&function_state_, &scope_, function_scope, kind, | 1100 FunctionState function_state(&function_state_, &scope_, function_scope, kind, |
| 1100 &factory); | 1101 &factory); |
| 1101 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 1102 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
| 1102 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 1103 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
| 1103 | 1104 |
| 1104 Expect(Token::LPAREN, CHECK_OK); | 1105 Expect(Token::LPAREN, CHECK_OK); |
| 1105 int start_position = scanner()->location().beg_pos; | 1106 int start_position = scanner()->location().beg_pos; |
| 1106 function_scope->set_start_position(start_position); | 1107 function_scope->set_start_position(start_position); |
| 1107 PreParserFormalParameters formals(function_scope); | 1108 PreParserFormalParameters formals(function_scope); |
| 1109 function_state.set_parse_phase(FunctionParsePhase::FormalParameters); |
| 1108 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); | 1110 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
| 1109 Expect(Token::RPAREN, CHECK_OK); | 1111 Expect(Token::RPAREN, CHECK_OK); |
| 1110 int formals_end_position = scanner()->location().end_pos; | 1112 int formals_end_position = scanner()->location().end_pos; |
| 1111 | 1113 |
| 1112 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, | 1114 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, |
| 1113 formals_end_position, CHECK_OK); | 1115 formals_end_position, CHECK_OK); |
| 1114 | 1116 |
| 1115 // See Parser::ParseFunctionLiteral for more information about lazy parsing | 1117 // See Parser::ParseFunctionLiteral for more information about lazy parsing |
| 1116 // and lazy compilation. | 1118 // and lazy compilation. |
| 1117 bool is_lazily_parsed = (outer_is_script_scope && allow_lazy() && | 1119 bool is_lazily_parsed = (outer_is_script_scope && allow_lazy() && |
| 1118 !function_state_->this_function_is_parenthesized()); | 1120 !function_state_->this_function_is_parenthesized()); |
| 1119 | 1121 |
| 1122 function_state.set_parse_phase(FunctionParsePhase::FunctionBody); |
| 1120 Expect(Token::LBRACE, CHECK_OK); | 1123 Expect(Token::LBRACE, CHECK_OK); |
| 1121 if (is_lazily_parsed) { | 1124 if (is_lazily_parsed) { |
| 1122 ParseLazyFunctionLiteralBody(CHECK_OK); | 1125 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1123 } else { | 1126 } else { |
| 1124 ParseStatementList(Token::RBRACE, CHECK_OK); | 1127 ParseStatementList(Token::RBRACE, CHECK_OK); |
| 1125 } | 1128 } |
| 1126 Expect(Token::RBRACE, CHECK_OK); | 1129 Expect(Token::RBRACE, CHECK_OK); |
| 1127 | 1130 |
| 1128 // Parsing the body may change the language mode in our scope. | 1131 // Parsing the body may change the language mode in our scope. |
| 1129 language_mode = function_scope->language_mode(); | 1132 language_mode = function_scope->language_mode(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 // do '{' StatementList '}' | 1287 // do '{' StatementList '}' |
| 1285 Expect(Token::DO, CHECK_OK); | 1288 Expect(Token::DO, CHECK_OK); |
| 1286 Expect(Token::LBRACE, CHECK_OK); | 1289 Expect(Token::LBRACE, CHECK_OK); |
| 1287 while (peek() != Token::RBRACE) { | 1290 while (peek() != Token::RBRACE) { |
| 1288 ParseStatementListItem(CHECK_OK); | 1291 ParseStatementListItem(CHECK_OK); |
| 1289 } | 1292 } |
| 1290 Expect(Token::RBRACE, CHECK_OK); | 1293 Expect(Token::RBRACE, CHECK_OK); |
| 1291 return PreParserExpression::Default(); | 1294 return PreParserExpression::Default(); |
| 1292 } | 1295 } |
| 1293 | 1296 |
| 1297 void PreParserTraits::ParseAsyncArrowSingleExpressionBody( |
| 1298 PreParserStatementList body, bool accept_IN, |
| 1299 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
| 1300 Scope* scope = pre_parser_->scope_; |
| 1301 scope->ForceContextAllocation(); |
| 1302 |
| 1303 PreParserExpression return_value = |
| 1304 pre_parser_->ParseAssignmentExpression(accept_IN, classifier, ok); |
| 1305 if (!*ok) return; |
| 1306 |
| 1307 body->Add(PreParserStatement::ExpressionStatement(return_value), zone()); |
| 1308 } |
| 1309 |
| 1294 #undef CHECK_OK | 1310 #undef CHECK_OK |
| 1295 | 1311 |
| 1296 | 1312 |
| 1297 } // namespace internal | 1313 } // namespace internal |
| 1298 } // namespace v8 | 1314 } // namespace v8 |
| OLD | NEW |