| 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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 pending_error_arg_(NULL), | 711 pending_error_arg_(NULL), |
| 712 pending_error_char_arg_(NULL) { | 712 pending_error_char_arg_(NULL) { |
| 713 ASSERT(!script_.is_null()); | 713 ASSERT(!script_.is_null()); |
| 714 isolate_->set_ast_node_id(0); | 714 isolate_->set_ast_node_id(0); |
| 715 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 715 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
| 716 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 716 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
| 717 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 717 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
| 718 set_allow_lazy(false); // Must be explicitly enabled. | 718 set_allow_lazy(false); // Must be explicitly enabled. |
| 719 set_allow_generators(FLAG_harmony_generators); | 719 set_allow_generators(FLAG_harmony_generators); |
| 720 set_allow_for_of(FLAG_harmony_iteration); | 720 set_allow_for_of(FLAG_harmony_iteration); |
| 721 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | |
| 722 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 721 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 723 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 722 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 724 ++feature) { | 723 ++feature) { |
| 725 use_counts_[feature] = 0; | 724 use_counts_[feature] = 0; |
| 726 } | 725 } |
| 727 } | 726 } |
| 728 | 727 |
| 729 | 728 |
| 730 FunctionLiteral* Parser::ParseProgram() { | 729 FunctionLiteral* Parser::ParseProgram() { |
| 731 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 730 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
| (...skipping 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3265 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3264 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
| 3266 return static_cast<LiteralType>(literal_type->value()); | 3265 return static_cast<LiteralType>(literal_type->value()); |
| 3267 } | 3266 } |
| 3268 | 3267 |
| 3269 | 3268 |
| 3270 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3269 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
| 3271 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3270 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
| 3272 } | 3271 } |
| 3273 | 3272 |
| 3274 | 3273 |
| 3275 bool CheckAndCollectArrowParameter(ParserTraits* traits, | |
| 3276 Collector<VariableProxy*>* collector, | |
| 3277 Expression* expression) { | |
| 3278 // Case for empty parameter lists: | |
| 3279 // () => ... | |
| 3280 if (expression == NULL) return true; | |
| 3281 | |
| 3282 // Too many parentheses around expression: | |
| 3283 // (( ... )) => ... | |
| 3284 if (expression->parenthesization_level() > 1) return false; | |
| 3285 | |
| 3286 // Case for a single parameter: | |
| 3287 // (foo) => ... | |
| 3288 // foo => ... | |
| 3289 if (expression->IsVariableProxy()) { | |
| 3290 if (expression->AsVariableProxy()->is_this()) return false; | |
| 3291 | |
| 3292 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); | |
| 3293 if (traits->IsEvalOrArguments(raw_name) || | |
| 3294 traits->IsFutureStrictReserved(raw_name)) | |
| 3295 return false; | |
| 3296 | |
| 3297 collector->Add(expression->AsVariableProxy()); | |
| 3298 return true; | |
| 3299 } | |
| 3300 | |
| 3301 // Case for more than one parameter: | |
| 3302 // (foo, bar [, ...]) => ... | |
| 3303 if (expression->IsBinaryOperation()) { | |
| 3304 BinaryOperation* binop = expression->AsBinaryOperation(); | |
| 3305 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() || | |
| 3306 binop->right()->is_parenthesized()) | |
| 3307 return false; | |
| 3308 | |
| 3309 return CheckAndCollectArrowParameter(traits, collector, binop->left()) && | |
| 3310 CheckAndCollectArrowParameter(traits, collector, binop->right()); | |
| 3311 } | |
| 3312 | |
| 3313 // Any other kind of expression is not a valid parameter list. | |
| 3314 return false; | |
| 3315 } | |
| 3316 | |
| 3317 | |
| 3318 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( | |
| 3319 Expression* expression, bool* ok) { | |
| 3320 Collector<VariableProxy*> collector; | |
| 3321 *ok = CheckAndCollectArrowParameter(this, &collector, expression); | |
| 3322 return collector.ToVector(); | |
| 3323 } | |
| 3324 | |
| 3325 | |
| 3326 FunctionLiteral* Parser::ParseFunctionLiteral( | 3274 FunctionLiteral* Parser::ParseFunctionLiteral( |
| 3327 const AstRawString* function_name, | 3275 const AstRawString* function_name, |
| 3328 Scanner::Location function_name_location, | 3276 Scanner::Location function_name_location, |
| 3329 bool name_is_strict_reserved, | 3277 bool name_is_strict_reserved, |
| 3330 bool is_generator, | 3278 bool is_generator, |
| 3331 int function_token_pos, | 3279 int function_token_pos, |
| 3332 FunctionLiteral::FunctionType function_type, | 3280 FunctionLiteral::FunctionType function_type, |
| 3333 FunctionLiteral::ArityRestriction arity_restriction, | 3281 FunctionLiteral::ArityRestriction arity_restriction, |
| 3334 bool* ok) { | 3282 bool* ok) { |
| 3335 // Function :: | 3283 // Function :: |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3725 | 3673 |
| 3726 if (reusable_preparser_ == NULL) { | 3674 if (reusable_preparser_ == NULL) { |
| 3727 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3675 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
| 3728 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3676 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
| 3729 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3677 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
| 3730 reusable_preparser_->set_allow_modules(allow_modules()); | 3678 reusable_preparser_->set_allow_modules(allow_modules()); |
| 3731 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3679 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
| 3732 reusable_preparser_->set_allow_lazy(true); | 3680 reusable_preparser_->set_allow_lazy(true); |
| 3733 reusable_preparser_->set_allow_generators(allow_generators()); | 3681 reusable_preparser_->set_allow_generators(allow_generators()); |
| 3734 reusable_preparser_->set_allow_for_of(allow_for_of()); | 3682 reusable_preparser_->set_allow_for_of(allow_for_of()); |
| 3735 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | |
| 3736 reusable_preparser_->set_allow_harmony_numeric_literals( | 3683 reusable_preparser_->set_allow_harmony_numeric_literals( |
| 3737 allow_harmony_numeric_literals()); | 3684 allow_harmony_numeric_literals()); |
| 3738 } | 3685 } |
| 3739 PreParser::PreParseResult result = | 3686 PreParser::PreParseResult result = |
| 3740 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3687 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
| 3741 is_generator(), | 3688 is_generator(), |
| 3742 logger); | 3689 logger); |
| 3743 return result; | 3690 return result; |
| 3744 } | 3691 } |
| 3745 | 3692 |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4795 info()->SetAstValueFactory(ast_value_factory_); | 4742 info()->SetAstValueFactory(ast_value_factory_); |
| 4796 } | 4743 } |
| 4797 ast_value_factory_ = NULL; | 4744 ast_value_factory_ = NULL; |
| 4798 | 4745 |
| 4799 InternalizeUseCounts(); | 4746 InternalizeUseCounts(); |
| 4800 | 4747 |
| 4801 return (result != NULL); | 4748 return (result != NULL); |
| 4802 } | 4749 } |
| 4803 | 4750 |
| 4804 } } // namespace v8::internal | 4751 } } // namespace v8::internal |
| OLD | NEW |