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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // Bookkeeping | 303 // Bookkeeping |
304 TemporaryScope** variable_; | 304 TemporaryScope** variable_; |
305 TemporaryScope* parent_; | 305 TemporaryScope* parent_; |
306 }; | 306 }; |
307 | 307 |
308 | 308 |
309 TemporaryScope::TemporaryScope(TemporaryScope** variable) | 309 TemporaryScope::TemporaryScope(TemporaryScope** variable) |
310 : materialized_literal_count_(0), | 310 : materialized_literal_count_(0), |
311 expected_property_count_(0), | 311 expected_property_count_(0), |
312 only_simple_this_property_assignments_(false), | 312 only_simple_this_property_assignments_(false), |
313 this_property_assignments_(Factory::empty_fixed_array()), | 313 this_property_assignments_( |
| 314 Isolate::Current()->factory()->empty_fixed_array()), |
314 loop_count_(0), | 315 loop_count_(0), |
315 variable_(variable), | 316 variable_(variable), |
316 parent_(*variable) { | 317 parent_(*variable) { |
317 *variable = this; | 318 *variable = this; |
318 } | 319 } |
319 | 320 |
320 | 321 |
321 TemporaryScope::~TemporaryScope() { | 322 TemporaryScope::~TemporaryScope() { |
322 *variable_ = parent_; | 323 *variable_ = parent_; |
323 } | 324 } |
324 | 325 |
325 | 326 |
326 Handle<String> Parser::LookupSymbol(int symbol_id) { | 327 Handle<String> Parser::LookupSymbol(int symbol_id) { |
327 // Length of symbol cache is the number of identified symbols. | 328 // Length of symbol cache is the number of identified symbols. |
328 // If we are larger than that, or negative, it's not a cached symbol. | 329 // If we are larger than that, or negative, it's not a cached symbol. |
329 // This might also happen if there is no preparser symbol data, even | 330 // This might also happen if there is no preparser symbol data, even |
330 // if there is some preparser data. | 331 // if there is some preparser data. |
331 if (static_cast<unsigned>(symbol_id) | 332 if (static_cast<unsigned>(symbol_id) |
332 >= static_cast<unsigned>(symbol_cache_.length())) { | 333 >= static_cast<unsigned>(symbol_cache_.length())) { |
333 if (scanner().is_literal_ascii()) { | 334 if (scanner().is_literal_ascii()) { |
334 return Factory::LookupAsciiSymbol(scanner().literal_ascii_string()); | 335 return isolate()->factory()->LookupAsciiSymbol( |
| 336 scanner().literal_ascii_string()); |
335 } else { | 337 } else { |
336 return Factory::LookupTwoByteSymbol(scanner().literal_uc16_string()); | 338 return isolate()->factory()->LookupTwoByteSymbol( |
| 339 scanner().literal_uc16_string()); |
337 } | 340 } |
338 } | 341 } |
339 return LookupCachedSymbol(symbol_id); | 342 return LookupCachedSymbol(symbol_id); |
340 } | 343 } |
341 | 344 |
342 | 345 |
343 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { | 346 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { |
344 // Make sure the cache is large enough to hold the symbol identifier. | 347 // Make sure the cache is large enough to hold the symbol identifier. |
345 if (symbol_cache_.length() <= symbol_id) { | 348 if (symbol_cache_.length() <= symbol_id) { |
346 // Increase length to index + 1. | 349 // Increase length to index + 1. |
347 symbol_cache_.AddBlock(Handle<String>::null(), | 350 symbol_cache_.AddBlock(Handle<String>::null(), |
348 symbol_id + 1 - symbol_cache_.length()); | 351 symbol_id + 1 - symbol_cache_.length()); |
349 } | 352 } |
350 Handle<String> result = symbol_cache_.at(symbol_id); | 353 Handle<String> result = symbol_cache_.at(symbol_id); |
351 if (result.is_null()) { | 354 if (result.is_null()) { |
352 if (scanner().is_literal_ascii()) { | 355 if (scanner().is_literal_ascii()) { |
353 result = Factory::LookupAsciiSymbol(scanner().literal_ascii_string()); | 356 result = isolate()->factory()->LookupAsciiSymbol( |
| 357 scanner().literal_ascii_string()); |
354 } else { | 358 } else { |
355 result = Factory::LookupTwoByteSymbol(scanner().literal_uc16_string()); | 359 result = isolate()->factory()->LookupTwoByteSymbol( |
| 360 scanner().literal_uc16_string()); |
356 } | 361 } |
357 symbol_cache_.at(symbol_id) = result; | 362 symbol_cache_.at(symbol_id) = result; |
358 return result; | 363 return result; |
359 } | 364 } |
360 Counters::total_preparse_symbols_skipped.Increment(); | 365 COUNTERS->total_preparse_symbols_skipped()->Increment(); |
361 return result; | 366 return result; |
362 } | 367 } |
363 | 368 |
364 | 369 |
365 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { | 370 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { |
366 // The current pre-data entry must be a FunctionEntry with the given | 371 // The current pre-data entry must be a FunctionEntry with the given |
367 // start position. | 372 // start position. |
368 if ((function_index_ + FunctionEntry::kSize <= store_.length()) | 373 if ((function_index_ + FunctionEntry::kSize <= store_.length()) |
369 && (static_cast<int>(store_[function_index_]) == start)) { | 374 && (static_cast<int>(store_[function_index_]) == start)) { |
370 int index = function_index_; | 375 int index = function_index_; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 #define DUMMY ) // to make indentation work | 586 #define DUMMY ) // to make indentation work |
582 #undef DUMMY | 587 #undef DUMMY |
583 | 588 |
584 // ---------------------------------------------------------------------------- | 589 // ---------------------------------------------------------------------------- |
585 // Implementation of Parser | 590 // Implementation of Parser |
586 | 591 |
587 Parser::Parser(Handle<Script> script, | 592 Parser::Parser(Handle<Script> script, |
588 bool allow_natives_syntax, | 593 bool allow_natives_syntax, |
589 v8::Extension* extension, | 594 v8::Extension* extension, |
590 ScriptDataImpl* pre_data) | 595 ScriptDataImpl* pre_data) |
591 : symbol_cache_(pre_data ? pre_data->symbol_count() : 0), | 596 : isolate_(script->GetIsolate()), |
| 597 symbol_cache_(pre_data ? pre_data->symbol_count() : 0), |
592 script_(script), | 598 script_(script), |
593 scanner_(), | 599 scanner_(isolate_), |
594 top_scope_(NULL), | 600 top_scope_(NULL), |
595 with_nesting_level_(0), | 601 with_nesting_level_(0), |
596 temp_scope_(NULL), | 602 temp_scope_(NULL), |
597 target_stack_(NULL), | 603 target_stack_(NULL), |
598 allow_natives_syntax_(allow_natives_syntax), | 604 allow_natives_syntax_(allow_natives_syntax), |
599 extension_(extension), | 605 extension_(extension), |
600 pre_data_(pre_data), | 606 pre_data_(pre_data), |
601 fni_(NULL), | 607 fni_(NULL), |
602 stack_overflow_(false), | 608 stack_overflow_(false), |
603 parenthesized_function_(false) { | 609 parenthesized_function_(false) { |
604 AstNode::ResetIds(); | 610 AstNode::ResetIds(); |
605 } | 611 } |
606 | 612 |
607 | 613 |
608 FunctionLiteral* Parser::ParseProgram(Handle<String> source, | 614 FunctionLiteral* Parser::ParseProgram(Handle<String> source, |
609 bool in_global_context, | 615 bool in_global_context, |
610 StrictModeFlag strict_mode) { | 616 StrictModeFlag strict_mode) { |
611 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); | 617 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); |
612 | 618 |
613 HistogramTimerScope timer(&Counters::parse); | 619 HistogramTimerScope timer(COUNTERS->parse()); |
614 Counters::total_parse_size.Increment(source->length()); | 620 COUNTERS->total_parse_size()->Increment(source->length()); |
615 fni_ = new FuncNameInferrer(); | 621 fni_ = new FuncNameInferrer(); |
616 | 622 |
617 // Initialize parser state. | 623 // Initialize parser state. |
618 source->TryFlatten(); | 624 source->TryFlatten(); |
619 if (source->IsExternalTwoByteString()) { | 625 if (source->IsExternalTwoByteString()) { |
620 // Notice that the stream is destroyed at the end of the branch block. | 626 // Notice that the stream is destroyed at the end of the branch block. |
621 // The last line of the blocks can't be moved outside, even though they're | 627 // The last line of the blocks can't be moved outside, even though they're |
622 // identical calls. | 628 // identical calls. |
623 ExternalTwoByteStringUC16CharacterStream stream( | 629 ExternalTwoByteStringUC16CharacterStream stream( |
624 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 630 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
(...skipping 15 matching lines...) Expand all Loading... |
640 if (pre_data_ != NULL) pre_data_->Initialize(); | 646 if (pre_data_ != NULL) pre_data_->Initialize(); |
641 | 647 |
642 // Compute the parsing mode. | 648 // Compute the parsing mode. |
643 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; | 649 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; |
644 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; | 650 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; |
645 | 651 |
646 Scope::Type type = | 652 Scope::Type type = |
647 in_global_context | 653 in_global_context |
648 ? Scope::GLOBAL_SCOPE | 654 ? Scope::GLOBAL_SCOPE |
649 : Scope::EVAL_SCOPE; | 655 : Scope::EVAL_SCOPE; |
650 Handle<String> no_name = Factory::empty_symbol(); | 656 Handle<String> no_name = isolate()->factory()->empty_symbol(); |
651 | 657 |
652 FunctionLiteral* result = NULL; | 658 FunctionLiteral* result = NULL; |
653 { Scope* scope = NewScope(top_scope_, type, inside_with()); | 659 { Scope* scope = NewScope(top_scope_, type, inside_with()); |
654 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, | 660 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, |
655 scope); | 661 scope); |
656 TemporaryScope temp_scope(&this->temp_scope_); | 662 TemporaryScope temp_scope(&this->temp_scope_); |
657 if (strict_mode == kStrictMode) { | 663 if (strict_mode == kStrictMode) { |
658 top_scope_->EnableStrictMode(); | 664 top_scope_->EnableStrictMode(); |
659 } | 665 } |
660 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); | 666 ZoneList<Statement*>* body = new ZoneList<Statement*>(16); |
(...skipping 11 matching lines...) Expand all Loading... |
672 temp_scope.materialized_literal_count(), | 678 temp_scope.materialized_literal_count(), |
673 temp_scope.expected_property_count(), | 679 temp_scope.expected_property_count(), |
674 temp_scope.only_simple_this_property_assignments(), | 680 temp_scope.only_simple_this_property_assignments(), |
675 temp_scope.this_property_assignments(), | 681 temp_scope.this_property_assignments(), |
676 0, | 682 0, |
677 0, | 683 0, |
678 source->length(), | 684 source->length(), |
679 false, | 685 false, |
680 temp_scope.ContainsLoops()); | 686 temp_scope.ContainsLoops()); |
681 } else if (stack_overflow_) { | 687 } else if (stack_overflow_) { |
682 Top::StackOverflow(); | 688 isolate()->StackOverflow(); |
683 } | 689 } |
684 } | 690 } |
685 | 691 |
686 // Make sure the target stack is empty. | 692 // Make sure the target stack is empty. |
687 ASSERT(target_stack_ == NULL); | 693 ASSERT(target_stack_ == NULL); |
688 | 694 |
689 // If there was a syntax error we have to get rid of the AST | 695 // If there was a syntax error we have to get rid of the AST |
690 // and it is not safe to do so before the scope has been deleted. | 696 // and it is not safe to do so before the scope has been deleted. |
691 if (result == NULL) zone_scope->DeleteOnExit(); | 697 if (result == NULL) zone_scope->DeleteOnExit(); |
692 return result; | 698 return result; |
693 } | 699 } |
694 | 700 |
695 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info) { | 701 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info) { |
696 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); | 702 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); |
697 HistogramTimerScope timer(&Counters::parse_lazy); | 703 HistogramTimerScope timer(COUNTERS->parse_lazy()); |
698 Handle<String> source(String::cast(script_->source())); | 704 Handle<String> source(String::cast(script_->source())); |
699 Counters::total_parse_size.Increment(source->length()); | 705 COUNTERS->total_parse_size()->Increment(source->length()); |
700 | 706 |
701 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 707 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
702 // Initialize parser state. | 708 // Initialize parser state. |
703 source->TryFlatten(); | 709 source->TryFlatten(); |
704 if (source->IsExternalTwoByteString()) { | 710 if (source->IsExternalTwoByteString()) { |
705 ExternalTwoByteStringUC16CharacterStream stream( | 711 ExternalTwoByteStringUC16CharacterStream stream( |
706 Handle<ExternalTwoByteString>::cast(source), | 712 Handle<ExternalTwoByteString>::cast(source), |
707 shared_info->start_position(), | 713 shared_info->start_position(), |
708 shared_info->end_position()); | 714 shared_info->end_position()); |
709 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); | 715 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); |
(...skipping 19 matching lines...) Expand all Loading... |
729 fni_ = new FuncNameInferrer(); | 735 fni_ = new FuncNameInferrer(); |
730 fni_->PushEnclosingName(name); | 736 fni_->PushEnclosingName(name); |
731 | 737 |
732 mode_ = PARSE_EAGERLY; | 738 mode_ = PARSE_EAGERLY; |
733 | 739 |
734 // Place holder for the result. | 740 // Place holder for the result. |
735 FunctionLiteral* result = NULL; | 741 FunctionLiteral* result = NULL; |
736 | 742 |
737 { | 743 { |
738 // Parse the function literal. | 744 // Parse the function literal. |
739 Handle<String> no_name = Factory::empty_symbol(); | 745 Handle<String> no_name = isolate()->factory()->empty_symbol(); |
740 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); | 746 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); |
741 if (!info->closure().is_null()) { | 747 if (!info->closure().is_null()) { |
742 scope = Scope::DeserializeScopeChain(info, scope); | 748 scope = Scope::DeserializeScopeChain(info, scope); |
743 } | 749 } |
744 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, | 750 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, |
745 scope); | 751 scope); |
746 TemporaryScope temp_scope(&this->temp_scope_); | 752 TemporaryScope temp_scope(&this->temp_scope_); |
747 | 753 |
748 if (shared_info->strict_mode()) { | 754 if (shared_info->strict_mode()) { |
749 top_scope_->EnableStrictMode(); | 755 top_scope_->EnableStrictMode(); |
750 } | 756 } |
751 | 757 |
752 FunctionLiteralType type = | 758 FunctionLiteralType type = |
753 shared_info->is_expression() ? EXPRESSION : DECLARATION; | 759 shared_info->is_expression() ? EXPRESSION : DECLARATION; |
754 bool ok = true; | 760 bool ok = true; |
755 result = ParseFunctionLiteral(name, | 761 result = ParseFunctionLiteral(name, |
756 false, // Strict mode name already checked. | 762 false, // Strict mode name already checked. |
757 RelocInfo::kNoPosition, type, &ok); | 763 RelocInfo::kNoPosition, type, &ok); |
758 // Make sure the results agree. | 764 // Make sure the results agree. |
759 ASSERT(ok == (result != NULL)); | 765 ASSERT(ok == (result != NULL)); |
760 } | 766 } |
761 | 767 |
762 // Make sure the target stack is empty. | 768 // Make sure the target stack is empty. |
763 ASSERT(target_stack_ == NULL); | 769 ASSERT(target_stack_ == NULL); |
764 | 770 |
765 // If there was a stack overflow we have to get rid of AST and it is | 771 // If there was a stack overflow we have to get rid of AST and it is |
766 // not safe to do before scope has been deleted. | 772 // not safe to do before scope has been deleted. |
767 if (result == NULL) { | 773 if (result == NULL) { |
768 zone_scope->DeleteOnExit(); | 774 zone_scope->DeleteOnExit(); |
769 if (stack_overflow_) Top::StackOverflow(); | 775 if (stack_overflow_) isolate()->StackOverflow(); |
770 } else { | 776 } else { |
771 Handle<String> inferred_name(shared_info->inferred_name()); | 777 Handle<String> inferred_name(shared_info->inferred_name()); |
772 result->set_inferred_name(inferred_name); | 778 result->set_inferred_name(inferred_name); |
773 } | 779 } |
774 return result; | 780 return result; |
775 } | 781 } |
776 | 782 |
777 | 783 |
778 Handle<String> Parser::GetSymbol(bool* ok) { | 784 Handle<String> Parser::GetSymbol(bool* ok) { |
779 int symbol_id = -1; | 785 int symbol_id = -1; |
780 if (pre_data() != NULL) { | 786 if (pre_data() != NULL) { |
781 symbol_id = pre_data()->GetSymbolIdentifier(); | 787 symbol_id = pre_data()->GetSymbolIdentifier(); |
782 } | 788 } |
783 return LookupSymbol(symbol_id); | 789 return LookupSymbol(symbol_id); |
784 } | 790 } |
785 | 791 |
786 | 792 |
787 void Parser::ReportMessage(const char* type, Vector<const char*> args) { | 793 void Parser::ReportMessage(const char* type, Vector<const char*> args) { |
788 Scanner::Location source_location = scanner().location(); | 794 Scanner::Location source_location = scanner().location(); |
789 ReportMessageAt(source_location, type, args); | 795 ReportMessageAt(source_location, type, args); |
790 } | 796 } |
791 | 797 |
792 | 798 |
793 void Parser::ReportMessageAt(Scanner::Location source_location, | 799 void Parser::ReportMessageAt(Scanner::Location source_location, |
794 const char* type, | 800 const char* type, |
795 Vector<const char*> args) { | 801 Vector<const char*> args) { |
796 MessageLocation location(script_, | 802 MessageLocation location(script_, |
797 source_location.beg_pos, | 803 source_location.beg_pos, |
798 source_location.end_pos); | 804 source_location.end_pos); |
799 Handle<FixedArray> elements = Factory::NewFixedArray(args.length()); | 805 Factory* factory = isolate()->factory(); |
| 806 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); |
800 for (int i = 0; i < args.length(); i++) { | 807 for (int i = 0; i < args.length(); i++) { |
801 Handle<String> arg_string = Factory::NewStringFromUtf8(CStrVector(args[i])); | 808 Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i])); |
802 elements->set(i, *arg_string); | 809 elements->set(i, *arg_string); |
803 } | 810 } |
804 Handle<JSArray> array = Factory::NewJSArrayWithElements(elements); | 811 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
805 Handle<Object> result = Factory::NewSyntaxError(type, array); | 812 Handle<Object> result = factory->NewSyntaxError(type, array); |
806 Top::Throw(*result, &location); | 813 isolate()->Throw(*result, &location); |
807 } | 814 } |
808 | 815 |
809 | 816 |
810 void Parser::ReportMessageAt(Scanner::Location source_location, | 817 void Parser::ReportMessageAt(Scanner::Location source_location, |
811 const char* type, | 818 const char* type, |
812 Vector<Handle<String> > args) { | 819 Vector<Handle<String> > args) { |
813 MessageLocation location(script_, | 820 MessageLocation location(script_, |
814 source_location.beg_pos, | 821 source_location.beg_pos, |
815 source_location.end_pos); | 822 source_location.end_pos); |
816 Handle<FixedArray> elements = Factory::NewFixedArray(args.length()); | 823 Factory* factory = isolate()->factory(); |
| 824 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); |
817 for (int i = 0; i < args.length(); i++) { | 825 for (int i = 0; i < args.length(); i++) { |
818 elements->set(i, *args[i]); | 826 elements->set(i, *args[i]); |
819 } | 827 } |
820 Handle<JSArray> array = Factory::NewJSArrayWithElements(elements); | 828 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
821 Handle<Object> result = Factory::NewSyntaxError(type, array); | 829 Handle<Object> result = factory->NewSyntaxError(type, array); |
822 Top::Throw(*result, &location); | 830 isolate()->Throw(*result, &location); |
823 } | 831 } |
824 | 832 |
825 | 833 |
826 // Base class containing common code for the different finder classes used by | 834 // Base class containing common code for the different finder classes used by |
827 // the parser. | 835 // the parser. |
828 class ParserFinder { | 836 class ParserFinder { |
829 protected: | 837 protected: |
830 ParserFinder() {} | 838 ParserFinder() {} |
831 static Assignment* AsAssignment(Statement* stat) { | 839 static Assignment* AsAssignment(Statement* stat) { |
832 if (stat == NULL) return NULL; | 840 if (stat == NULL) return NULL; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 // Returns whether only statements of the form this.x = y; where y is either a | 977 // Returns whether only statements of the form this.x = y; where y is either a |
970 // constant or a function argument was encountered. | 978 // constant or a function argument was encountered. |
971 bool only_simple_this_property_assignments() { | 979 bool only_simple_this_property_assignments() { |
972 return only_simple_this_property_assignments_; | 980 return only_simple_this_property_assignments_; |
973 } | 981 } |
974 | 982 |
975 // Returns a fixed array containing three elements for each assignment of the | 983 // Returns a fixed array containing three elements for each assignment of the |
976 // form this.x = y; | 984 // form this.x = y; |
977 Handle<FixedArray> GetThisPropertyAssignments() { | 985 Handle<FixedArray> GetThisPropertyAssignments() { |
978 if (names_ == NULL) { | 986 if (names_ == NULL) { |
979 return Factory::empty_fixed_array(); | 987 return FACTORY->empty_fixed_array(); |
980 } | 988 } |
981 ASSERT(names_ != NULL); | 989 ASSERT(names_ != NULL); |
982 ASSERT(assigned_arguments_ != NULL); | 990 ASSERT(assigned_arguments_ != NULL); |
983 ASSERT_EQ(names_->length(), assigned_arguments_->length()); | 991 ASSERT_EQ(names_->length(), assigned_arguments_->length()); |
984 ASSERT_EQ(names_->length(), assigned_constants_->length()); | 992 ASSERT_EQ(names_->length(), assigned_constants_->length()); |
985 Handle<FixedArray> assignments = | 993 Handle<FixedArray> assignments = |
986 Factory::NewFixedArray(names_->length() * 3); | 994 FACTORY->NewFixedArray(names_->length() * 3); |
987 for (int i = 0; i < names_->length(); i++) { | 995 for (int i = 0; i < names_->length(); i++) { |
988 assignments->set(i * 3, *names_->at(i)); | 996 assignments->set(i * 3, *names_->at(i)); |
989 assignments->set(i * 3 + 1, Smi::FromInt(assigned_arguments_->at(i))); | 997 assignments->set(i * 3 + 1, Smi::FromInt(assigned_arguments_->at(i))); |
990 assignments->set(i * 3 + 2, *assigned_constants_->at(i)); | 998 assignments->set(i * 3 + 2, *assigned_constants_->at(i)); |
991 } | 999 } |
992 return assignments; | 1000 return assignments; |
993 } | 1001 } |
994 | 1002 |
995 private: | 1003 private: |
996 bool IsThisPropertyAssignment(Assignment* assignment) { | 1004 bool IsThisPropertyAssignment(Assignment* assignment) { |
997 if (assignment != NULL) { | 1005 if (assignment != NULL) { |
998 Property* property = assignment->target()->AsProperty(); | 1006 Property* property = assignment->target()->AsProperty(); |
999 return assignment->op() == Token::ASSIGN | 1007 return assignment->op() == Token::ASSIGN |
1000 && property != NULL | 1008 && property != NULL |
1001 && property->obj()->AsVariableProxy() != NULL | 1009 && property->obj()->AsVariableProxy() != NULL |
1002 && property->obj()->AsVariableProxy()->is_this(); | 1010 && property->obj()->AsVariableProxy()->is_this(); |
1003 } | 1011 } |
1004 return false; | 1012 return false; |
1005 } | 1013 } |
1006 | 1014 |
1007 void HandleThisPropertyAssignment(Scope* scope, Assignment* assignment) { | 1015 void HandleThisPropertyAssignment(Scope* scope, Assignment* assignment) { |
1008 // Check that the property assigned to is a named property, which is not | 1016 // Check that the property assigned to is a named property, which is not |
1009 // __proto__. | 1017 // __proto__. |
1010 Property* property = assignment->target()->AsProperty(); | 1018 Property* property = assignment->target()->AsProperty(); |
1011 ASSERT(property != NULL); | 1019 ASSERT(property != NULL); |
1012 Literal* literal = property->key()->AsLiteral(); | 1020 Literal* literal = property->key()->AsLiteral(); |
1013 uint32_t dummy; | 1021 uint32_t dummy; |
1014 if (literal != NULL && | 1022 if (literal != NULL && |
1015 literal->handle()->IsString() && | 1023 literal->handle()->IsString() && |
1016 !String::cast(*(literal->handle()))->Equals(Heap::Proto_symbol()) && | 1024 !String::cast(*(literal->handle()))->Equals(HEAP->Proto_symbol()) && |
1017 !String::cast(*(literal->handle()))->AsArrayIndex(&dummy)) { | 1025 !String::cast(*(literal->handle()))->AsArrayIndex(&dummy)) { |
1018 Handle<String> key = Handle<String>::cast(literal->handle()); | 1026 Handle<String> key = Handle<String>::cast(literal->handle()); |
1019 | 1027 |
1020 // Check whether the value assigned is either a constant or matches the | 1028 // Check whether the value assigned is either a constant or matches the |
1021 // name of one of the arguments to the function. | 1029 // name of one of the arguments to the function. |
1022 if (assignment->value()->AsLiteral() != NULL) { | 1030 if (assignment->value()->AsLiteral() != NULL) { |
1023 // Constant assigned. | 1031 // Constant assigned. |
1024 Literal* literal = assignment->value()->AsLiteral(); | 1032 Literal* literal = assignment->value()->AsLiteral(); |
1025 AssignmentFromConstant(key, literal->handle()); | 1033 AssignmentFromConstant(key, literal->handle()); |
1026 return; | 1034 return; |
(...skipping 13 matching lines...) Expand all Loading... |
1040 } | 1048 } |
1041 // It is not a simple "this.x = value;" assignment with a constant | 1049 // It is not a simple "this.x = value;" assignment with a constant |
1042 // or parameter value. | 1050 // or parameter value. |
1043 AssignmentFromSomethingElse(); | 1051 AssignmentFromSomethingElse(); |
1044 } | 1052 } |
1045 | 1053 |
1046 void AssignmentFromParameter(Handle<String> name, int index) { | 1054 void AssignmentFromParameter(Handle<String> name, int index) { |
1047 EnsureAllocation(); | 1055 EnsureAllocation(); |
1048 names_->Add(name); | 1056 names_->Add(name); |
1049 assigned_arguments_->Add(index); | 1057 assigned_arguments_->Add(index); |
1050 assigned_constants_->Add(Factory::undefined_value()); | 1058 assigned_constants_->Add(FACTORY->undefined_value()); |
1051 } | 1059 } |
1052 | 1060 |
1053 void AssignmentFromConstant(Handle<String> name, Handle<Object> value) { | 1061 void AssignmentFromConstant(Handle<String> name, Handle<Object> value) { |
1054 EnsureAllocation(); | 1062 EnsureAllocation(); |
1055 names_->Add(name); | 1063 names_->Add(name); |
1056 assigned_arguments_->Add(-1); | 1064 assigned_arguments_->Add(-1); |
1057 assigned_constants_->Add(value); | 1065 assigned_constants_->Add(value); |
1058 } | 1066 } |
1059 | 1067 |
1060 void AssignmentFromSomethingElse() { | 1068 void AssignmentFromSomethingElse() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 ExpressionStatement *e_stat; | 1135 ExpressionStatement *e_stat; |
1128 Literal *literal; | 1136 Literal *literal; |
1129 // Still processing directive prologue? | 1137 // Still processing directive prologue? |
1130 if ((e_stat = stat->AsExpressionStatement()) != NULL && | 1138 if ((e_stat = stat->AsExpressionStatement()) != NULL && |
1131 (literal = e_stat->expression()->AsLiteral()) != NULL && | 1139 (literal = e_stat->expression()->AsLiteral()) != NULL && |
1132 literal->handle()->IsString()) { | 1140 literal->handle()->IsString()) { |
1133 Handle<String> directive = Handle<String>::cast(literal->handle()); | 1141 Handle<String> directive = Handle<String>::cast(literal->handle()); |
1134 | 1142 |
1135 // Check "use strict" directive (ES5 14.1). | 1143 // Check "use strict" directive (ES5 14.1). |
1136 if (!top_scope_->is_strict_mode() && | 1144 if (!top_scope_->is_strict_mode() && |
1137 directive->Equals(Heap::use_strict()) && | 1145 directive->Equals(isolate()->heap()->use_strict()) && |
1138 token_loc.end_pos - token_loc.beg_pos == | 1146 token_loc.end_pos - token_loc.beg_pos == |
1139 Heap::use_strict()->length() + 2) { | 1147 isolate()->heap()->use_strict()->length() + 2) { |
1140 top_scope_->EnableStrictMode(); | 1148 top_scope_->EnableStrictMode(); |
1141 // "use strict" is the only directive for now. | 1149 // "use strict" is the only directive for now. |
1142 directive_prologue = false; | 1150 directive_prologue = false; |
1143 } | 1151 } |
1144 } else { | 1152 } else { |
1145 // End of the directive prologue. | 1153 // End of the directive prologue. |
1146 directive_prologue = false; | 1154 directive_prologue = false; |
1147 } | 1155 } |
1148 } | 1156 } |
1149 | 1157 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 // The name was declared before; check for conflicting | 1335 // The name was declared before; check for conflicting |
1328 // re-declarations. If the previous declaration was a const or the | 1336 // re-declarations. If the previous declaration was a const or the |
1329 // current declaration is a const then we have a conflict. There is | 1337 // current declaration is a const then we have a conflict. There is |
1330 // similar code in runtime.cc in the Declare functions. | 1338 // similar code in runtime.cc in the Declare functions. |
1331 if ((mode == Variable::CONST) || (var->mode() == Variable::CONST)) { | 1339 if ((mode == Variable::CONST) || (var->mode() == Variable::CONST)) { |
1332 // We only have vars and consts in declarations. | 1340 // We only have vars and consts in declarations. |
1333 ASSERT(var->mode() == Variable::VAR || | 1341 ASSERT(var->mode() == Variable::VAR || |
1334 var->mode() == Variable::CONST); | 1342 var->mode() == Variable::CONST); |
1335 const char* type = (var->mode() == Variable::VAR) ? "var" : "const"; | 1343 const char* type = (var->mode() == Variable::VAR) ? "var" : "const"; |
1336 Handle<String> type_string = | 1344 Handle<String> type_string = |
1337 Factory::NewStringFromUtf8(CStrVector(type), TENURED); | 1345 isolate()->factory()->NewStringFromUtf8(CStrVector(type), TENURED); |
1338 Expression* expression = | 1346 Expression* expression = |
1339 NewThrowTypeError(Factory::redeclaration_symbol(), | 1347 NewThrowTypeError(isolate()->factory()->redeclaration_symbol(), |
1340 type_string, name); | 1348 type_string, name); |
1341 top_scope_->SetIllegalRedeclaration(expression); | 1349 top_scope_->SetIllegalRedeclaration(expression); |
1342 } | 1350 } |
1343 } | 1351 } |
1344 } | 1352 } |
1345 | 1353 |
1346 // We add a declaration node for every declaration. The compiler | 1354 // We add a declaration node for every declaration. The compiler |
1347 // will only generate code if necessary. In particular, declarations | 1355 // will only generate code if necessary. In particular, declarations |
1348 // for inner local variables that do not represent functions won't | 1356 // for inner local variables that do not represent functions won't |
1349 // result in any generated code. | 1357 // result in any generated code. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 v8::Handle<v8::FunctionTemplate> fun_template = | 1443 v8::Handle<v8::FunctionTemplate> fun_template = |
1436 extension_->GetNativeFunction(v8::Utils::ToLocal(name)); | 1444 extension_->GetNativeFunction(v8::Utils::ToLocal(name)); |
1437 ASSERT(!fun_template.IsEmpty()); | 1445 ASSERT(!fun_template.IsEmpty()); |
1438 | 1446 |
1439 // Instantiate the function and create a shared function info from it. | 1447 // Instantiate the function and create a shared function info from it. |
1440 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction()); | 1448 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction()); |
1441 const int literals = fun->NumberOfLiterals(); | 1449 const int literals = fun->NumberOfLiterals(); |
1442 Handle<Code> code = Handle<Code>(fun->shared()->code()); | 1450 Handle<Code> code = Handle<Code>(fun->shared()->code()); |
1443 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); | 1451 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); |
1444 Handle<SharedFunctionInfo> shared = | 1452 Handle<SharedFunctionInfo> shared = |
1445 Factory::NewSharedFunctionInfo(name, literals, code, | 1453 isolate()->factory()->NewSharedFunctionInfo(name, literals, code, |
1446 Handle<SerializedScopeInfo>(fun->shared()->scope_info())); | 1454 Handle<SerializedScopeInfo>(fun->shared()->scope_info())); |
1447 shared->set_construct_stub(*construct_stub); | 1455 shared->set_construct_stub(*construct_stub); |
1448 | 1456 |
1449 // Copy the function data to the shared function info. | 1457 // Copy the function data to the shared function info. |
1450 shared->set_function_data(fun->shared()->function_data()); | 1458 shared->set_function_data(fun->shared()->function_data()); |
1451 int parameters = fun->shared()->formal_parameter_count(); | 1459 int parameters = fun->shared()->formal_parameter_count(); |
1452 shared->set_formal_parameter_count(parameters); | 1460 shared->set_formal_parameter_count(parameters); |
1453 | 1461 |
1454 // TODO(1240846): It's weird that native function declarations are | 1462 // TODO(1240846): It's weird that native function declarations are |
1455 // introduced dynamically when we meet their declarations, whereas | 1463 // introduced dynamically when we meet their declarations, whereas |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 // VariableStatement :: | 1513 // VariableStatement :: |
1506 // VariableDeclarations ';' | 1514 // VariableDeclarations ';' |
1507 | 1515 |
1508 Expression* dummy; // to satisfy the ParseVariableDeclarations() signature | 1516 Expression* dummy; // to satisfy the ParseVariableDeclarations() signature |
1509 Block* result = ParseVariableDeclarations(true, &dummy, CHECK_OK); | 1517 Block* result = ParseVariableDeclarations(true, &dummy, CHECK_OK); |
1510 ExpectSemicolon(CHECK_OK); | 1518 ExpectSemicolon(CHECK_OK); |
1511 return result; | 1519 return result; |
1512 } | 1520 } |
1513 | 1521 |
1514 static bool IsEvalOrArguments(Handle<String> string) { | 1522 static bool IsEvalOrArguments(Handle<String> string) { |
1515 return string.is_identical_to(Factory::eval_symbol()) || | 1523 return string.is_identical_to(FACTORY->eval_symbol()) || |
1516 string.is_identical_to(Factory::arguments_symbol()); | 1524 string.is_identical_to(FACTORY->arguments_symbol()); |
1517 } | 1525 } |
1518 | 1526 |
1519 // If the variable declaration declares exactly one non-const | 1527 // If the variable declaration declares exactly one non-const |
1520 // variable, then *var is set to that variable. In all other cases, | 1528 // variable, then *var is set to that variable. In all other cases, |
1521 // *var is untouched; in particular, it is the caller's responsibility | 1529 // *var is untouched; in particular, it is the caller's responsibility |
1522 // to initialize it properly. This mechanism is used for the parsing | 1530 // to initialize it properly. This mechanism is used for the parsing |
1523 // of 'for-in' loops. | 1531 // of 'for-in' loops. |
1524 Block* Parser::ParseVariableDeclarations(bool accept_IN, | 1532 Block* Parser::ParseVariableDeclarations(bool accept_IN, |
1525 Expression** var, | 1533 Expression** var, |
1526 bool* ok) { | 1534 bool* ok) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 if (is_const) { | 1672 if (is_const) { |
1665 arguments->Add(value); | 1673 arguments->Add(value); |
1666 value = NULL; // zap the value to avoid the unnecessary assignment | 1674 value = NULL; // zap the value to avoid the unnecessary assignment |
1667 | 1675 |
1668 // Construct the call to Runtime_InitializeConstGlobal | 1676 // Construct the call to Runtime_InitializeConstGlobal |
1669 // and add it to the initialization statement block. | 1677 // and add it to the initialization statement block. |
1670 // Note that the function does different things depending on | 1678 // Note that the function does different things depending on |
1671 // the number of arguments (1 or 2). | 1679 // the number of arguments (1 or 2). |
1672 initialize = | 1680 initialize = |
1673 new CallRuntime( | 1681 new CallRuntime( |
1674 Factory::InitializeConstGlobal_symbol(), | 1682 isolate()->factory()->InitializeConstGlobal_symbol(), |
1675 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), | 1683 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), |
1676 arguments); | 1684 arguments); |
1677 } else { | 1685 } else { |
1678 // Add strict mode. | 1686 // Add strict mode. |
1679 // We may want to pass singleton to avoid Literal allocations. | 1687 // We may want to pass singleton to avoid Literal allocations. |
1680 arguments->Add(NewNumberLiteral( | 1688 arguments->Add(NewNumberLiteral( |
1681 top_scope_->is_strict_mode() ? kStrictMode : kNonStrictMode)); | 1689 top_scope_->is_strict_mode() ? kStrictMode : kNonStrictMode)); |
1682 | 1690 |
1683 // Be careful not to assign a value to the global variable if | 1691 // Be careful not to assign a value to the global variable if |
1684 // we're in a with. The initialization value should not | 1692 // we're in a with. The initialization value should not |
1685 // necessarily be stored in the global object in that case, | 1693 // necessarily be stored in the global object in that case, |
1686 // which is why we need to generate a separate assignment node. | 1694 // which is why we need to generate a separate assignment node. |
1687 if (value != NULL && !inside_with()) { | 1695 if (value != NULL && !inside_with()) { |
1688 arguments->Add(value); | 1696 arguments->Add(value); |
1689 value = NULL; // zap the value to avoid the unnecessary assignment | 1697 value = NULL; // zap the value to avoid the unnecessary assignment |
1690 } | 1698 } |
1691 | 1699 |
1692 // Construct the call to Runtime_InitializeVarGlobal | 1700 // Construct the call to Runtime_InitializeVarGlobal |
1693 // and add it to the initialization statement block. | 1701 // and add it to the initialization statement block. |
1694 // Note that the function does different things depending on | 1702 // Note that the function does different things depending on |
1695 // the number of arguments (2 or 3). | 1703 // the number of arguments (2 or 3). |
1696 initialize = | 1704 initialize = |
1697 new CallRuntime( | 1705 new CallRuntime( |
1698 Factory::InitializeVarGlobal_symbol(), | 1706 isolate()->factory()->InitializeVarGlobal_symbol(), |
1699 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), | 1707 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), |
1700 arguments); | 1708 arguments); |
1701 } | 1709 } |
1702 | 1710 |
1703 block->AddStatement(new ExpressionStatement(initialize)); | 1711 block->AddStatement(new ExpressionStatement(initialize)); |
1704 } | 1712 } |
1705 | 1713 |
1706 // Add an assignment node to the initialization statement block if | 1714 // Add an assignment node to the initialization statement block if |
1707 // we still have a pending initialization value. We must distinguish | 1715 // we still have a pending initialization value. We must distinguish |
1708 // between variables and constants: Variable initializations are simply | 1716 // between variables and constants: Variable initializations are simply |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 // reporting any errors on it, because of the way errors are | 1887 // reporting any errors on it, because of the way errors are |
1880 // reported (underlining). | 1888 // reported (underlining). |
1881 Expect(Token::RETURN, CHECK_OK); | 1889 Expect(Token::RETURN, CHECK_OK); |
1882 | 1890 |
1883 // An ECMAScript program is considered syntactically incorrect if it | 1891 // An ECMAScript program is considered syntactically incorrect if it |
1884 // contains a return statement that is not within the body of a | 1892 // contains a return statement that is not within the body of a |
1885 // function. See ECMA-262, section 12.9, page 67. | 1893 // function. See ECMA-262, section 12.9, page 67. |
1886 // | 1894 // |
1887 // To be consistent with KJS we report the syntax error at runtime. | 1895 // To be consistent with KJS we report the syntax error at runtime. |
1888 if (!top_scope_->is_function_scope()) { | 1896 if (!top_scope_->is_function_scope()) { |
1889 Handle<String> type = Factory::illegal_return_symbol(); | 1897 Handle<String> type = isolate()->factory()->illegal_return_symbol(); |
1890 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); | 1898 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); |
1891 return new ExpressionStatement(throw_error); | 1899 return new ExpressionStatement(throw_error); |
1892 } | 1900 } |
1893 | 1901 |
1894 Token::Value tok = peek(); | 1902 Token::Value tok = peek(); |
1895 if (scanner().has_line_terminator_before_next() || | 1903 if (scanner().has_line_terminator_before_next() || |
1896 tok == Token::SEMICOLON || | 1904 tok == Token::SEMICOLON || |
1897 tok == Token::RBRACE || | 1905 tok == Token::RBRACE || |
1898 tok == Token::EOS) { | 1906 tok == Token::EOS) { |
1899 ExpectSemicolon(CHECK_OK); | 1907 ExpectSemicolon(CHECK_OK); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2094 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); | 2102 ReportMessage("strict_catch_variable", Vector<const char*>::empty()); |
2095 *ok = false; | 2103 *ok = false; |
2096 return NULL; | 2104 return NULL; |
2097 } | 2105 } |
2098 | 2106 |
2099 Expect(Token::RPAREN, CHECK_OK); | 2107 Expect(Token::RPAREN, CHECK_OK); |
2100 | 2108 |
2101 if (peek() == Token::LBRACE) { | 2109 if (peek() == Token::LBRACE) { |
2102 // Allocate a temporary for holding the finally state while | 2110 // Allocate a temporary for holding the finally state while |
2103 // executing the finally block. | 2111 // executing the finally block. |
2104 catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol()); | 2112 catch_var = |
| 2113 top_scope_->NewTemporary(isolate()->factory()->catch_var_symbol()); |
2105 Literal* name_literal = new Literal(name); | 2114 Literal* name_literal = new Literal(name); |
2106 VariableProxy* catch_var_use = new VariableProxy(catch_var); | 2115 VariableProxy* catch_var_use = new VariableProxy(catch_var); |
2107 Expression* obj = new CatchExtensionObject(name_literal, catch_var_use); | 2116 Expression* obj = new CatchExtensionObject(name_literal, catch_var_use); |
2108 { Target target(&this->target_stack_, &catch_collector); | 2117 { Target target(&this->target_stack_, &catch_collector); |
2109 catch_block = WithHelper(obj, NULL, true, CHECK_OK); | 2118 catch_block = WithHelper(obj, NULL, true, CHECK_OK); |
2110 } | 2119 } |
2111 } else { | 2120 } else { |
2112 Expect(Token::LBRACE, CHECK_OK); | 2121 Expect(Token::LBRACE, CHECK_OK); |
2113 } | 2122 } |
2114 | 2123 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 } | 2254 } |
2246 | 2255 |
2247 } else { | 2256 } else { |
2248 Expression* expression = ParseExpression(false, CHECK_OK); | 2257 Expression* expression = ParseExpression(false, CHECK_OK); |
2249 if (peek() == Token::IN) { | 2258 if (peek() == Token::IN) { |
2250 // Signal a reference error if the expression is an invalid | 2259 // Signal a reference error if the expression is an invalid |
2251 // left-hand side expression. We could report this as a syntax | 2260 // left-hand side expression. We could report this as a syntax |
2252 // error here but for compatibility with JSC we choose to report | 2261 // error here but for compatibility with JSC we choose to report |
2253 // the error at runtime. | 2262 // the error at runtime. |
2254 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2263 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2255 Handle<String> type = Factory::invalid_lhs_in_for_in_symbol(); | 2264 Handle<String> type = |
| 2265 isolate()->factory()->invalid_lhs_in_for_in_symbol(); |
2256 expression = NewThrowReferenceError(type); | 2266 expression = NewThrowReferenceError(type); |
2257 } | 2267 } |
2258 ForInStatement* loop = new ForInStatement(labels); | 2268 ForInStatement* loop = new ForInStatement(labels); |
2259 Target target(&this->target_stack_, loop); | 2269 Target target(&this->target_stack_, loop); |
2260 | 2270 |
2261 Expect(Token::IN, CHECK_OK); | 2271 Expect(Token::IN, CHECK_OK); |
2262 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2272 Expression* enumerable = ParseExpression(true, CHECK_OK); |
2263 Expect(Token::RPAREN, CHECK_OK); | 2273 Expect(Token::RPAREN, CHECK_OK); |
2264 | 2274 |
2265 Statement* body = ParseStatement(NULL, CHECK_OK); | 2275 Statement* body = ParseStatement(NULL, CHECK_OK); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2330 if (fni_ != NULL) fni_->Leave(); | 2340 if (fni_ != NULL) fni_->Leave(); |
2331 // Parsed conditional expression only (no assignment). | 2341 // Parsed conditional expression only (no assignment). |
2332 return expression; | 2342 return expression; |
2333 } | 2343 } |
2334 | 2344 |
2335 // Signal a reference error if the expression is an invalid left-hand | 2345 // Signal a reference error if the expression is an invalid left-hand |
2336 // side expression. We could report this as a syntax error here but | 2346 // side expression. We could report this as a syntax error here but |
2337 // for compatibility with JSC we choose to report the error at | 2347 // for compatibility with JSC we choose to report the error at |
2338 // runtime. | 2348 // runtime. |
2339 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2349 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2340 Handle<String> type = Factory::invalid_lhs_in_assignment_symbol(); | 2350 Handle<String> type = |
| 2351 isolate()->factory()->invalid_lhs_in_assignment_symbol(); |
2341 expression = NewThrowReferenceError(type); | 2352 expression = NewThrowReferenceError(type); |
2342 } | 2353 } |
2343 | 2354 |
2344 if (top_scope_->is_strict_mode()) { | 2355 if (top_scope_->is_strict_mode()) { |
2345 // Assignment to eval or arguments is disallowed in strict mode. | 2356 // Assignment to eval or arguments is disallowed in strict mode. |
2346 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK); | 2357 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK); |
2347 } | 2358 } |
2348 | 2359 |
2349 Token::Value op = Next(); // Get assignment operator. | 2360 Token::Value op = Next(); // Get assignment operator. |
2350 int pos = scanner().location().beg_pos; | 2361 int pos = scanner().location().beg_pos; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2572 return new UnaryOperation(op, expression); | 2583 return new UnaryOperation(op, expression); |
2573 | 2584 |
2574 } else if (Token::IsCountOp(op)) { | 2585 } else if (Token::IsCountOp(op)) { |
2575 op = Next(); | 2586 op = Next(); |
2576 Expression* expression = ParseUnaryExpression(CHECK_OK); | 2587 Expression* expression = ParseUnaryExpression(CHECK_OK); |
2577 // Signal a reference error if the expression is an invalid | 2588 // Signal a reference error if the expression is an invalid |
2578 // left-hand side expression. We could report this as a syntax | 2589 // left-hand side expression. We could report this as a syntax |
2579 // error here but for compatibility with JSC we choose to report the | 2590 // error here but for compatibility with JSC we choose to report the |
2580 // error at runtime. | 2591 // error at runtime. |
2581 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2592 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2582 Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol(); | 2593 Handle<String> type = |
| 2594 isolate()->factory()->invalid_lhs_in_prefix_op_symbol(); |
2583 expression = NewThrowReferenceError(type); | 2595 expression = NewThrowReferenceError(type); |
2584 } | 2596 } |
2585 | 2597 |
2586 if (top_scope_->is_strict_mode()) { | 2598 if (top_scope_->is_strict_mode()) { |
2587 // Prefix expression operand in strict mode may not be eval or arguments. | 2599 // Prefix expression operand in strict mode may not be eval or arguments. |
2588 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); | 2600 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); |
2589 } | 2601 } |
2590 | 2602 |
2591 int position = scanner().location().beg_pos; | 2603 int position = scanner().location().beg_pos; |
2592 IncrementOperation* increment = new IncrementOperation(op, expression); | 2604 IncrementOperation* increment = new IncrementOperation(op, expression); |
(...skipping 10 matching lines...) Expand all Loading... |
2603 // LeftHandSideExpression ('++' | '--')? | 2615 // LeftHandSideExpression ('++' | '--')? |
2604 | 2616 |
2605 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); | 2617 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); |
2606 if (!scanner().has_line_terminator_before_next() && | 2618 if (!scanner().has_line_terminator_before_next() && |
2607 Token::IsCountOp(peek())) { | 2619 Token::IsCountOp(peek())) { |
2608 // Signal a reference error if the expression is an invalid | 2620 // Signal a reference error if the expression is an invalid |
2609 // left-hand side expression. We could report this as a syntax | 2621 // left-hand side expression. We could report this as a syntax |
2610 // error here but for compatibility with JSC we choose to report the | 2622 // error here but for compatibility with JSC we choose to report the |
2611 // error at runtime. | 2623 // error at runtime. |
2612 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2624 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2613 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol(); | 2625 Handle<String> type = |
| 2626 isolate()->factory()->invalid_lhs_in_postfix_op_symbol(); |
2614 expression = NewThrowReferenceError(type); | 2627 expression = NewThrowReferenceError(type); |
2615 } | 2628 } |
2616 | 2629 |
2617 if (top_scope_->is_strict_mode()) { | 2630 if (top_scope_->is_strict_mode()) { |
2618 // Postfix expression operand in strict mode may not be eval or arguments. | 2631 // Postfix expression operand in strict mode may not be eval or arguments. |
2619 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); | 2632 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); |
2620 } | 2633 } |
2621 | 2634 |
2622 Token::Value next = Next(); | 2635 Token::Value next = Next(); |
2623 int position = scanner().location().beg_pos; | 2636 int position = scanner().location().beg_pos; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2660 // direct (i.e. not aliased) eval calls. These calls are all of the | 2673 // direct (i.e. not aliased) eval calls. These calls are all of the |
2661 // form eval(...) with no explicit receiver object where eval is not | 2674 // form eval(...) with no explicit receiver object where eval is not |
2662 // declared in the current scope chain. | 2675 // declared in the current scope chain. |
2663 // These calls are marked as potentially direct eval calls. Whether | 2676 // These calls are marked as potentially direct eval calls. Whether |
2664 // they are actually direct calls to eval is determined at run time. | 2677 // they are actually direct calls to eval is determined at run time. |
2665 // TODO(994): In ES5, it doesn't matter if the "eval" var is declared | 2678 // TODO(994): In ES5, it doesn't matter if the "eval" var is declared |
2666 // in the local scope chain. It only matters that it's called "eval", | 2679 // in the local scope chain. It only matters that it's called "eval", |
2667 // is called without a receiver and it refers to the original eval | 2680 // is called without a receiver and it refers to the original eval |
2668 // function. | 2681 // function. |
2669 VariableProxy* callee = result->AsVariableProxy(); | 2682 VariableProxy* callee = result->AsVariableProxy(); |
2670 if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) { | 2683 if (callee != NULL && |
| 2684 callee->IsVariable(isolate()->factory()->eval_symbol())) { |
2671 Handle<String> name = callee->name(); | 2685 Handle<String> name = callee->name(); |
2672 Variable* var = top_scope_->Lookup(name); | 2686 Variable* var = top_scope_->Lookup(name); |
2673 if (var == NULL) { | 2687 if (var == NULL) { |
2674 top_scope_->RecordEvalCall(); | 2688 top_scope_->RecordEvalCall(); |
2675 } | 2689 } |
2676 } | 2690 } |
2677 result = NewCall(result, args, pos); | 2691 result = NewCall(result, args, pos); |
2678 break; | 2692 break; |
2679 } | 2693 } |
2680 | 2694 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2861 switch (peek()) { | 2875 switch (peek()) { |
2862 case Token::THIS: { | 2876 case Token::THIS: { |
2863 Consume(Token::THIS); | 2877 Consume(Token::THIS); |
2864 VariableProxy* recv = top_scope_->receiver(); | 2878 VariableProxy* recv = top_scope_->receiver(); |
2865 result = recv; | 2879 result = recv; |
2866 break; | 2880 break; |
2867 } | 2881 } |
2868 | 2882 |
2869 case Token::NULL_LITERAL: | 2883 case Token::NULL_LITERAL: |
2870 Consume(Token::NULL_LITERAL); | 2884 Consume(Token::NULL_LITERAL); |
2871 result = new Literal(Factory::null_value()); | 2885 result = new Literal(isolate()->factory()->null_value()); |
2872 break; | 2886 break; |
2873 | 2887 |
2874 case Token::TRUE_LITERAL: | 2888 case Token::TRUE_LITERAL: |
2875 Consume(Token::TRUE_LITERAL); | 2889 Consume(Token::TRUE_LITERAL); |
2876 result = new Literal(Factory::true_value()); | 2890 result = new Literal(isolate()->factory()->true_value()); |
2877 break; | 2891 break; |
2878 | 2892 |
2879 case Token::FALSE_LITERAL: | 2893 case Token::FALSE_LITERAL: |
2880 Consume(Token::FALSE_LITERAL); | 2894 Consume(Token::FALSE_LITERAL); |
2881 result = new Literal(Factory::false_value()); | 2895 result = new Literal(isolate()->factory()->false_value()); |
2882 break; | 2896 break; |
2883 | 2897 |
2884 case Token::IDENTIFIER: | 2898 case Token::IDENTIFIER: |
2885 case Token::FUTURE_RESERVED_WORD: { | 2899 case Token::FUTURE_RESERVED_WORD: { |
2886 Handle<String> name = ParseIdentifier(CHECK_OK); | 2900 Handle<String> name = ParseIdentifier(CHECK_OK); |
2887 if (fni_ != NULL) fni_->PushVariableName(name); | 2901 if (fni_ != NULL) fni_->PushVariableName(name); |
2888 result = top_scope_->NewUnresolved(name, inside_with()); | 2902 result = top_scope_->NewUnresolved(name, inside_with()); |
2889 break; | 2903 break; |
2890 } | 2904 } |
2891 | 2905 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2996 Expect(Token::COMMA, CHECK_OK); | 3010 Expect(Token::COMMA, CHECK_OK); |
2997 } | 3011 } |
2998 } | 3012 } |
2999 Expect(Token::RBRACK, CHECK_OK); | 3013 Expect(Token::RBRACK, CHECK_OK); |
3000 | 3014 |
3001 // Update the scope information before the pre-parsing bailout. | 3015 // Update the scope information before the pre-parsing bailout. |
3002 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); | 3016 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); |
3003 | 3017 |
3004 // Allocate a fixed array with all the literals. | 3018 // Allocate a fixed array with all the literals. |
3005 Handle<FixedArray> literals = | 3019 Handle<FixedArray> literals = |
3006 Factory::NewFixedArray(values->length(), TENURED); | 3020 isolate()->factory()->NewFixedArray(values->length(), TENURED); |
3007 | 3021 |
3008 // Fill in the literals. | 3022 // Fill in the literals. |
3009 bool is_simple = true; | 3023 bool is_simple = true; |
3010 int depth = 1; | 3024 int depth = 1; |
3011 for (int i = 0, n = values->length(); i < n; i++) { | 3025 for (int i = 0, n = values->length(); i < n; i++) { |
3012 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); | 3026 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); |
3013 if (m_literal != NULL && m_literal->depth() + 1 > depth) { | 3027 if (m_literal != NULL && m_literal->depth() + 1 > depth) { |
3014 depth = m_literal->depth() + 1; | 3028 depth = m_literal->depth() + 1; |
3015 } | 3029 } |
3016 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); | 3030 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); |
3017 if (boilerplate_value->IsUndefined()) { | 3031 if (boilerplate_value->IsUndefined()) { |
3018 literals->set_the_hole(i); | 3032 literals->set_the_hole(i); |
3019 is_simple = false; | 3033 is_simple = false; |
3020 } else { | 3034 } else { |
3021 literals->set(i, *boilerplate_value); | 3035 literals->set(i, *boilerplate_value); |
3022 } | 3036 } |
3023 } | 3037 } |
3024 | 3038 |
3025 // Simple and shallow arrays can be lazily copied, we transform the | 3039 // Simple and shallow arrays can be lazily copied, we transform the |
3026 // elements array to a copy-on-write array. | 3040 // elements array to a copy-on-write array. |
3027 if (is_simple && depth == 1 && values->length() > 0) { | 3041 if (is_simple && depth == 1 && values->length() > 0) { |
3028 literals->set_map(Heap::fixed_cow_array_map()); | 3042 literals->set_map(isolate()->heap()->fixed_cow_array_map()); |
3029 } | 3043 } |
3030 | 3044 |
3031 return new ArrayLiteral(literals, values, | 3045 return new ArrayLiteral(literals, values, |
3032 literal_index, is_simple, depth); | 3046 literal_index, is_simple, depth); |
3033 } | 3047 } |
3034 | 3048 |
3035 | 3049 |
3036 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 3050 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
3037 return property != NULL && | 3051 return property != NULL && |
3038 property->kind() != ObjectLiteral::Property::PROTOTYPE; | 3052 property->kind() != ObjectLiteral::Property::PROTOTYPE; |
(...skipping 14 matching lines...) Expand all Loading... |
3053 if (value->AsLiteral() != NULL) return false; | 3067 if (value->AsLiteral() != NULL) return false; |
3054 // If value is a materialized literal the property value is already set | 3068 // If value is a materialized literal the property value is already set |
3055 // in the boilerplate object if it is simple. | 3069 // in the boilerplate object if it is simple. |
3056 if (CompileTimeValue::IsCompileTimeValue(value)) return false; | 3070 if (CompileTimeValue::IsCompileTimeValue(value)) return false; |
3057 return true; | 3071 return true; |
3058 } | 3072 } |
3059 | 3073 |
3060 | 3074 |
3061 Handle<FixedArray> CompileTimeValue::GetValue(Expression* expression) { | 3075 Handle<FixedArray> CompileTimeValue::GetValue(Expression* expression) { |
3062 ASSERT(IsCompileTimeValue(expression)); | 3076 ASSERT(IsCompileTimeValue(expression)); |
3063 Handle<FixedArray> result = Factory::NewFixedArray(2, TENURED); | 3077 Handle<FixedArray> result = FACTORY->NewFixedArray(2, TENURED); |
3064 ObjectLiteral* object_literal = expression->AsObjectLiteral(); | 3078 ObjectLiteral* object_literal = expression->AsObjectLiteral(); |
3065 if (object_literal != NULL) { | 3079 if (object_literal != NULL) { |
3066 ASSERT(object_literal->is_simple()); | 3080 ASSERT(object_literal->is_simple()); |
3067 if (object_literal->fast_elements()) { | 3081 if (object_literal->fast_elements()) { |
3068 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS)); | 3082 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS)); |
3069 } else { | 3083 } else { |
3070 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS)); | 3084 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS)); |
3071 } | 3085 } |
3072 result->set(kElementsSlot, *object_literal->constant_properties()); | 3086 result->set(kElementsSlot, *object_literal->constant_properties()); |
3073 } else { | 3087 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
3091 } | 3105 } |
3092 | 3106 |
3093 | 3107 |
3094 Handle<Object> Parser::GetBoilerplateValue(Expression* expression) { | 3108 Handle<Object> Parser::GetBoilerplateValue(Expression* expression) { |
3095 if (expression->AsLiteral() != NULL) { | 3109 if (expression->AsLiteral() != NULL) { |
3096 return expression->AsLiteral()->handle(); | 3110 return expression->AsLiteral()->handle(); |
3097 } | 3111 } |
3098 if (CompileTimeValue::IsCompileTimeValue(expression)) { | 3112 if (CompileTimeValue::IsCompileTimeValue(expression)) { |
3099 return CompileTimeValue::GetValue(expression); | 3113 return CompileTimeValue::GetValue(expression); |
3100 } | 3114 } |
3101 return Factory::undefined_value(); | 3115 return isolate()->factory()->undefined_value(); |
3102 } | 3116 } |
3103 | 3117 |
3104 // Defined in ast.cc | 3118 // Defined in ast.cc |
3105 bool IsEqualString(void* first, void* second); | 3119 bool IsEqualString(void* first, void* second); |
3106 bool IsEqualNumber(void* first, void* second); | 3120 bool IsEqualNumber(void* first, void* second); |
3107 | 3121 |
3108 | 3122 |
3109 // Validation per 11.1.5 Object Initialiser | 3123 // Validation per 11.1.5 Object Initialiser |
3110 class ObjectLiteralPropertyChecker { | 3124 class ObjectLiteralPropertyChecker { |
3111 public: | 3125 public: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3157 Literal *lit = property->key(); | 3171 Literal *lit = property->key(); |
3158 Handle<Object> handle = lit->handle(); | 3172 Handle<Object> handle = lit->handle(); |
3159 | 3173 |
3160 uint32_t hash; | 3174 uint32_t hash; |
3161 HashMap* map; | 3175 HashMap* map; |
3162 void* key; | 3176 void* key; |
3163 | 3177 |
3164 if (handle->IsSymbol()) { | 3178 if (handle->IsSymbol()) { |
3165 Handle<String> name(String::cast(*handle)); | 3179 Handle<String> name(String::cast(*handle)); |
3166 if (name->AsArrayIndex(&hash)) { | 3180 if (name->AsArrayIndex(&hash)) { |
3167 Handle<Object> key_handle = Factory::NewNumberFromUint(hash); | 3181 Handle<Object> key_handle = FACTORY->NewNumberFromUint(hash); |
3168 key = key_handle.location(); | 3182 key = key_handle.location(); |
3169 map = &elems; | 3183 map = &elems; |
3170 } else { | 3184 } else { |
3171 key = handle.location(); | 3185 key = handle.location(); |
3172 hash = name->Hash(); | 3186 hash = name->Hash(); |
3173 map = &props; | 3187 map = &props; |
3174 } | 3188 } |
3175 } else if (handle->ToArrayIndex(&hash)) { | 3189 } else if (handle->ToArrayIndex(&hash)) { |
3176 key = handle.location(); | 3190 key = handle.location(); |
3177 map = &elems; | 3191 map = &elems; |
3178 } else { | 3192 } else { |
3179 ASSERT(handle->IsNumber()); | 3193 ASSERT(handle->IsNumber()); |
3180 double num = handle->Number(); | 3194 double num = handle->Number(); |
3181 char arr[100]; | 3195 char arr[100]; |
3182 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 3196 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
3183 const char* str = DoubleToCString(num, buffer); | 3197 const char* str = DoubleToCString(num, buffer); |
3184 Handle<String> name = Factory::NewStringFromAscii(CStrVector(str)); | 3198 Handle<String> name = FACTORY->NewStringFromAscii(CStrVector(str)); |
3185 key = name.location(); | 3199 key = name.location(); |
3186 hash = name->Hash(); | 3200 hash = name->Hash(); |
3187 map = &props; | 3201 map = &props; |
3188 } | 3202 } |
3189 | 3203 |
3190 // Lookup property previously defined, if any. | 3204 // Lookup property previously defined, if any. |
3191 HashMap::Entry* entry = map->Lookup(key, hash, true); | 3205 HashMap::Entry* entry = map->Lookup(key, hash, true); |
3192 intptr_t prev = reinterpret_cast<intptr_t> (entry->value); | 3206 intptr_t prev = reinterpret_cast<intptr_t> (entry->value); |
3193 intptr_t curr = GetPropertyKind(property); | 3207 intptr_t curr = GetPropertyKind(property); |
3194 | 3208 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3286 // Special handling of getter and setter syntax: | 3300 // Special handling of getter and setter syntax: |
3287 // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } | 3301 // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } |
3288 // We have already read the "get" or "set" keyword. | 3302 // We have already read the "get" or "set" keyword. |
3289 Token::Value next = Next(); | 3303 Token::Value next = Next(); |
3290 bool is_keyword = Token::IsKeyword(next); | 3304 bool is_keyword = Token::IsKeyword(next); |
3291 if (next == Token::IDENTIFIER || next == Token::NUMBER || | 3305 if (next == Token::IDENTIFIER || next == Token::NUMBER || |
3292 next == Token::FUTURE_RESERVED_WORD || | 3306 next == Token::FUTURE_RESERVED_WORD || |
3293 next == Token::STRING || is_keyword) { | 3307 next == Token::STRING || is_keyword) { |
3294 Handle<String> name; | 3308 Handle<String> name; |
3295 if (is_keyword) { | 3309 if (is_keyword) { |
3296 name = Factory::LookupAsciiSymbol(Token::String(next)); | 3310 name = isolate_->factory()->LookupAsciiSymbol(Token::String(next)); |
3297 } else { | 3311 } else { |
3298 name = GetSymbol(CHECK_OK); | 3312 name = GetSymbol(CHECK_OK); |
3299 } | 3313 } |
3300 FunctionLiteral* value = | 3314 FunctionLiteral* value = |
3301 ParseFunctionLiteral(name, | 3315 ParseFunctionLiteral(name, |
3302 false, // reserved words are allowed here | 3316 false, // reserved words are allowed here |
3303 RelocInfo::kNoPosition, | 3317 RelocInfo::kNoPosition, |
3304 DECLARATION, | 3318 DECLARATION, |
3305 CHECK_OK); | 3319 CHECK_OK); |
3306 // Allow any number of parameters for compatiabilty with JSC. | 3320 // Allow any number of parameters for compatiabilty with JSC. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3426 if (fni_ != NULL) { | 3440 if (fni_ != NULL) { |
3427 fni_->Infer(); | 3441 fni_->Infer(); |
3428 fni_->Leave(); | 3442 fni_->Leave(); |
3429 } | 3443 } |
3430 } | 3444 } |
3431 Expect(Token::RBRACE, CHECK_OK); | 3445 Expect(Token::RBRACE, CHECK_OK); |
3432 | 3446 |
3433 // Computation of literal_index must happen before pre parse bailout. | 3447 // Computation of literal_index must happen before pre parse bailout. |
3434 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); | 3448 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); |
3435 | 3449 |
3436 Handle<FixedArray> constant_properties = | 3450 Handle<FixedArray> constant_properties = isolate()->factory()->NewFixedArray( |
3437 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED); | 3451 number_of_boilerplate_properties * 2, TENURED); |
3438 | 3452 |
3439 bool is_simple = true; | 3453 bool is_simple = true; |
3440 bool fast_elements = true; | 3454 bool fast_elements = true; |
3441 int depth = 1; | 3455 int depth = 1; |
3442 BuildObjectLiteralConstantProperties(properties, | 3456 BuildObjectLiteralConstantProperties(properties, |
3443 constant_properties, | 3457 constant_properties, |
3444 &is_simple, | 3458 &is_simple, |
3445 &fast_elements, | 3459 &fast_elements, |
3446 &depth); | 3460 &depth); |
3447 return new ObjectLiteral(constant_properties, | 3461 return new ObjectLiteral(constant_properties, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3496 FunctionLiteralType type, | 3510 FunctionLiteralType type, |
3497 bool* ok) { | 3511 bool* ok) { |
3498 // Function :: | 3512 // Function :: |
3499 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 3513 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
3500 bool is_named = !var_name.is_null(); | 3514 bool is_named = !var_name.is_null(); |
3501 | 3515 |
3502 // The name associated with this function. If it's a function expression, | 3516 // The name associated with this function. If it's a function expression, |
3503 // this is the actual function name, otherwise this is the name of the | 3517 // this is the actual function name, otherwise this is the name of the |
3504 // variable declared and initialized with the function (expression). In | 3518 // variable declared and initialized with the function (expression). In |
3505 // that case, we don't have a function name (it's empty). | 3519 // that case, we don't have a function name (it's empty). |
3506 Handle<String> name = is_named ? var_name : Factory::empty_symbol(); | 3520 Handle<String> name = |
| 3521 is_named ? var_name : isolate()->factory()->empty_symbol(); |
3507 // The function name, if any. | 3522 // The function name, if any. |
3508 Handle<String> function_name = Factory::empty_symbol(); | 3523 Handle<String> function_name = isolate()->factory()->empty_symbol(); |
3509 if (is_named && (type == EXPRESSION || type == NESTED)) { | 3524 if (is_named && (type == EXPRESSION || type == NESTED)) { |
3510 function_name = name; | 3525 function_name = name; |
3511 } | 3526 } |
3512 | 3527 |
3513 int num_parameters = 0; | 3528 int num_parameters = 0; |
3514 // Parse function body. | 3529 // Parse function body. |
3515 { Scope* scope = | 3530 { Scope* scope = |
3516 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); | 3531 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); |
3517 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, | 3532 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, |
3518 scope); | 3533 scope); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3595 if (is_lazily_compiled && pre_data() != NULL) { | 3610 if (is_lazily_compiled && pre_data() != NULL) { |
3596 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); | 3611 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); |
3597 if (!entry.is_valid()) { | 3612 if (!entry.is_valid()) { |
3598 ReportInvalidPreparseData(name, CHECK_OK); | 3613 ReportInvalidPreparseData(name, CHECK_OK); |
3599 } | 3614 } |
3600 end_pos = entry.end_pos(); | 3615 end_pos = entry.end_pos(); |
3601 if (end_pos <= function_block_pos) { | 3616 if (end_pos <= function_block_pos) { |
3602 // End position greater than end of stream is safe, and hard to check. | 3617 // End position greater than end of stream is safe, and hard to check. |
3603 ReportInvalidPreparseData(name, CHECK_OK); | 3618 ReportInvalidPreparseData(name, CHECK_OK); |
3604 } | 3619 } |
3605 Counters::total_preparse_skipped.Increment(end_pos - function_block_pos); | 3620 COUNTERS->total_preparse_skipped()->Increment( |
| 3621 end_pos - function_block_pos); |
3606 // Seek to position just before terminal '}'. | 3622 // Seek to position just before terminal '}'. |
3607 scanner().SeekForward(end_pos - 1); | 3623 scanner().SeekForward(end_pos - 1); |
3608 materialized_literal_count = entry.literal_count(); | 3624 materialized_literal_count = entry.literal_count(); |
3609 expected_property_count = entry.property_count(); | 3625 expected_property_count = entry.property_count(); |
3610 only_simple_this_property_assignments = false; | 3626 only_simple_this_property_assignments = false; |
3611 this_property_assignments = Factory::empty_fixed_array(); | 3627 this_property_assignments = isolate()->factory()->empty_fixed_array(); |
3612 Expect(Token::RBRACE, CHECK_OK); | 3628 Expect(Token::RBRACE, CHECK_OK); |
3613 } else { | 3629 } else { |
3614 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 3630 ParseSourceElements(body, Token::RBRACE, CHECK_OK); |
3615 | 3631 |
3616 materialized_literal_count = temp_scope.materialized_literal_count(); | 3632 materialized_literal_count = temp_scope.materialized_literal_count(); |
3617 expected_property_count = temp_scope.expected_property_count(); | 3633 expected_property_count = temp_scope.expected_property_count(); |
3618 only_simple_this_property_assignments = | 3634 only_simple_this_property_assignments = |
3619 temp_scope.only_simple_this_property_assignments(); | 3635 temp_scope.only_simple_this_property_assignments(); |
3620 this_property_assignments = temp_scope.this_property_assignments(); | 3636 this_property_assignments = temp_scope.this_property_assignments(); |
3621 | 3637 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3694 Expect(Token::MOD, CHECK_OK); | 3710 Expect(Token::MOD, CHECK_OK); |
3695 Handle<String> name = ParseIdentifier(CHECK_OK); | 3711 Handle<String> name = ParseIdentifier(CHECK_OK); |
3696 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); | 3712 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); |
3697 | 3713 |
3698 if (extension_ != NULL) { | 3714 if (extension_ != NULL) { |
3699 // The extension structures are only accessible while parsing the | 3715 // The extension structures are only accessible while parsing the |
3700 // very first time not when reparsing because of lazy compilation. | 3716 // very first time not when reparsing because of lazy compilation. |
3701 top_scope_->ForceEagerCompilation(); | 3717 top_scope_->ForceEagerCompilation(); |
3702 } | 3718 } |
3703 | 3719 |
3704 Runtime::Function* function = Runtime::FunctionForSymbol(name); | 3720 const Runtime::Function* function = Runtime::FunctionForSymbol(name); |
3705 | 3721 |
3706 // Check for built-in IS_VAR macro. | 3722 // Check for built-in IS_VAR macro. |
3707 if (function != NULL && | 3723 if (function != NULL && |
3708 function->intrinsic_type == Runtime::RUNTIME && | 3724 function->intrinsic_type == Runtime::RUNTIME && |
3709 function->function_id == Runtime::kIS_VAR) { | 3725 function->function_id == Runtime::kIS_VAR) { |
3710 // %IS_VAR(x) evaluates to x if x is a variable, | 3726 // %IS_VAR(x) evaluates to x if x is a variable, |
3711 // leads to a parse error otherwise. Could be implemented as an | 3727 // leads to a parse error otherwise. Could be implemented as an |
3712 // inline function %_IS_VAR(x) to eliminate this special case. | 3728 // inline function %_IS_VAR(x) to eliminate this special case. |
3713 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { | 3729 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { |
3714 return args->at(0); | 3730 return args->at(0); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3777 if (scanner().has_line_terminator_before_next() || | 3793 if (scanner().has_line_terminator_before_next() || |
3778 tok == Token::RBRACE || | 3794 tok == Token::RBRACE || |
3779 tok == Token::EOS) { | 3795 tok == Token::EOS) { |
3780 return; | 3796 return; |
3781 } | 3797 } |
3782 Expect(Token::SEMICOLON, ok); | 3798 Expect(Token::SEMICOLON, ok); |
3783 } | 3799 } |
3784 | 3800 |
3785 | 3801 |
3786 Literal* Parser::GetLiteralUndefined() { | 3802 Literal* Parser::GetLiteralUndefined() { |
3787 return new Literal(Factory::undefined_value()); | 3803 return new Literal(isolate()->factory()->undefined_value()); |
3788 } | 3804 } |
3789 | 3805 |
3790 | 3806 |
3791 Literal* Parser::GetLiteralTheHole() { | 3807 Literal* Parser::GetLiteralTheHole() { |
3792 return new Literal(Factory::the_hole_value()); | 3808 return new Literal(isolate()->factory()->the_hole_value()); |
3793 } | 3809 } |
3794 | 3810 |
3795 | 3811 |
3796 Literal* Parser::GetLiteralNumber(double value) { | 3812 Literal* Parser::GetLiteralNumber(double value) { |
3797 return NewNumberLiteral(value); | 3813 return NewNumberLiteral(value); |
3798 } | 3814 } |
3799 | 3815 |
3800 | 3816 |
3801 Handle<String> Parser::ParseIdentifier(bool* ok) { | 3817 Handle<String> Parser::ParseIdentifier(bool* ok) { |
3802 bool is_reserved; | 3818 bool is_reserved; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3930 // target stack has been used from the top of the target stack. Add | 3946 // target stack has been used from the top of the target stack. Add |
3931 // the break target to any TargetCollectors passed on the stack. | 3947 // the break target to any TargetCollectors passed on the stack. |
3932 for (Target* t = target_stack_; t != stop; t = t->previous()) { | 3948 for (Target* t = target_stack_; t != stop; t = t->previous()) { |
3933 TargetCollector* collector = t->node()->AsTargetCollector(); | 3949 TargetCollector* collector = t->node()->AsTargetCollector(); |
3934 if (collector != NULL) collector->AddTarget(target); | 3950 if (collector != NULL) collector->AddTarget(target); |
3935 } | 3951 } |
3936 } | 3952 } |
3937 | 3953 |
3938 | 3954 |
3939 Literal* Parser::NewNumberLiteral(double number) { | 3955 Literal* Parser::NewNumberLiteral(double number) { |
3940 return new Literal(Factory::NewNumber(number, TENURED)); | 3956 return new Literal(isolate()->factory()->NewNumber(number, TENURED)); |
3941 } | 3957 } |
3942 | 3958 |
3943 | 3959 |
3944 Expression* Parser::NewThrowReferenceError(Handle<String> type) { | 3960 Expression* Parser::NewThrowReferenceError(Handle<String> type) { |
3945 return NewThrowError(Factory::MakeReferenceError_symbol(), | 3961 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(), |
3946 type, HandleVector<Object>(NULL, 0)); | 3962 type, HandleVector<Object>(NULL, 0)); |
3947 } | 3963 } |
3948 | 3964 |
3949 | 3965 |
3950 Expression* Parser::NewThrowSyntaxError(Handle<String> type, | 3966 Expression* Parser::NewThrowSyntaxError(Handle<String> type, |
3951 Handle<Object> first) { | 3967 Handle<Object> first) { |
3952 int argc = first.is_null() ? 0 : 1; | 3968 int argc = first.is_null() ? 0 : 1; |
3953 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc); | 3969 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc); |
3954 return NewThrowError(Factory::MakeSyntaxError_symbol(), type, arguments); | 3970 return NewThrowError( |
| 3971 isolate()->factory()->MakeSyntaxError_symbol(), type, arguments); |
3955 } | 3972 } |
3956 | 3973 |
3957 | 3974 |
3958 Expression* Parser::NewThrowTypeError(Handle<String> type, | 3975 Expression* Parser::NewThrowTypeError(Handle<String> type, |
3959 Handle<Object> first, | 3976 Handle<Object> first, |
3960 Handle<Object> second) { | 3977 Handle<Object> second) { |
3961 ASSERT(!first.is_null() && !second.is_null()); | 3978 ASSERT(!first.is_null() && !second.is_null()); |
3962 Handle<Object> elements[] = { first, second }; | 3979 Handle<Object> elements[] = { first, second }; |
3963 Vector< Handle<Object> > arguments = | 3980 Vector< Handle<Object> > arguments = |
3964 HandleVector<Object>(elements, ARRAY_SIZE(elements)); | 3981 HandleVector<Object>(elements, ARRAY_SIZE(elements)); |
3965 return NewThrowError(Factory::MakeTypeError_symbol(), type, arguments); | 3982 return NewThrowError( |
| 3983 isolate()->factory()->MakeTypeError_symbol(), type, arguments); |
3966 } | 3984 } |
3967 | 3985 |
3968 | 3986 |
3969 Expression* Parser::NewThrowError(Handle<String> constructor, | 3987 Expression* Parser::NewThrowError(Handle<String> constructor, |
3970 Handle<String> type, | 3988 Handle<String> type, |
3971 Vector< Handle<Object> > arguments) { | 3989 Vector< Handle<Object> > arguments) { |
3972 int argc = arguments.length(); | 3990 int argc = arguments.length(); |
3973 Handle<FixedArray> elements = Factory::NewFixedArray(argc, TENURED); | 3991 Handle<FixedArray> elements = isolate()->factory()->NewFixedArray(argc, |
| 3992 TENURED); |
3974 for (int i = 0; i < argc; i++) { | 3993 for (int i = 0; i < argc; i++) { |
3975 Handle<Object> element = arguments[i]; | 3994 Handle<Object> element = arguments[i]; |
3976 if (!element.is_null()) { | 3995 if (!element.is_null()) { |
3977 elements->set(i, *element); | 3996 elements->set(i, *element); |
3978 } | 3997 } |
3979 } | 3998 } |
3980 Handle<JSArray> array = Factory::NewJSArrayWithElements(elements, TENURED); | 3999 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(elements, |
| 4000 TENURED); |
3981 | 4001 |
3982 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); | 4002 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); |
3983 args->Add(new Literal(type)); | 4003 args->Add(new Literal(type)); |
3984 args->Add(new Literal(array)); | 4004 args->Add(new Literal(array)); |
3985 return new Throw(new CallRuntime(constructor, NULL, args), | 4005 return new Throw(new CallRuntime(constructor, NULL, args), |
3986 scanner().location().beg_pos); | 4006 scanner().location().beg_pos); |
3987 } | 4007 } |
3988 | 4008 |
3989 // ---------------------------------------------------------------------------- | 4009 // ---------------------------------------------------------------------------- |
3990 // JSON | 4010 // JSON |
3991 | 4011 |
3992 Handle<Object> JsonParser::ParseJson(Handle<String> script, | 4012 Handle<Object> JsonParser::ParseJson(Handle<String> script, |
3993 UC16CharacterStream* source) { | 4013 UC16CharacterStream* source) { |
3994 scanner_.Initialize(source); | 4014 scanner_.Initialize(source); |
3995 stack_overflow_ = false; | 4015 stack_overflow_ = false; |
3996 Handle<Object> result = ParseJsonValue(); | 4016 Handle<Object> result = ParseJsonValue(); |
3997 if (result.is_null() || scanner_.Next() != Token::EOS) { | 4017 if (result.is_null() || scanner_.Next() != Token::EOS) { |
3998 if (stack_overflow_) { | 4018 if (stack_overflow_) { |
3999 // Scanner failed. | 4019 // Scanner failed. |
4000 Top::StackOverflow(); | 4020 isolate()->StackOverflow(); |
4001 } else { | 4021 } else { |
4002 // Parse failed. Scanner's current token is the unexpected token. | 4022 // Parse failed. Scanner's current token is the unexpected token. |
4003 Token::Value token = scanner_.current_token(); | 4023 Token::Value token = scanner_.current_token(); |
4004 | 4024 |
4005 const char* message; | 4025 const char* message; |
4006 const char* name_opt = NULL; | 4026 const char* name_opt = NULL; |
4007 | 4027 |
4008 switch (token) { | 4028 switch (token) { |
4009 case Token::EOS: | 4029 case Token::EOS: |
4010 message = "unexpected_eos"; | 4030 message = "unexpected_eos"; |
4011 break; | 4031 break; |
4012 case Token::NUMBER: | 4032 case Token::NUMBER: |
4013 message = "unexpected_token_number"; | 4033 message = "unexpected_token_number"; |
4014 break; | 4034 break; |
4015 case Token::STRING: | 4035 case Token::STRING: |
4016 message = "unexpected_token_string"; | 4036 message = "unexpected_token_string"; |
4017 break; | 4037 break; |
4018 case Token::IDENTIFIER: | 4038 case Token::IDENTIFIER: |
4019 case Token::FUTURE_RESERVED_WORD: | 4039 case Token::FUTURE_RESERVED_WORD: |
4020 message = "unexpected_token_identifier"; | 4040 message = "unexpected_token_identifier"; |
4021 break; | 4041 break; |
4022 default: | 4042 default: |
4023 message = "unexpected_token"; | 4043 message = "unexpected_token"; |
4024 name_opt = Token::String(token); | 4044 name_opt = Token::String(token); |
4025 ASSERT(name_opt != NULL); | 4045 ASSERT(name_opt != NULL); |
4026 break; | 4046 break; |
4027 } | 4047 } |
4028 | 4048 |
4029 Scanner::Location source_location = scanner_.location(); | 4049 Scanner::Location source_location = scanner_.location(); |
4030 MessageLocation location(Factory::NewScript(script), | 4050 Factory* factory = isolate()->factory(); |
| 4051 MessageLocation location(factory->NewScript(script), |
4031 source_location.beg_pos, | 4052 source_location.beg_pos, |
4032 source_location.end_pos); | 4053 source_location.end_pos); |
4033 Handle<JSArray> array; | 4054 Handle<JSArray> array; |
4034 if (name_opt == NULL) { | 4055 if (name_opt == NULL) { |
4035 array = Factory::NewJSArray(0); | 4056 array = factory->NewJSArray(0); |
4036 } else { | 4057 } else { |
4037 Handle<String> name = Factory::NewStringFromUtf8(CStrVector(name_opt)); | 4058 Handle<String> name = factory->NewStringFromUtf8(CStrVector(name_opt)); |
4038 Handle<FixedArray> element = Factory::NewFixedArray(1); | 4059 Handle<FixedArray> element = factory->NewFixedArray(1); |
4039 element->set(0, *name); | 4060 element->set(0, *name); |
4040 array = Factory::NewJSArrayWithElements(element); | 4061 array = factory->NewJSArrayWithElements(element); |
4041 } | 4062 } |
4042 Handle<Object> result = Factory::NewSyntaxError(message, array); | 4063 Handle<Object> result = factory->NewSyntaxError(message, array); |
4043 Top::Throw(*result, &location); | 4064 isolate()->Throw(*result, &location); |
4044 return Handle<Object>::null(); | 4065 return Handle<Object>::null(); |
4045 } | 4066 } |
4046 } | 4067 } |
4047 return result; | 4068 return result; |
4048 } | 4069 } |
4049 | 4070 |
4050 | 4071 |
4051 Handle<String> JsonParser::GetString() { | 4072 Handle<String> JsonParser::GetString() { |
4052 int literal_length = scanner_.literal_length(); | 4073 int literal_length = scanner_.literal_length(); |
4053 if (literal_length == 0) { | 4074 if (literal_length == 0) { |
4054 return Factory::empty_string(); | 4075 return isolate()->factory()->empty_string(); |
4055 } | 4076 } |
4056 if (scanner_.is_literal_ascii()) { | 4077 if (scanner_.is_literal_ascii()) { |
4057 return Factory::NewStringFromAscii(scanner_.literal_ascii_string()); | 4078 return isolate()->factory()->NewStringFromAscii( |
| 4079 scanner_.literal_ascii_string()); |
4058 } else { | 4080 } else { |
4059 return Factory::NewStringFromTwoByte(scanner_.literal_uc16_string()); | 4081 return isolate()->factory()->NewStringFromTwoByte( |
| 4082 scanner_.literal_uc16_string()); |
4060 } | 4083 } |
4061 } | 4084 } |
4062 | 4085 |
4063 | 4086 |
4064 // Parse any JSON value. | 4087 // Parse any JSON value. |
4065 Handle<Object> JsonParser::ParseJsonValue() { | 4088 Handle<Object> JsonParser::ParseJsonValue() { |
4066 Token::Value token = scanner_.Next(); | 4089 Token::Value token = scanner_.Next(); |
4067 switch (token) { | 4090 switch (token) { |
4068 case Token::STRING: | 4091 case Token::STRING: |
4069 return GetString(); | 4092 return GetString(); |
4070 case Token::NUMBER: | 4093 case Token::NUMBER: |
4071 return Factory::NewNumber(scanner_.number()); | 4094 return isolate()->factory()->NewNumber(scanner_.number()); |
4072 case Token::FALSE_LITERAL: | 4095 case Token::FALSE_LITERAL: |
4073 return Factory::false_value(); | 4096 return isolate()->factory()->false_value(); |
4074 case Token::TRUE_LITERAL: | 4097 case Token::TRUE_LITERAL: |
4075 return Factory::true_value(); | 4098 return isolate()->factory()->true_value(); |
4076 case Token::NULL_LITERAL: | 4099 case Token::NULL_LITERAL: |
4077 return Factory::null_value(); | 4100 return isolate()->factory()->null_value(); |
4078 case Token::LBRACE: | 4101 case Token::LBRACE: |
4079 return ParseJsonObject(); | 4102 return ParseJsonObject(); |
4080 case Token::LBRACK: | 4103 case Token::LBRACK: |
4081 return ParseJsonArray(); | 4104 return ParseJsonArray(); |
4082 default: | 4105 default: |
4083 return ReportUnexpectedToken(); | 4106 return ReportUnexpectedToken(); |
4084 } | 4107 } |
4085 } | 4108 } |
4086 | 4109 |
4087 | 4110 |
4088 // Parse a JSON object. Scanner must be right after '{' token. | 4111 // Parse a JSON object. Scanner must be right after '{' token. |
4089 Handle<Object> JsonParser::ParseJsonObject() { | 4112 Handle<Object> JsonParser::ParseJsonObject() { |
4090 Handle<JSFunction> object_constructor( | 4113 Handle<JSFunction> object_constructor( |
4091 Top::global_context()->object_function()); | 4114 isolate()->global_context()->object_function()); |
4092 Handle<JSObject> json_object = Factory::NewJSObject(object_constructor); | 4115 Handle<JSObject> json_object = |
| 4116 isolate()->factory()->NewJSObject(object_constructor); |
4093 if (scanner_.peek() == Token::RBRACE) { | 4117 if (scanner_.peek() == Token::RBRACE) { |
4094 scanner_.Next(); | 4118 scanner_.Next(); |
4095 } else { | 4119 } else { |
4096 if (StackLimitCheck().HasOverflowed()) { | 4120 if (StackLimitCheck(isolate()).HasOverflowed()) { |
4097 stack_overflow_ = true; | 4121 stack_overflow_ = true; |
4098 return Handle<Object>::null(); | 4122 return Handle<Object>::null(); |
4099 } | 4123 } |
4100 do { | 4124 do { |
4101 if (scanner_.Next() != Token::STRING) { | 4125 if (scanner_.Next() != Token::STRING) { |
4102 return ReportUnexpectedToken(); | 4126 return ReportUnexpectedToken(); |
4103 } | 4127 } |
4104 Handle<String> key = GetString(); | 4128 Handle<String> key = GetString(); |
4105 if (scanner_.Next() != Token::COLON) { | 4129 if (scanner_.Next() != Token::COLON) { |
4106 return ReportUnexpectedToken(); | 4130 return ReportUnexpectedToken(); |
4107 } | 4131 } |
4108 Handle<Object> value = ParseJsonValue(); | 4132 Handle<Object> value = ParseJsonValue(); |
4109 if (value.is_null()) return Handle<Object>::null(); | 4133 if (value.is_null()) return Handle<Object>::null(); |
4110 uint32_t index; | 4134 uint32_t index; |
4111 if (key->AsArrayIndex(&index)) { | 4135 if (key->AsArrayIndex(&index)) { |
4112 SetOwnElement(json_object, index, value, kNonStrictMode); | 4136 SetOwnElement(json_object, index, value, kNonStrictMode); |
4113 } else if (key->Equals(Heap::Proto_symbol())) { | 4137 } else if (key->Equals(isolate()->heap()->Proto_symbol())) { |
4114 // We can't remove the __proto__ accessor since it's hardcoded | 4138 // We can't remove the __proto__ accessor since it's hardcoded |
4115 // in several places. Instead go along and add the value as | 4139 // in several places. Instead go along and add the value as |
4116 // the prototype of the created object if possible. | 4140 // the prototype of the created object if possible. |
4117 SetPrototype(json_object, value); | 4141 SetPrototype(json_object, value); |
4118 } else { | 4142 } else { |
4119 SetLocalPropertyIgnoreAttributes(json_object, key, value, NONE); | 4143 SetLocalPropertyIgnoreAttributes(json_object, key, value, NONE); |
4120 } | 4144 } |
4121 } while (scanner_.Next() == Token::COMMA); | 4145 } while (scanner_.Next() == Token::COMMA); |
4122 if (scanner_.current_token() != Token::RBRACE) { | 4146 if (scanner_.current_token() != Token::RBRACE) { |
4123 return ReportUnexpectedToken(); | 4147 return ReportUnexpectedToken(); |
4124 } | 4148 } |
4125 } | 4149 } |
4126 return json_object; | 4150 return json_object; |
4127 } | 4151 } |
4128 | 4152 |
4129 | 4153 |
4130 // Parse a JSON array. Scanner must be right after '[' token. | 4154 // Parse a JSON array. Scanner must be right after '[' token. |
4131 Handle<Object> JsonParser::ParseJsonArray() { | 4155 Handle<Object> JsonParser::ParseJsonArray() { |
4132 ZoneScope zone_scope(DELETE_ON_EXIT); | 4156 ZoneScope zone_scope(DELETE_ON_EXIT); |
4133 ZoneList<Handle<Object> > elements(4); | 4157 ZoneList<Handle<Object> > elements(4); |
4134 | 4158 |
4135 Token::Value token = scanner_.peek(); | 4159 Token::Value token = scanner_.peek(); |
4136 if (token == Token::RBRACK) { | 4160 if (token == Token::RBRACK) { |
4137 scanner_.Next(); | 4161 scanner_.Next(); |
4138 } else { | 4162 } else { |
4139 if (StackLimitCheck().HasOverflowed()) { | 4163 if (StackLimitCheck(isolate()).HasOverflowed()) { |
4140 stack_overflow_ = true; | 4164 stack_overflow_ = true; |
4141 return Handle<Object>::null(); | 4165 return Handle<Object>::null(); |
4142 } | 4166 } |
4143 do { | 4167 do { |
4144 Handle<Object> element = ParseJsonValue(); | 4168 Handle<Object> element = ParseJsonValue(); |
4145 if (element.is_null()) return Handle<Object>::null(); | 4169 if (element.is_null()) return Handle<Object>::null(); |
4146 elements.Add(element); | 4170 elements.Add(element); |
4147 token = scanner_.Next(); | 4171 token = scanner_.Next(); |
4148 } while (token == Token::COMMA); | 4172 } while (token == Token::COMMA); |
4149 if (token != Token::RBRACK) { | 4173 if (token != Token::RBRACK) { |
4150 return ReportUnexpectedToken(); | 4174 return ReportUnexpectedToken(); |
4151 } | 4175 } |
4152 } | 4176 } |
4153 | 4177 |
4154 // Allocate a fixed array with all the elements. | 4178 // Allocate a fixed array with all the elements. |
4155 Handle<FixedArray> fast_elements = | 4179 Handle<FixedArray> fast_elements = |
4156 Factory::NewFixedArray(elements.length()); | 4180 isolate()->factory()->NewFixedArray(elements.length()); |
4157 | 4181 |
4158 for (int i = 0, n = elements.length(); i < n; i++) { | 4182 for (int i = 0, n = elements.length(); i < n; i++) { |
4159 fast_elements->set(i, *elements[i]); | 4183 fast_elements->set(i, *elements[i]); |
4160 } | 4184 } |
4161 | 4185 |
4162 return Factory::NewJSArrayWithElements(fast_elements); | 4186 return isolate()->factory()->NewJSArrayWithElements(fast_elements); |
4163 } | 4187 } |
4164 | 4188 |
4165 // ---------------------------------------------------------------------------- | 4189 // ---------------------------------------------------------------------------- |
4166 // Regular expressions | 4190 // Regular expressions |
4167 | 4191 |
4168 | 4192 |
4169 RegExpParser::RegExpParser(FlatStringReader* in, | 4193 RegExpParser::RegExpParser(FlatStringReader* in, |
4170 Handle<String>* error, | 4194 Handle<String>* error, |
4171 bool multiline) | 4195 bool multiline) |
4172 : error_(error), | 4196 : isolate_(Isolate::Current()), |
4173 captures_(NULL), | 4197 error_(error), |
4174 in_(in), | 4198 captures_(NULL), |
4175 current_(kEndMarker), | 4199 in_(in), |
4176 next_pos_(0), | 4200 current_(kEndMarker), |
4177 capture_count_(0), | 4201 next_pos_(0), |
4178 has_more_(true), | 4202 capture_count_(0), |
4179 multiline_(multiline), | 4203 has_more_(true), |
4180 simple_(false), | 4204 multiline_(multiline), |
4181 contains_anchor_(false), | 4205 simple_(false), |
4182 is_scanned_for_captures_(false), | 4206 contains_anchor_(false), |
4183 failed_(false) { | 4207 is_scanned_for_captures_(false), |
| 4208 failed_(false) { |
4184 Advance(); | 4209 Advance(); |
4185 } | 4210 } |
4186 | 4211 |
4187 | 4212 |
4188 uc32 RegExpParser::Next() { | 4213 uc32 RegExpParser::Next() { |
4189 if (has_next()) { | 4214 if (has_next()) { |
4190 return in()->Get(next_pos_); | 4215 return in()->Get(next_pos_); |
4191 } else { | 4216 } else { |
4192 return kEndMarker; | 4217 return kEndMarker; |
4193 } | 4218 } |
4194 } | 4219 } |
4195 | 4220 |
4196 | 4221 |
4197 void RegExpParser::Advance() { | 4222 void RegExpParser::Advance() { |
4198 if (next_pos_ < in()->length()) { | 4223 if (next_pos_ < in()->length()) { |
4199 StackLimitCheck check; | 4224 StackLimitCheck check(isolate()); |
4200 if (check.HasOverflowed()) { | 4225 if (check.HasOverflowed()) { |
4201 ReportError(CStrVector(Top::kStackOverflowMessage)); | 4226 ReportError(CStrVector(Isolate::kStackOverflowMessage)); |
4202 } else if (Zone::excess_allocation()) { | 4227 } else if (isolate()->zone()->excess_allocation()) { |
4203 ReportError(CStrVector("Regular expression too large")); | 4228 ReportError(CStrVector("Regular expression too large")); |
4204 } else { | 4229 } else { |
4205 current_ = in()->Get(next_pos_); | 4230 current_ = in()->Get(next_pos_); |
4206 next_pos_++; | 4231 next_pos_++; |
4207 } | 4232 } |
4208 } else { | 4233 } else { |
4209 current_ = kEndMarker; | 4234 current_ = kEndMarker; |
4210 has_more_ = false; | 4235 has_more_ = false; |
4211 } | 4236 } |
4212 } | 4237 } |
(...skipping 10 matching lines...) Expand all Loading... |
4223 Advance(); | 4248 Advance(); |
4224 } | 4249 } |
4225 | 4250 |
4226 | 4251 |
4227 bool RegExpParser::simple() { | 4252 bool RegExpParser::simple() { |
4228 return simple_; | 4253 return simple_; |
4229 } | 4254 } |
4230 | 4255 |
4231 RegExpTree* RegExpParser::ReportError(Vector<const char> message) { | 4256 RegExpTree* RegExpParser::ReportError(Vector<const char> message) { |
4232 failed_ = true; | 4257 failed_ = true; |
4233 *error_ = Factory::NewStringFromAscii(message, NOT_TENURED); | 4258 *error_ = isolate()->factory()->NewStringFromAscii(message, NOT_TENURED); |
4234 // Zip to the end to make sure the no more input is read. | 4259 // Zip to the end to make sure the no more input is read. |
4235 current_ = kEndMarker; | 4260 current_ = kEndMarker; |
4236 next_pos_ = in()->length(); | 4261 next_pos_ = in()->length(); |
4237 return NULL; | 4262 return NULL; |
4238 } | 4263 } |
4239 | 4264 |
4240 | 4265 |
4241 // Pattern :: | 4266 // Pattern :: |
4242 // Disjunction | 4267 // Disjunction |
4243 RegExpTree* RegExpParser::ParsePattern() { | 4268 RegExpTree* RegExpParser::ParsePattern() { |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4577 Advance(); | 4602 Advance(); |
4578 } else if (FLAG_regexp_possessive_quantifier && current() == '+') { | 4603 } else if (FLAG_regexp_possessive_quantifier && current() == '+') { |
4579 // FLAG_regexp_possessive_quantifier is a debug-only flag. | 4604 // FLAG_regexp_possessive_quantifier is a debug-only flag. |
4580 type = RegExpQuantifier::POSSESSIVE; | 4605 type = RegExpQuantifier::POSSESSIVE; |
4581 Advance(); | 4606 Advance(); |
4582 } | 4607 } |
4583 builder->AddQuantifierToAtom(min, max, type); | 4608 builder->AddQuantifierToAtom(min, max, type); |
4584 } | 4609 } |
4585 } | 4610 } |
4586 | 4611 |
4587 class SourceCharacter { | |
4588 public: | |
4589 static bool Is(uc32 c) { | |
4590 switch (c) { | |
4591 // case ']': case '}': | |
4592 // In spidermonkey and jsc these are treated as source characters | |
4593 // so we do too. | |
4594 case '^': case '$': case '\\': case '.': case '*': case '+': | |
4595 case '?': case '(': case ')': case '[': case '{': case '|': | |
4596 case RegExpParser::kEndMarker: | |
4597 return false; | |
4598 default: | |
4599 return true; | |
4600 } | |
4601 } | |
4602 }; | |
4603 | |
4604 | |
4605 static unibrow::Predicate<SourceCharacter> source_character; | |
4606 | |
4607 | |
4608 static inline bool IsSourceCharacter(uc32 c) { | |
4609 return source_character.get(c); | |
4610 } | |
4611 | 4612 |
4612 #ifdef DEBUG | 4613 #ifdef DEBUG |
4613 // Currently only used in an ASSERT. | 4614 // Currently only used in an ASSERT. |
4614 static bool IsSpecialClassEscape(uc32 c) { | 4615 static bool IsSpecialClassEscape(uc32 c) { |
4615 switch (c) { | 4616 switch (c) { |
4616 case 'd': case 'D': | 4617 case 'd': case 'D': |
4617 case 's': case 'S': | 4618 case 's': case 'S': |
4618 case 'w': case 'W': | 4619 case 'w': case 'W': |
4619 return true; | 4620 return true; |
4620 default: | 4621 default: |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5053 } | 5054 } |
5054 *source = data; | 5055 *source = data; |
5055 return result; | 5056 return result; |
5056 } | 5057 } |
5057 | 5058 |
5058 | 5059 |
5059 // Create a Scanner for the preparser to use as input, and preparse the source. | 5060 // Create a Scanner for the preparser to use as input, and preparse the source. |
5060 static ScriptDataImpl* DoPreParse(UC16CharacterStream* source, | 5061 static ScriptDataImpl* DoPreParse(UC16CharacterStream* source, |
5061 bool allow_lazy, | 5062 bool allow_lazy, |
5062 ParserRecorder* recorder) { | 5063 ParserRecorder* recorder) { |
5063 V8JavaScriptScanner scanner; | 5064 Isolate* isolate = Isolate::Current(); |
| 5065 V8JavaScriptScanner scanner(isolate); |
5064 scanner.Initialize(source); | 5066 scanner.Initialize(source); |
5065 intptr_t stack_limit = StackGuard::real_climit(); | 5067 intptr_t stack_limit = isolate->stack_guard()->real_climit(); |
5066 if (!preparser::PreParser::PreParseProgram(&scanner, | 5068 if (!preparser::PreParser::PreParseProgram(&scanner, |
5067 recorder, | 5069 recorder, |
5068 allow_lazy, | 5070 allow_lazy, |
5069 stack_limit)) { | 5071 stack_limit)) { |
5070 Top::StackOverflow(); | 5072 isolate->StackOverflow(); |
5071 return NULL; | 5073 return NULL; |
5072 } | 5074 } |
5073 | 5075 |
5074 // Extract the accumulated data from the recorder as a single | 5076 // Extract the accumulated data from the recorder as a single |
5075 // contiguous vector that we are responsible for disposing. | 5077 // contiguous vector that we are responsible for disposing. |
5076 Vector<unsigned> store = recorder->ExtractData(); | 5078 Vector<unsigned> store = recorder->ExtractData(); |
5077 return new ScriptDataImpl(store); | 5079 return new ScriptDataImpl(store); |
5078 } | 5080 } |
5079 | 5081 |
5080 | 5082 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5139 if (pre_data != NULL && pre_data->has_error()) { | 5141 if (pre_data != NULL && pre_data->has_error()) { |
5140 Scanner::Location loc = pre_data->MessageLocation(); | 5142 Scanner::Location loc = pre_data->MessageLocation(); |
5141 const char* message = pre_data->BuildMessage(); | 5143 const char* message = pre_data->BuildMessage(); |
5142 Vector<const char*> args = pre_data->BuildArgs(); | 5144 Vector<const char*> args = pre_data->BuildArgs(); |
5143 parser.ReportMessageAt(loc, message, args); | 5145 parser.ReportMessageAt(loc, message, args); |
5144 DeleteArray(message); | 5146 DeleteArray(message); |
5145 for (int i = 0; i < args.length(); i++) { | 5147 for (int i = 0; i < args.length(); i++) { |
5146 DeleteArray(args[i]); | 5148 DeleteArray(args[i]); |
5147 } | 5149 } |
5148 DeleteArray(args.start()); | 5150 DeleteArray(args.start()); |
5149 ASSERT(Top::has_pending_exception()); | 5151 ASSERT(info->isolate()->has_pending_exception()); |
5150 } else { | 5152 } else { |
5151 Handle<String> source = Handle<String>(String::cast(script->source())); | 5153 Handle<String> source = Handle<String>(String::cast(script->source())); |
5152 result = parser.ParseProgram(source, | 5154 result = parser.ParseProgram(source, |
5153 info->is_global(), | 5155 info->is_global(), |
5154 info->StrictMode()); | 5156 info->StrictMode()); |
5155 } | 5157 } |
5156 } | 5158 } |
5157 | 5159 |
5158 info->SetFunction(result); | 5160 info->SetFunction(result); |
5159 return (result != NULL); | 5161 return (result != NULL); |
5160 } | 5162 } |
5161 | 5163 |
5162 } } // namespace v8::internal | 5164 } } // namespace v8::internal |
OLD | NEW |