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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 pending_error_arg_(NULL), | 775 pending_error_arg_(NULL), |
776 pending_error_char_arg_(NULL) { | 776 pending_error_char_arg_(NULL) { |
777 ASSERT(!script_.is_null()); | 777 ASSERT(!script_.is_null()); |
778 isolate_->set_ast_node_id(0); | 778 isolate_->set_ast_node_id(0); |
779 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 779 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
780 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 780 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
781 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 781 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
782 set_allow_lazy(false); // Must be explicitly enabled. | 782 set_allow_lazy(false); // Must be explicitly enabled. |
783 set_allow_generators(FLAG_harmony_generators); | 783 set_allow_generators(FLAG_harmony_generators); |
784 set_allow_for_of(FLAG_harmony_iteration); | 784 set_allow_for_of(FLAG_harmony_iteration); |
| 785 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
785 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 786 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
786 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 787 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
787 ++feature) { | 788 ++feature) { |
788 use_counts_[feature] = 0; | 789 use_counts_[feature] = 0; |
789 } | 790 } |
790 } | 791 } |
791 | 792 |
792 | 793 |
793 FunctionLiteral* Parser::ParseProgram() { | 794 FunctionLiteral* Parser::ParseProgram() { |
794 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 795 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
(...skipping 2519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3314 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3315 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
3315 return static_cast<LiteralType>(literal_type->value()); | 3316 return static_cast<LiteralType>(literal_type->value()); |
3316 } | 3317 } |
3317 | 3318 |
3318 | 3319 |
3319 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3320 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3320 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3321 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3321 } | 3322 } |
3322 | 3323 |
3323 | 3324 |
| 3325 bool CheckAndCollectArrowParameter(ParserTraits* traits, |
| 3326 Collector<VariableProxy*>* collector, |
| 3327 Expression* expression) { |
| 3328 // Case for empty parameter lists: |
| 3329 // () => ... |
| 3330 if (expression == NULL) return true; |
| 3331 |
| 3332 // Too many parentheses around expression: |
| 3333 // (( ... )) => ... |
| 3334 if (expression->parenthesization_level() > 1) return false; |
| 3335 |
| 3336 // Case for a single parameter: |
| 3337 // (foo) => ... |
| 3338 // foo => ... |
| 3339 if (expression->IsVariableProxy()) { |
| 3340 if (expression->AsVariableProxy()->is_this()) return false; |
| 3341 |
| 3342 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); |
| 3343 if (traits->IsEvalOrArguments(raw_name) || |
| 3344 traits->IsFutureStrictReserved(raw_name)) |
| 3345 return false; |
| 3346 |
| 3347 collector->Add(expression->AsVariableProxy()); |
| 3348 return true; |
| 3349 } |
| 3350 |
| 3351 // Case for more than one parameter: |
| 3352 // (foo, bar [, ...]) => ... |
| 3353 if (expression->IsBinaryOperation()) { |
| 3354 BinaryOperation* binop = expression->AsBinaryOperation(); |
| 3355 if (binop->op() != Token::COMMA || binop->left()->is_parenthesized() || |
| 3356 binop->right()->is_parenthesized()) |
| 3357 return false; |
| 3358 |
| 3359 return CheckAndCollectArrowParameter(traits, collector, binop->left()) && |
| 3360 CheckAndCollectArrowParameter(traits, collector, binop->right()); |
| 3361 } |
| 3362 |
| 3363 // Any other kind of expression is not a valid parameter list. |
| 3364 return false; |
| 3365 } |
| 3366 |
| 3367 |
| 3368 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( |
| 3369 Expression* expression, bool* ok) { |
| 3370 Collector<VariableProxy*> collector; |
| 3371 *ok = CheckAndCollectArrowParameter(this, &collector, expression); |
| 3372 return collector.ToVector(); |
| 3373 } |
| 3374 |
| 3375 |
3324 FunctionLiteral* Parser::ParseFunctionLiteral( | 3376 FunctionLiteral* Parser::ParseFunctionLiteral( |
3325 const AstRawString* function_name, | 3377 const AstRawString* function_name, |
3326 Scanner::Location function_name_location, | 3378 Scanner::Location function_name_location, |
3327 bool name_is_strict_reserved, | 3379 bool name_is_strict_reserved, |
3328 bool is_generator, | 3380 bool is_generator, |
3329 int function_token_pos, | 3381 int function_token_pos, |
3330 FunctionLiteral::FunctionType function_type, | 3382 FunctionLiteral::FunctionType function_type, |
3331 FunctionLiteral::ArityRestriction arity_restriction, | 3383 FunctionLiteral::ArityRestriction arity_restriction, |
3332 bool* ok) { | 3384 bool* ok) { |
3333 // Function :: | 3385 // Function :: |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3733 | 3785 |
3734 if (reusable_preparser_ == NULL) { | 3786 if (reusable_preparser_ == NULL) { |
3735 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3787 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
3736 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3788 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
3737 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3789 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
3738 reusable_preparser_->set_allow_modules(allow_modules()); | 3790 reusable_preparser_->set_allow_modules(allow_modules()); |
3739 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3791 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
3740 reusable_preparser_->set_allow_lazy(true); | 3792 reusable_preparser_->set_allow_lazy(true); |
3741 reusable_preparser_->set_allow_generators(allow_generators()); | 3793 reusable_preparser_->set_allow_generators(allow_generators()); |
3742 reusable_preparser_->set_allow_for_of(allow_for_of()); | 3794 reusable_preparser_->set_allow_for_of(allow_for_of()); |
| 3795 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); |
3743 reusable_preparser_->set_allow_harmony_numeric_literals( | 3796 reusable_preparser_->set_allow_harmony_numeric_literals( |
3744 allow_harmony_numeric_literals()); | 3797 allow_harmony_numeric_literals()); |
3745 } | 3798 } |
3746 PreParser::PreParseResult result = | 3799 PreParser::PreParseResult result = |
3747 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3800 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
3748 is_generator(), | 3801 is_generator(), |
3749 logger); | 3802 logger); |
3750 return result; | 3803 return result; |
3751 } | 3804 } |
3752 | 3805 |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4866 info()->SetAstValueFactory(ast_value_factory_); | 4919 info()->SetAstValueFactory(ast_value_factory_); |
4867 } | 4920 } |
4868 ast_value_factory_ = NULL; | 4921 ast_value_factory_ = NULL; |
4869 | 4922 |
4870 InternalizeUseCounts(); | 4923 InternalizeUseCounts(); |
4871 | 4924 |
4872 return (result != NULL); | 4925 return (result != NULL); |
4873 } | 4926 } |
4874 | 4927 |
4875 } } // namespace v8::internal | 4928 } } // namespace v8::internal |
OLD | NEW |