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 AstString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 674 const AstString* 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 2498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3295 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); | 3297 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
3296 return static_cast<LiteralType>(literal_type->value()); | 3298 return static_cast<LiteralType>(literal_type->value()); |
3297 } | 3299 } |
3298 | 3300 |
3299 | 3301 |
3300 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3302 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3301 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3303 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3302 } | 3304 } |
3303 | 3305 |
3304 | 3306 |
| 3307 Vector<VariableProxy*> ParserTraits::ParameterListFromExpression( |
| 3308 Expression* expression, bool* ok) { |
| 3309 |
| 3310 // Parsing the parameter list of an arrow function does not have parameters |
| 3311 // (as in: () => ...) returns NULL, so expression being NULL is not an error, |
| 3312 // but an valid empty parameter list. |
| 3313 if (expression == NULL) |
| 3314 return Vector<VariableProxy*>::empty(); |
| 3315 |
| 3316 const char* error_token = NULL; |
| 3317 Collector<VariableProxy*> collector; |
| 3318 |
| 3319 while (expression->IsBinaryOperation()) { |
| 3320 BinaryOperation* binop = expression->AsBinaryOperation(); |
| 3321 |
| 3322 if (binop->op() != Token::COMMA) { |
| 3323 error_token = Token::String(expression->AsBinaryOperation()->op()); |
| 3324 break; |
| 3325 } |
| 3326 |
| 3327 expression = binop->right(); |
| 3328 if (!expression->IsVariableProxy()) { |
| 3329 error_token = ""; |
| 3330 break; |
| 3331 } |
| 3332 if (expression->AsVariableProxy()->is_this()) { |
| 3333 error_token = Token::String(Token::THIS); |
| 3334 break; |
| 3335 } |
| 3336 |
| 3337 collector.Add(expression->AsVariableProxy()); |
| 3338 expression = binop->left(); |
| 3339 } |
| 3340 |
| 3341 // No errors were found in the loop above, try to add the remaining item. |
| 3342 if (error_token == NULL) { |
| 3343 if (!expression->IsVariableProxy()) { |
| 3344 error_token = ""; |
| 3345 } else if (expression->AsVariableProxy()->is_this()) { |
| 3346 error_token = Token::String(Token::THIS); |
| 3347 } else { |
| 3348 collector.Add(expression->AsVariableProxy()); |
| 3349 return collector.ToVector(); |
| 3350 } |
| 3351 } |
| 3352 |
| 3353 // Report errors. |
| 3354 ASSERT_NE(error_token, NULL); |
| 3355 int error_pos = expression->position(); |
| 3356 int error_token_len = strlen(error_token); |
| 3357 ParserTraits::ReportMessageAt( |
| 3358 Scanner::Location(error_pos, |
| 3359 error_pos + error_token_len ? error_token_len : 1), |
| 3360 "unexpected_token", |
| 3361 error_token); |
| 3362 *ok = false; |
| 3363 return Vector<VariableProxy*>::empty(); |
| 3364 } |
| 3365 |
| 3366 |
3305 FunctionLiteral* Parser::ParseFunctionLiteral( | 3367 FunctionLiteral* Parser::ParseFunctionLiteral( |
3306 const AstString* function_name, | 3368 const AstString* function_name, |
3307 Scanner::Location function_name_location, | 3369 Scanner::Location function_name_location, |
3308 bool name_is_strict_reserved, | 3370 bool name_is_strict_reserved, |
3309 bool is_generator, | 3371 bool is_generator, |
3310 int function_token_pos, | 3372 int function_token_pos, |
3311 FunctionLiteral::FunctionType function_type, | 3373 FunctionLiteral::FunctionType function_type, |
3312 FunctionLiteral::ArityRestriction arity_restriction, | 3374 FunctionLiteral::ArityRestriction arity_restriction, |
3313 bool* ok) { | 3375 bool* ok) { |
3314 // Function :: | 3376 // Function :: |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3515 SkipLazyFunctionBody(function_name, &materialized_literal_count, | 3577 SkipLazyFunctionBody(function_name, &materialized_literal_count, |
3516 &expected_property_count, CHECK_OK); | 3578 &expected_property_count, CHECK_OK); |
3517 } else { | 3579 } else { |
3518 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op, | 3580 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op, |
3519 is_generator, CHECK_OK); | 3581 is_generator, CHECK_OK); |
3520 materialized_literal_count = function_state.materialized_literal_count(); | 3582 materialized_literal_count = function_state.materialized_literal_count(); |
3521 expected_property_count = function_state.expected_property_count(); | 3583 expected_property_count = function_state.expected_property_count(); |
3522 handler_count = function_state.handler_count(); | 3584 handler_count = function_state.handler_count(); |
3523 } | 3585 } |
3524 | 3586 |
3525 // Validate strict mode. We can do this only after parsing the function, | 3587 // Validate strict mode. |
3526 // since the function can declare itself strict. | |
3527 if (strict_mode() == STRICT) { | 3588 if (strict_mode() == STRICT) { |
3528 if (IsEvalOrArguments(function_name)) { | 3589 CheckStrictFunctionNameAndParameters(function_name, |
3529 ReportMessageAt(function_name_location, "strict_eval_arguments"); | 3590 name_is_strict_reserved, |
3530 *ok = false; | 3591 function_name_location, |
3531 return NULL; | 3592 eval_args_error_log, |
3532 } | 3593 dupe_error_loc, |
3533 if (name_is_strict_reserved) { | 3594 reserved_loc, |
3534 ReportMessageAt(function_name_location, "unexpected_strict_reserved"); | 3595 CHECK_OK); |
3535 *ok = false; | |
3536 return NULL; | |
3537 } | |
3538 if (eval_args_error_log.IsValid()) { | |
3539 ReportMessageAt(eval_args_error_log, "strict_eval_arguments"); | |
3540 *ok = false; | |
3541 return NULL; | |
3542 } | |
3543 if (dupe_error_loc.IsValid()) { | |
3544 ReportMessageAt(dupe_error_loc, "strict_param_dupe"); | |
3545 *ok = false; | |
3546 return NULL; | |
3547 } | |
3548 if (reserved_loc.IsValid()) { | |
3549 ReportMessageAt(reserved_loc, "unexpected_strict_reserved"); | |
3550 *ok = false; | |
3551 return NULL; | |
3552 } | |
3553 CheckOctalLiteral(scope->start_position(), | 3596 CheckOctalLiteral(scope->start_position(), |
3554 scope->end_position(), | 3597 scope->end_position(), |
3555 CHECK_OK); | 3598 CHECK_OK); |
3556 } | 3599 } |
3557 ast_properties = *factory()->visitor()->ast_properties(); | 3600 ast_properties = *factory()->visitor()->ast_properties(); |
3558 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); | 3601 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); |
3559 } | 3602 } |
3560 | 3603 |
3561 if (allow_harmony_scoping() && strict_mode() == STRICT) { | 3604 if (allow_harmony_scoping() && strict_mode() == STRICT) { |
3562 CheckConflictingVarDeclarations(scope, CHECK_OK); | 3605 CheckConflictingVarDeclarations(scope, CHECK_OK); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3733 | 3776 |
3734 if (reusable_preparser_ == NULL) { | 3777 if (reusable_preparser_ == NULL) { |
3735 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3778 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); |
3736 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | 3779 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); |
3737 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3780 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
3738 reusable_preparser_->set_allow_modules(allow_modules()); | 3781 reusable_preparser_->set_allow_modules(allow_modules()); |
3739 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3782 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
3740 reusable_preparser_->set_allow_lazy(true); | 3783 reusable_preparser_->set_allow_lazy(true); |
3741 reusable_preparser_->set_allow_generators(allow_generators()); | 3784 reusable_preparser_->set_allow_generators(allow_generators()); |
3742 reusable_preparser_->set_allow_for_of(allow_for_of()); | 3785 reusable_preparser_->set_allow_for_of(allow_for_of()); |
| 3786 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); |
3743 reusable_preparser_->set_allow_harmony_numeric_literals( | 3787 reusable_preparser_->set_allow_harmony_numeric_literals( |
3744 allow_harmony_numeric_literals()); | 3788 allow_harmony_numeric_literals()); |
3745 } | 3789 } |
3746 PreParser::PreParseResult result = | 3790 PreParser::PreParseResult result = |
3747 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 3791 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
3748 is_generator(), | 3792 is_generator(), |
3749 logger); | 3793 logger); |
3750 return result; | 3794 return result; |
3751 } | 3795 } |
3752 | 3796 |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4850 ASSERT(ast_value_factory_->IsInternalized()); | 4894 ASSERT(ast_value_factory_->IsInternalized()); |
4851 // info takes ownership of ast_value_factory_. | 4895 // info takes ownership of ast_value_factory_. |
4852 if (info()->ast_value_factory() == NULL) { | 4896 if (info()->ast_value_factory() == NULL) { |
4853 info()->SetAstValueFactory(ast_value_factory_); | 4897 info()->SetAstValueFactory(ast_value_factory_); |
4854 } | 4898 } |
4855 ast_value_factory_ = NULL; | 4899 ast_value_factory_ = NULL; |
4856 return (result != NULL); | 4900 return (result != NULL); |
4857 } | 4901 } |
4858 | 4902 |
4859 } } // namespace v8::internal | 4903 } } // namespace v8::internal |
OLD | NEW |