| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // separately by Parser::SkipLazyFunctionBody. | 124 // separately by Parser::SkipLazyFunctionBody. |
| 125 ParseFormalParameterList(&formals, CHECK_OK_VALUE(kPreParseSuccess)); | 125 ParseFormalParameterList(&formals, CHECK_OK_VALUE(kPreParseSuccess)); |
| 126 Expect(Token::RPAREN, CHECK_OK_VALUE(kPreParseSuccess)); | 126 Expect(Token::RPAREN, CHECK_OK_VALUE(kPreParseSuccess)); |
| 127 int formals_end_position = scanner()->location().end_pos; | 127 int formals_end_position = scanner()->location().end_pos; |
| 128 | 128 |
| 129 CheckArityRestrictions( | 129 CheckArityRestrictions( |
| 130 formals.arity, kind, formals.has_rest, function_scope->start_position(), | 130 formals.arity, kind, formals.has_rest, function_scope->start_position(), |
| 131 formals_end_position, CHECK_OK_VALUE(kPreParseSuccess)); | 131 formals_end_position, CHECK_OK_VALUE(kPreParseSuccess)); |
| 132 has_duplicate_parameters = | 132 has_duplicate_parameters = |
| 133 !classifier()->is_valid_formal_parameter_list_without_duplicates(); | 133 !classifier()->is_valid_formal_parameter_list_without_duplicates(); |
| 134 | |
| 135 if (track_unresolved_variables_) { | |
| 136 function_scope->DeclareVariableName( | |
| 137 ast_value_factory()->arguments_string(), VAR); | |
| 138 function_scope->DeclareVariableName(ast_value_factory()->this_string(), | |
| 139 VAR); | |
| 140 } | |
| 141 } | 134 } |
| 142 | 135 |
| 143 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); | 136 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); |
| 144 LazyParsingResult result = ParseStatementListAndLogFunction( | 137 LazyParsingResult result = ParseStatementListAndLogFunction( |
| 145 &formals, has_duplicate_parameters, may_abort, ok); | 138 &formals, has_duplicate_parameters, may_abort, ok); |
| 146 | 139 |
| 140 if (!IsArrowFunction(kind) && track_unresolved_variables_) { |
| 141 // Declare arguments after parsing the function since lexical 'arguments' |
| 142 // masks the arguments object. Declare arguments before declaring the |
| 143 // function var since the arguments object masks 'function arguments'. |
| 144 function_scope->DeclareArguments(ast_value_factory()); |
| 145 } |
| 146 |
| 147 if (is_sloppy(function_scope->language_mode())) { | 147 if (is_sloppy(function_scope->language_mode())) { |
| 148 function_scope->HoistSloppyBlockFunctions(nullptr); | 148 function_scope->HoistSloppyBlockFunctions(nullptr); |
| 149 } | 149 } |
| 150 | 150 |
| 151 use_counts_ = nullptr; | 151 use_counts_ = nullptr; |
| 152 track_unresolved_variables_ = false; | 152 track_unresolved_variables_ = false; |
| 153 | 153 |
| 154 if (result == kLazyParsingAborted) { | 154 if (result == kLazyParsingAborted) { |
| 155 return kPreParseAbort; | 155 return kPreParseAbort; |
| 156 } else if (stack_overflow()) { | 156 } else if (stack_overflow()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 202 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 203 const RuntimeCallStats::CounterId counters[2][2] = { | 203 const RuntimeCallStats::CounterId counters[2][2] = { |
| 204 {&RuntimeCallStats::PreParseBackgroundNoVariableResolution, | 204 {&RuntimeCallStats::PreParseBackgroundNoVariableResolution, |
| 205 &RuntimeCallStats::PreParseNoVariableResolution}, | 205 &RuntimeCallStats::PreParseNoVariableResolution}, |
| 206 {&RuntimeCallStats::PreParseBackgroundWithVariableResolution, | 206 {&RuntimeCallStats::PreParseBackgroundWithVariableResolution, |
| 207 &RuntimeCallStats::PreParseWithVariableResolution}}; | 207 &RuntimeCallStats::PreParseWithVariableResolution}}; |
| 208 RuntimeCallTimerScope runtime_timer( | 208 RuntimeCallTimerScope runtime_timer( |
| 209 runtime_call_stats_, | 209 runtime_call_stats_, |
| 210 counters[track_unresolved_variables_][parsing_on_main_thread_]); | 210 counters[track_unresolved_variables_][parsing_on_main_thread_]); |
| 211 | 211 |
| 212 // Parse function body. | |
| 213 PreParserStatementList body; | |
| 214 DeclarationScope* function_scope = NewFunctionScope(kind); | 212 DeclarationScope* function_scope = NewFunctionScope(kind); |
| 215 function_scope->SetLanguageMode(language_mode); | 213 function_scope->SetLanguageMode(language_mode); |
| 216 FunctionState function_state(&function_state_, &scope_state_, function_scope); | 214 FunctionState function_state(&function_state_, &scope_state_, function_scope); |
| 217 DuplicateFinder duplicate_finder; | 215 DuplicateFinder duplicate_finder; |
| 218 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 216 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
| 219 GetNextFunctionLiteralId(); | 217 GetNextFunctionLiteralId(); |
| 220 | 218 |
| 221 Expect(Token::LPAREN, CHECK_OK); | 219 Expect(Token::LPAREN, CHECK_OK); |
| 222 int start_position = scanner()->location().beg_pos; | 220 int start_position = scanner()->location().beg_pos; |
| 223 function_scope->set_start_position(start_position); | 221 function_scope->set_start_position(start_position); |
| 224 PreParserFormalParameters formals(function_scope); | 222 PreParserFormalParameters formals(function_scope); |
| 225 ParseFormalParameterList(&formals, CHECK_OK); | 223 ParseFormalParameterList(&formals, CHECK_OK); |
| 226 Expect(Token::RPAREN, CHECK_OK); | 224 Expect(Token::RPAREN, CHECK_OK); |
| 227 int formals_end_position = scanner()->location().end_pos; | 225 int formals_end_position = scanner()->location().end_pos; |
| 228 | 226 |
| 229 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, | 227 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, |
| 230 formals_end_position, CHECK_OK); | 228 formals_end_position, CHECK_OK); |
| 231 | 229 |
| 232 Expect(Token::LBRACE, CHECK_OK); | 230 Expect(Token::LBRACE, CHECK_OK); |
| 233 ParseStatementList(body, Token::RBRACE, CHECK_OK); | 231 |
| 234 Expect(Token::RBRACE, CHECK_OK); | 232 // Parse function body. |
| 233 PreParserStatementList body; |
| 234 int pos = function_token_pos == kNoSourcePosition ? peek_position() |
| 235 : function_token_pos; |
| 236 ParseFunctionBody(body, function_name, pos, formals, kind, function_type, |
| 237 CHECK_OK); |
| 235 | 238 |
| 236 // Parsing the body may change the language mode in our scope. | 239 // Parsing the body may change the language mode in our scope. |
| 237 language_mode = function_scope->language_mode(); | 240 language_mode = function_scope->language_mode(); |
| 238 | 241 |
| 239 if (is_sloppy(language_mode)) { | 242 if (is_sloppy(language_mode)) { |
| 240 function_scope->HoistSloppyBlockFunctions(nullptr); | 243 function_scope->HoistSloppyBlockFunctions(nullptr); |
| 241 } | 244 } |
| 242 | 245 |
| 243 // Validate name and parameter names. We can do this only after parsing the | 246 // Validate name and parameter names. We can do this only after parsing the |
| 244 // function, since the function can declare itself strict. | 247 // function, since the function can declare itself strict. |
| 245 CheckFunctionName(language_mode, function_name, function_name_validity, | 248 CheckFunctionName(language_mode, function_name, function_name_validity, |
| 246 function_name_location, CHECK_OK); | 249 function_name_location, CHECK_OK); |
| 247 const bool allow_duplicate_parameters = | 250 const bool allow_duplicate_parameters = |
| 248 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); | 251 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); |
| 249 ValidateFormalParameters(language_mode, allow_duplicate_parameters, CHECK_OK); | 252 ValidateFormalParameters(language_mode, allow_duplicate_parameters, CHECK_OK); |
| 250 | 253 |
| 251 int end_position = scanner()->location().end_pos; | 254 int end_position = scanner()->location().end_pos; |
| 252 if (is_strict(language_mode)) { | 255 if (is_strict(language_mode)) { |
| 253 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); | 256 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); |
| 254 } | 257 } |
| 255 function_scope->set_end_position(end_position); | |
| 256 | 258 |
| 257 if (FLAG_trace_preparse) { | 259 if (FLAG_trace_preparse) { |
| 258 PrintF(" [%s]: %i-%i\n", | 260 PrintF(" [%s]: %i-%i\n", |
| 259 track_unresolved_variables_ ? "Preparse resolution" | 261 track_unresolved_variables_ ? "Preparse resolution" |
| 260 : "Preparse no-resolution", | 262 : "Preparse no-resolution", |
| 261 function_scope->start_position(), function_scope->end_position()); | 263 function_scope->start_position(), function_scope->end_position()); |
| 262 } | 264 } |
| 263 | 265 |
| 264 return Expression::Default(); | 266 return Expression::Default(); |
| 265 } | 267 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 318 } |
| 317 } | 319 } |
| 318 } | 320 } |
| 319 | 321 |
| 320 #undef CHECK_OK | 322 #undef CHECK_OK |
| 321 #undef CHECK_OK_CUSTOM | 323 #undef CHECK_OK_CUSTOM |
| 322 | 324 |
| 323 | 325 |
| 324 } // namespace internal | 326 } // namespace internal |
| 325 } // namespace v8 | 327 } // namespace v8 |
| OLD | NEW |