Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/parser.cc

Issue 6286043: Direct call to eval passes strict mode through. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review feedback. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
668 temp_scope.EnableStrictMode();
669 }
665 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); 670 ZoneList<Statement*>* body = new ZoneList<Statement*>(16);
666 bool ok = true; 671 bool ok = true;
667 int beg_loc = scanner().location().beg_pos; 672 int beg_loc = scanner().location().beg_pos;
668 ParseSourceElements(body, Token::EOS, &ok); 673 ParseSourceElements(body, Token::EOS, &ok);
669 if (ok && temp_scope_->StrictMode()) { 674 if (ok && temp_scope_->StrictMode()) {
670 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); 675 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok);
671 } 676 }
672 if (ok) { 677 if (ok) {
673 result = new FunctionLiteral( 678 result = new FunctionLiteral(
674 no_name, 679 no_name,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 745
741 { 746 {
742 // Parse the function literal. 747 // Parse the function literal.
743 Handle<String> no_name = Factory::empty_symbol(); 748 Handle<String> no_name = Factory::empty_symbol();
744 Scope* scope = 749 Scope* scope =
745 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 750 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
746 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 751 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
747 scope); 752 scope);
748 TemporaryScope temp_scope(&this->temp_scope_); 753 TemporaryScope temp_scope(&this->temp_scope_);
749 754
755 if (info->strict_mode()) {
756 temp_scope.EnableStrictMode();
757 }
758
750 FunctionLiteralType type = 759 FunctionLiteralType type =
751 info->is_expression() ? EXPRESSION : DECLARATION; 760 info->is_expression() ? EXPRESSION : DECLARATION;
752 bool ok = true; 761 bool ok = true;
753 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); 762 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok);
754 // Make sure the results agree. 763 // Make sure the results agree.
755 ASSERT(ok == (result != NULL)); 764 ASSERT(ok == (result != NULL));
756 // The only errors should be stack overflows. 765 // The only errors should be stack overflows.
757 ASSERT(ok || stack_overflow_); 766 ASSERT(ok || stack_overflow_);
758 } 767 }
759 768
(...skipping 4258 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698