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/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/char-predicates-inl.h" | 10 #include "src/char-predicates-inl.h" |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
671 } | 671 } |
672 | 672 |
673 | 673 |
674 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 674 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
675 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); | 675 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); |
676 } | 676 } |
677 | 677 |
678 | 678 |
679 Expression* ParserTraits::ThisExpression( | 679 Expression* ParserTraits::ThisExpression( |
680 Scope* scope, | 680 Scope* scope, |
681 AstNodeFactory<AstConstructionVisitor>* factory) { | 681 AstNodeFactory<AstConstructionVisitor>* factory, |
682 return factory->NewVariableProxy(scope->receiver()); | 682 int pos) { |
683 return factory->NewVariableProxy(scope->receiver(), pos); | |
683 } | 684 } |
684 | 685 |
685 | 686 |
686 Literal* ParserTraits::ExpressionFromLiteral( | 687 Literal* ParserTraits::ExpressionFromLiteral( |
687 Token::Value token, int pos, | 688 Token::Value token, int pos, |
688 Scanner* scanner, | 689 Scanner* scanner, |
689 AstNodeFactory<AstConstructionVisitor>* factory) { | 690 AstNodeFactory<AstConstructionVisitor>* factory) { |
690 switch (token) { | 691 switch (token) { |
691 case Token::NULL_LITERAL: | 692 case Token::NULL_LITERAL: |
692 return factory->NewNullLiteral(pos); | 693 return factory->NewNullLiteral(pos); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 pending_error_arg_(NULL), | 778 pending_error_arg_(NULL), |
778 pending_error_char_arg_(NULL) { | 779 pending_error_char_arg_(NULL) { |
779 ASSERT(!script_.is_null()); | 780 ASSERT(!script_.is_null()); |
780 isolate_->set_ast_node_id(0); | 781 isolate_->set_ast_node_id(0); |
781 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 782 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
782 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 783 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
783 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 784 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
784 set_allow_lazy(false); // Must be explicitly enabled. | 785 set_allow_lazy(false); // Must be explicitly enabled. |
785 set_allow_generators(FLAG_harmony_generators); | 786 set_allow_generators(FLAG_harmony_generators); |
786 set_allow_for_of(FLAG_harmony_iteration); | 787 set_allow_for_of(FLAG_harmony_iteration); |
788 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | |
787 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 789 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
788 } | 790 } |
789 | 791 |
790 | 792 |
791 FunctionLiteral* Parser::ParseProgram() { | 793 FunctionLiteral* Parser::ParseProgram() { |
792 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 794 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
793 // see comment for HistogramTimerScope class. | 795 // see comment for HistogramTimerScope class. |
794 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); | 796 HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); |
795 Handle<String> source(String::cast(script_->source())); | 797 Handle<String> source(String::cast(script_->source())); |
796 isolate()->counters()->total_parse_size()->Increment(source->length()); | 798 isolate()->counters()->total_parse_size()->Increment(source->length()); |
(...skipping 2501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3298 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3300 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
3299 return static_cast<LiteralType>(literal_type->value()); | 3301 return static_cast<LiteralType>(literal_type->value()); |
3300 } | 3302 } |
3301 | 3303 |
3302 | 3304 |
3303 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3305 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3304 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3306 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3305 } | 3307 } |
3306 | 3308 |
3307 | 3309 |
3310 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( | |
marja
2014/06/26 14:38:13
Here you have the same logic in 2 functions; would
| |
3311 Expression* expression) { | |
3312 // Parsing the parameter list of an arrow function does not have parameters | |
3313 // (as in: () => ...) returns NULL, so expression being NULL is not an error, | |
3314 // but an valid empty parameter list. | |
3315 if (expression == NULL) | |
3316 return Vector<VariableProxy*>::empty(); | |
3317 | |
3318 Collector<VariableProxy*> collector; | |
3319 | |
3320 // IsValidArrowFunctionParamterList() can be used to check for validity, | |
3321 // here we just ASSERT() that the passed expression is a valid param list. | |
3322 while (expression->IsBinaryOperation()) { | |
3323 BinaryOperation* binop = expression->AsBinaryOperation(); | |
3324 ASSERT_EQ(binop->op(), Token::COMMA); | |
3325 | |
3326 expression = binop->right(); | |
3327 ASSERT(expression->IsVariableProxy()); | |
3328 ASSERT(!expression->AsVariableProxy()->is_this()); | |
3329 ASSERT(!IsEvalOrArguments(expression->AsVariableProxy()->raw_name())); | |
3330 ASSERT(!IsFutureStrictReserved(expression->AsVariableProxy()->raw_name())); | |
3331 | |
3332 collector.Add(expression->AsVariableProxy()); | |
3333 expression = binop->left(); | |
3334 } | |
3335 | |
3336 // Add the remaining item. | |
3337 ASSERT(expression->IsVariableProxy()); | |
3338 ASSERT(!expression->AsVariableProxy()->is_this()); | |
3339 ASSERT(!IsEvalOrArguments(expression->AsVariableProxy()->raw_name())); | |
3340 ASSERT(!IsFutureStrictReserved(expression->AsVariableProxy()->raw_name())); | |
3341 | |
3342 collector.Add(expression->AsVariableProxy()); | |
3343 return collector.ToVector(); | |
3344 } | |
3345 | |
3346 | |
3347 bool ParserTraits::IsValidArrowFunctionParameterList(Expression* expression) { | |
3348 // Case for empty parameter lists: | |
3349 // () => ... | |
3350 if (expression == NULL) | |
3351 return true; | |
3352 | |
3353 // Too many parentheses around expression: | |
3354 // (( ... )) => ... | |
3355 if (expression->parenthesization_level() > 1) | |
3356 return false; | |
3357 | |
3358 // Case for a single parameter: | |
3359 // (foo) => ... | |
3360 // foo => ... | |
3361 if (expression->IsVariableProxy()) { | |
3362 if (expression->AsVariableProxy()->is_this()) return false; | |
3363 const AstRawString* raw_name = expression->AsVariableProxy()->raw_name(); | |
3364 return !(IsEvalOrArguments(raw_name) || IsFutureStrictReserved(raw_name)); | |
3365 } | |
3366 | |
3367 // Case for more than one parameter: | |
3368 // (foo, bar [, ...]) => ... | |
3369 if (expression->IsBinaryOperation()) { | |
3370 BinaryOperation* binop = expression->AsBinaryOperation(); | |
3371 return binop->op() == Token::COMMA && | |
3372 !binop->right()->is_parenthesized() && | |
3373 !binop->left()->is_parenthesized() && | |
3374 IsValidArrowFunctionParameterList(binop->right()) && | |
3375 IsValidArrowFunctionParameterList(binop->left()); | |
3376 } | |
3377 | |
3378 // Any other kind of expression is not a valid parameter list. | |
3379 return false; | |
3380 } | |
3381 | |
3382 | |
3308 FunctionLiteral* Parser::ParseFunctionLiteral( | 3383 FunctionLiteral* Parser::ParseFunctionLiteral( |
3309 const AstRawString* function_name, | 3384 const AstRawString* function_name, |
3310 Scanner::Location function_name_location, | 3385 Scanner::Location function_name_location, |
3311 bool name_is_strict_reserved, | 3386 bool name_is_strict_reserved, |
3312 bool is_generator, | 3387 bool is_generator, |
3313 int function_token_pos, | 3388 int function_token_pos, |
3314 FunctionLiteral::FunctionType function_type, | 3389 FunctionLiteral::FunctionType function_type, |
3315 FunctionLiteral::ArityRestriction arity_restriction, | 3390 FunctionLiteral::ArityRestriction arity_restriction, |
3316 bool* ok) { | 3391 bool* ok) { |
3317 // Function :: | 3392 // Function :: |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3717 | 3792 |
3718 if (reusable_preparser_ == NULL) { | 3793 if (reusable_preparser_ == NULL) { |
3719 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3794 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
3720 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3795 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
3721 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3796 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
3722 reusable_preparser_->set_allow_modules(allow_modules()); | 3797 reusable_preparser_->set_allow_modules(allow_modules()); |
3723 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3798 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
3724 reusable_preparser_->set_allow_lazy(true); | 3799 reusable_preparser_->set_allow_lazy(true); |
3725 reusable_preparser_->set_allow_generators(allow_generators()); | 3800 reusable_preparser_->set_allow_generators(allow_generators()); |
3726 reusable_preparser_->set_allow_for_of(allow_for_of()); | 3801 reusable_preparser_->set_allow_for_of(allow_for_of()); |
3802 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | |
3727 reusable_preparser_->set_allow_harmony_numeric_literals( | 3803 reusable_preparser_->set_allow_harmony_numeric_literals( |
3728 allow_harmony_numeric_literals()); | 3804 allow_harmony_numeric_literals()); |
3729 } | 3805 } |
3730 PreParser::PreParseResult result = | 3806 PreParser::PreParseResult result = |
3731 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3807 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
3732 is_generator(), | 3808 is_generator(), |
3733 logger); | 3809 logger); |
3734 return result; | 3810 return result; |
3735 } | 3811 } |
3736 | 3812 |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4835 ASSERT(ast_value_factory_->IsInternalized()); | 4911 ASSERT(ast_value_factory_->IsInternalized()); |
4836 // info takes ownership of ast_value_factory_. | 4912 // info takes ownership of ast_value_factory_. |
4837 if (info()->ast_value_factory() == NULL) { | 4913 if (info()->ast_value_factory() == NULL) { |
4838 info()->SetAstValueFactory(ast_value_factory_); | 4914 info()->SetAstValueFactory(ast_value_factory_); |
4839 } | 4915 } |
4840 ast_value_factory_ = NULL; | 4916 ast_value_factory_ = NULL; |
4841 return (result != NULL); | 4917 return (result != NULL); |
4842 } | 4918 } |
4843 | 4919 |
4844 } } // namespace v8::internal | 4920 } } // namespace v8::internal |
OLD | NEW |