| 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/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 3254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3265 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3265 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
| 3266 return static_cast<LiteralType>(literal_type->value()); | 3266 return static_cast<LiteralType>(literal_type->value()); |
| 3267 } | 3267 } |
| 3268 | 3268 |
| 3269 | 3269 |
| 3270 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3270 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
| 3271 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3271 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
| 3272 } | 3272 } |
| 3273 | 3273 |
| 3274 | 3274 |
| 3275 bool CheckAndCollectArrowParameter(ParserTraits* traits, | 3275 bool CheckAndDeclareArrowParameter(ParserTraits* traits, Expression* expression, |
| 3276 Collector<VariableProxy*>* collector, | 3276 Scope* scope, unsigned* num_params, |
| 3277 Expression* expression) { | 3277 Scanner::Location* dupe_loc) { |
| 3278 // Case for empty parameter lists: | 3278 // Case for empty parameter lists: |
| 3279 // () => ... | 3279 // () => ... |
| 3280 if (expression == NULL) return true; | 3280 if (expression == NULL) return true; |
| 3281 | 3281 |
| 3282 // Too many parentheses around expression: | 3282 // Too many parentheses around expression: |
| 3283 // (( ... )) => ... | 3283 // (( ... )) => ... |
| 3284 if (expression->parenthesization_level() > 1) return false; | 3284 if (expression->parenthesization_level() > 1) return false; |
| 3285 | 3285 |
| 3286 // Case for a single parameter: | 3286 // Case for a single parameter: |
| 3287 // (foo) => ... | 3287 // (foo) => ... |
| 3288 // foo => ... | 3288 // foo => ... |
| 3289 if (expression->IsVariableProxy()) { | 3289 if (expression->IsVariableProxy()) { |
| 3290 if (expression->AsVariableProxy()->is_this()) return false; | 3290 if (expression->AsVariableProxy()->is_this()) return false; |
| 3291 | 3291 |
| 3292 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); | 3292 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); |
| 3293 if (traits->IsEvalOrArguments(raw_name) || | 3293 if (traits->IsEvalOrArguments(raw_name) || |
| 3294 traits->IsFutureStrictReserved(raw_name)) | 3294 traits->IsFutureStrictReserved(raw_name)) |
| 3295 return false; | 3295 return false; |
| 3296 | 3296 |
| 3297 collector->Add(expression->AsVariableProxy()); | 3297 if (scope->IsDeclared(raw_name)) { |
| 3298 *dupe_loc = Scanner::Location( |
| 3299 expression->position(), expression->position() + raw_name->length()); |
| 3300 return false; |
| 3301 } |
| 3302 |
| 3303 scope->DeclareParameter(raw_name, VAR); |
| 3304 ++(*num_params); |
| 3298 return true; | 3305 return true; |
| 3299 } | 3306 } |
| 3300 | 3307 |
| 3301 // Case for more than one parameter: | 3308 // Case for more than one parameter: |
| 3302 // (foo, bar [, ...]) => ... | 3309 // (foo, bar [, ...]) => ... |
| 3303 if (expression->IsBinaryOperation()) { | 3310 if (expression->IsBinaryOperation()) { |
| 3304 BinaryOperation* binop = expression->AsBinaryOperation(); | 3311 BinaryOperation* binop = expression->AsBinaryOperation(); |
| 3305 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() || | 3312 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() || |
| 3306 binop->right()->is_parenthesized()) | 3313 binop->right()->is_parenthesized()) |
| 3307 return false; | 3314 return false; |
| 3308 | 3315 |
| 3309 return CheckAndCollectArrowParameter(traits, collector, binop->left()) && | 3316 return CheckAndDeclareArrowParameter(traits, binop->left(), scope, |
| 3310 CheckAndCollectArrowParameter(traits, collector, binop->right()); | 3317 num_params, dupe_loc) && |
| 3318 CheckAndDeclareArrowParameter(traits, binop->right(), scope, |
| 3319 num_params, dupe_loc); |
| 3311 } | 3320 } |
| 3312 | 3321 |
| 3313 // Any other kind of expression is not a valid parameter list. | 3322 // Any other kind of expression is not a valid parameter list. |
| 3314 return false; | 3323 return false; |
| 3315 } | 3324 } |
| 3316 | 3325 |
| 3317 | 3326 |
| 3318 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( | 3327 unsigned ParserTraits::DeclareArrowParametersFromExpression( |
| 3319 Expression* expression, bool* ok) { | 3328 Expression* expression, Scope* scope, Scanner::Location* dupe_loc, |
| 3320 Collector<VariableProxy*> collector; | 3329 bool* ok) { |
| 3321 *ok = CheckAndCollectArrowParameter(this, &collector, expression); | 3330 unsigned num_params = 0; |
| 3322 return collector.ToVector(); | 3331 *ok = CheckAndDeclareArrowParameter(this, expression, scope, &num_params, |
| 3332 dupe_loc); |
| 3333 return num_params; |
| 3323 } | 3334 } |
| 3324 | 3335 |
| 3325 | 3336 |
| 3326 FunctionLiteral* Parser::ParseFunctionLiteral( | 3337 FunctionLiteral* Parser::ParseFunctionLiteral( |
| 3327 const AstRawString* function_name, | 3338 const AstRawString* function_name, |
| 3328 Scanner::Location function_name_location, | 3339 Scanner::Location function_name_location, |
| 3329 bool name_is_strict_reserved, | 3340 bool name_is_strict_reserved, |
| 3330 bool is_generator, | 3341 bool is_generator, |
| 3331 int function_token_pos, | 3342 int function_token_pos, |
| 3332 FunctionLiteral::FunctionType function_type, | 3343 FunctionLiteral::FunctionType function_type, |
| (...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4795 info()->SetAstValueFactory(ast_value_factory_); | 4806 info()->SetAstValueFactory(ast_value_factory_); |
| 4796 } | 4807 } |
| 4797 ast_value_factory_ = NULL; | 4808 ast_value_factory_ = NULL; |
| 4798 | 4809 |
| 4799 InternalizeUseCounts(); | 4810 InternalizeUseCounts(); |
| 4800 | 4811 |
| 4801 return (result != NULL); | 4812 return (result != NULL); |
| 4802 } | 4813 } |
| 4803 | 4814 |
| 4804 } } // namespace v8::internal | 4815 } } // namespace v8::internal |
| OLD | NEW |