Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 extension_(extension), | 609 extension_(extension), |
| 610 pre_data_(pre_data), | 610 pre_data_(pre_data), |
| 611 fni_(NULL), | 611 fni_(NULL), |
| 612 stack_overflow_(false), | 612 stack_overflow_(false), |
| 613 parenthesized_function_(false) { | 613 parenthesized_function_(false) { |
| 614 AstNode::ResetIds(); | 614 AstNode::ResetIds(); |
| 615 } | 615 } |
| 616 | 616 |
| 617 | 617 |
| 618 FunctionLiteral* Parser::ParseProgram(Handle<String> source, | 618 FunctionLiteral* Parser::ParseProgram(Handle<String> source, |
| 619 bool in_global_context) { | 619 bool in_global_context, |
| 620 bool strict_mode) { | |
| 620 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); | 621 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); |
| 621 | 622 |
| 622 HistogramTimerScope timer(&Counters::parse); | 623 HistogramTimerScope timer(&Counters::parse); |
| 623 Counters::total_parse_size.Increment(source->length()); | 624 Counters::total_parse_size.Increment(source->length()); |
| 624 fni_ = new FuncNameInferrer(); | 625 fni_ = new FuncNameInferrer(); |
| 625 | 626 |
| 626 // Initialize parser state. | 627 // Initialize parser state. |
| 627 source->TryFlatten(); | 628 source->TryFlatten(); |
| 628 if (source->IsExternalTwoByteString()) { | 629 if (source->IsExternalTwoByteString()) { |
| 629 // Notice that the stream is destroyed at the end of the branch block. | 630 // Notice that the stream is destroyed at the end of the branch block. |
| 630 // The last line of the blocks can't be moved outside, even though they're | 631 // The last line of the blocks can't be moved outside, even though they're |
| 631 // identical calls. | 632 // identical calls. |
| 632 ExternalTwoByteStringUC16CharacterStream stream( | 633 ExternalTwoByteStringUC16CharacterStream stream( |
| 633 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 634 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
| 634 scanner_.Initialize(&stream); | 635 scanner_.Initialize(&stream); |
| 635 return DoParseProgram(source, in_global_context, &zone_scope); | 636 return DoParseProgram(source, in_global_context, strict_mode, &zone_scope); |
| 636 } else { | 637 } else { |
| 637 GenericStringUC16CharacterStream stream(source, 0, source->length()); | 638 GenericStringUC16CharacterStream stream(source, 0, source->length()); |
| 638 scanner_.Initialize(&stream); | 639 scanner_.Initialize(&stream); |
| 639 return DoParseProgram(source, in_global_context, &zone_scope); | 640 return DoParseProgram(source, in_global_context, strict_mode, &zone_scope); |
| 640 } | 641 } |
| 641 } | 642 } |
| 642 | 643 |
| 643 | 644 |
| 644 FunctionLiteral* Parser::DoParseProgram(Handle<String> source, | 645 FunctionLiteral* Parser::DoParseProgram(Handle<String> source, |
| 645 bool in_global_context, | 646 bool in_global_context, |
| 647 bool strict_mode, | |
| 646 ZoneScope* zone_scope) { | 648 ZoneScope* zone_scope) { |
| 647 ASSERT(target_stack_ == NULL); | 649 ASSERT(target_stack_ == NULL); |
| 648 if (pre_data_ != NULL) pre_data_->Initialize(); | 650 if (pre_data_ != NULL) pre_data_->Initialize(); |
| 649 | 651 |
| 650 // Compute the parsing mode. | 652 // Compute the parsing mode. |
| 651 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; | 653 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; |
| 652 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; | 654 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; |
| 653 | 655 |
| 654 Scope::Type type = | 656 Scope::Type type = |
| 655 in_global_context | 657 in_global_context |
| 656 ? Scope::GLOBAL_SCOPE | 658 ? Scope::GLOBAL_SCOPE |
| 657 : Scope::EVAL_SCOPE; | 659 : Scope::EVAL_SCOPE; |
| 658 Handle<String> no_name = Factory::empty_symbol(); | 660 Handle<String> no_name = Factory::empty_symbol(); |
| 659 | 661 |
| 660 FunctionLiteral* result = NULL; | 662 FunctionLiteral* result = NULL; |
| 661 { Scope* scope = NewScope(top_scope_, type, inside_with()); | 663 { Scope* scope = NewScope(top_scope_, type, inside_with()); |
| 662 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, | 664 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, |
| 663 scope); | 665 scope); |
| 664 TemporaryScope temp_scope(&this->temp_scope_); | 666 TemporaryScope temp_scope(&this->temp_scope_); |
| 667 if (strict_mode) temp_scope.EnableStrictMode(); | |
| 665 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); | 668 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); |
| 666 bool ok = true; | 669 bool ok = true; |
| 667 int beg_loc = scanner().location().beg_pos; | 670 int beg_loc = scanner().location().beg_pos; |
| 668 ParseSourceElements(body, Token::EOS, &ok); | 671 ParseSourceElements(body, Token::EOS, &ok); |
| 669 if (ok && temp_scope_->StrictMode()) { | 672 if (ok && temp_scope_->StrictMode()) { |
| 670 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 673 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
| 671 } | 674 } |
| 672 if (ok) { | 675 if (ok) { |
| 673 result = new FunctionLiteral( | 676 result = new FunctionLiteral( |
| 674 no_name, | 677 no_name, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 FunctionLiteral* result = NULL; | 742 FunctionLiteral* result = NULL; |
| 740 | 743 |
| 741 { | 744 { |
| 742 // Parse the function literal. | 745 // Parse the function literal. |
| 743 Handle<String> no_name = Factory::empty_symbol(); | 746 Handle<String> no_name = Factory::empty_symbol(); |
| 744 Scope* scope = | 747 Scope* scope = |
| 745 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); | 748 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); |
| 746 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, | 749 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, |
| 747 scope); | 750 scope); |
| 748 TemporaryScope temp_scope(&this->temp_scope_); | 751 TemporaryScope temp_scope(&this->temp_scope_); |
| 752 if (info->strict_mode()) { | |
| 753 temp_scope.EnableStrictMode(); | |
| 754 } | |
| 749 | 755 |
| 750 FunctionLiteralType type = | 756 FunctionLiteralType type = |
| 751 info->is_expression() ? EXPRESSION : DECLARATION; | 757 info->is_expression() ? EXPRESSION : DECLARATION; |
| 752 bool ok = true; | 758 bool ok = true; |
| 753 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); | 759 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); |
| 754 // Make sure the results agree. | 760 // Make sure the results agree. |
| 755 ASSERT(ok == (result != NULL)); | 761 ASSERT(ok == (result != NULL)); |
| 756 // The only errors should be stack overflows. | 762 // The only errors should be stack overflows. |
| 757 ASSERT(ok || stack_overflow_); | 763 ASSERT(ok || stack_overflow_); |
| 758 } | 764 } |
| (...skipping 2774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3533 materialized_literal_count = temp_scope.materialized_literal_count(); | 3539 materialized_literal_count = temp_scope.materialized_literal_count(); |
| 3534 expected_property_count = temp_scope.expected_property_count(); | 3540 expected_property_count = temp_scope.expected_property_count(); |
| 3535 only_simple_this_property_assignments = | 3541 only_simple_this_property_assignments = |
| 3536 temp_scope.only_simple_this_property_assignments(); | 3542 temp_scope.only_simple_this_property_assignments(); |
| 3537 this_property_assignments = temp_scope.this_property_assignments(); | 3543 this_property_assignments = temp_scope.this_property_assignments(); |
| 3538 | 3544 |
| 3539 Expect(Token::RBRACE, CHECK_OK); | 3545 Expect(Token::RBRACE, CHECK_OK); |
| 3540 end_pos = scanner().location().end_pos; | 3546 end_pos = scanner().location().end_pos; |
| 3541 } | 3547 } |
| 3542 | 3548 |
| 3543 // Validate strict mode. | 3549 // Strict mode. |
| 3544 if (temp_scope_->StrictMode()) { | 3550 if (temp_scope_->StrictMode()) { |
| 3545 if (IsEvalOrArguments(name)) { | 3551 if (IsEvalOrArguments(name)) { |
| 3546 int position = function_token_position != RelocInfo::kNoPosition | 3552 int position = function_token_position != RelocInfo::kNoPosition |
| 3547 ? function_token_position | 3553 ? function_token_position |
| 3548 : (start_pos > 0 ? start_pos - 1 : start_pos); | 3554 : (start_pos > 0 ? start_pos - 1 : start_pos); |
| 3549 ReportMessageAt(Scanner::Location(position, start_pos), | 3555 ReportMessageAt(Scanner::Location(position, start_pos), |
| 3550 "strict_function_name", Vector<const char*>::empty()); | 3556 "strict_function_name", Vector<const char*>::empty()); |
| 3551 *ok = false; | 3557 *ok = false; |
| 3552 return NULL; | 3558 return NULL; |
| 3553 } | 3559 } |
| 3554 if (name_loc.IsValid()) { | 3560 if (name_loc.IsValid()) { |
| 3555 ReportMessageAt(name_loc, "strict_param_name", | 3561 ReportMessageAt(name_loc, "strict_param_name", |
| 3556 Vector<const char*>::empty()); | 3562 Vector<const char*>::empty()); |
| 3557 *ok = false; | 3563 *ok = false; |
| 3558 return NULL; | 3564 return NULL; |
| 3559 } | 3565 } |
| 3560 if (dupe_loc.IsValid()) { | 3566 if (dupe_loc.IsValid()) { |
| 3561 ReportMessageAt(dupe_loc, "strict_param_dupe", | 3567 ReportMessageAt(dupe_loc, "strict_param_dupe", |
| 3562 Vector<const char*>::empty()); | 3568 Vector<const char*>::empty()); |
| 3563 *ok = false; | 3569 *ok = false; |
| 3564 return NULL; | 3570 return NULL; |
| 3565 } | 3571 } |
| 3566 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); | 3572 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); |
| 3573 | |
| 3574 // In strict mode, arguments are const. | |
| 3575 top_scope_->SetAttributesConst(); | |
|
Lasse Reichstein
2011/02/01 11:26:24
Attributes? Should that be "Arguments"?
| |
| 3567 } | 3576 } |
| 3568 | 3577 |
| 3569 FunctionLiteral* function_literal = | 3578 FunctionLiteral* function_literal = |
| 3570 new FunctionLiteral(name, | 3579 new FunctionLiteral(name, |
| 3571 top_scope_, | 3580 top_scope_, |
| 3572 body, | 3581 body, |
| 3573 materialized_literal_count, | 3582 materialized_literal_count, |
| 3574 expected_property_count, | 3583 expected_property_count, |
| 3575 only_simple_this_property_assignments, | 3584 only_simple_this_property_assignments, |
| 3576 this_property_assignments, | 3585 this_property_assignments, |
| (...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5018 Vector<const char*> args = pre_data->BuildArgs(); | 5027 Vector<const char*> args = pre_data->BuildArgs(); |
| 5019 parser.ReportMessageAt(loc, message, args); | 5028 parser.ReportMessageAt(loc, message, args); |
| 5020 DeleteArray(message); | 5029 DeleteArray(message); |
| 5021 for (int i = 0; i < args.length(); i++) { | 5030 for (int i = 0; i < args.length(); i++) { |
| 5022 DeleteArray(args[i]); | 5031 DeleteArray(args[i]); |
| 5023 } | 5032 } |
| 5024 DeleteArray(args.start()); | 5033 DeleteArray(args.start()); |
| 5025 ASSERT(Top::has_pending_exception()); | 5034 ASSERT(Top::has_pending_exception()); |
| 5026 } else { | 5035 } else { |
| 5027 Handle<String> source = Handle<String>(String::cast(script->source())); | 5036 Handle<String> source = Handle<String>(String::cast(script->source())); |
| 5028 result = parser.ParseProgram(source, info->is_global()); | 5037 result = parser.ParseProgram(source, |
| 5038 info->is_global(), | |
| 5039 info->is_strict()); | |
| 5029 } | 5040 } |
| 5030 } | 5041 } |
| 5031 | 5042 |
| 5032 info->SetFunction(result); | 5043 info->SetFunction(result); |
| 5033 return (result != NULL); | 5044 return (result != NULL); |
| 5034 } | 5045 } |
| 5035 | 5046 |
| 5036 } } // namespace v8::internal | 5047 } } // namespace v8::internal |
| OLD | NEW |