Chromium Code Reviews

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: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/runtime.cc » ('j') | src/runtime.cc » ('J')
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...)
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 65 matching lines...)
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_);
749 752
753 if (info->strict_mode()) {
754 temp_scope.EnableStrictMode();
755 }
756
750 FunctionLiteralType type = 757 FunctionLiteralType type =
751 info->is_expression() ? EXPRESSION : DECLARATION; 758 info->is_expression() ? EXPRESSION : DECLARATION;
752 bool ok = true; 759 bool ok = true;
753 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); 760 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok);
754 // Make sure the results agree. 761 // Make sure the results agree.
755 ASSERT(ok == (result != NULL)); 762 ASSERT(ok == (result != NULL));
756 // The only errors should be stack overflows. 763 // The only errors should be stack overflows.
757 ASSERT(ok || stack_overflow_); 764 ASSERT(ok || stack_overflow_);
758 } 765 }
759 766
(...skipping 4258 matching lines...)
5018 Vector<const char*> args = pre_data->BuildArgs(); 5025 Vector<const char*> args = pre_data->BuildArgs();
5019 parser.ReportMessageAt(loc, message, args); 5026 parser.ReportMessageAt(loc, message, args);
5020 DeleteArray(message); 5027 DeleteArray(message);
5021 for (int i = 0; i < args.length(); i++) { 5028 for (int i = 0; i < args.length(); i++) {
5022 DeleteArray(args[i]); 5029 DeleteArray(args[i]);
5023 } 5030 }
5024 DeleteArray(args.start()); 5031 DeleteArray(args.start());
5025 ASSERT(Top::has_pending_exception()); 5032 ASSERT(Top::has_pending_exception());
5026 } else { 5033 } else {
5027 Handle<String> source = Handle<String>(String::cast(script->source())); 5034 Handle<String> source = Handle<String>(String::cast(script->source()));
5028 result = parser.ParseProgram(source, info->is_global()); 5035 result = parser.ParseProgram(source,
5036 info->is_global(),
5037 info->is_strict());
5029 } 5038 }
5030 } 5039 }
5031 5040
5032 info->SetFunction(result); 5041 info->SetFunction(result);
5033 return (result != NULL); 5042 return (result != NULL);
5034 } 5043 }
5035 5044
5036 } } // namespace v8::internal 5045 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/runtime.cc » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine