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

Side by Side Diff: src/parser.cc

Issue 4244003: Remove old preparser option and behavior from the parser. (Closed)
Patch Set: Address review comment + cleanup. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 #include "bootstrapper.h" 32 #include "bootstrapper.h"
33 #include "codegen.h" 33 #include "codegen.h"
34 #include "compiler.h" 34 #include "compiler.h"
35 #include "func-name-inferrer.h" 35 #include "func-name-inferrer.h"
36 #include "messages.h" 36 #include "messages.h"
37 #include "parser.h" 37 #include "parser.h"
38 #include "platform.h" 38 #include "platform.h"
39 #include "preparser.h" 39 #include "preparser.h"
40 #include "runtime.h" 40 #include "runtime.h"
41 #include "scopeinfo.h" 41 #include "scopeinfo.h"
42 #include "scopes.h"
43 #include "string-stream.h" 42 #include "string-stream.h"
44 43
45 #include "ast-inl.h" 44 #include "ast-inl.h"
46 #include "jump-target-inl.h" 45 #include "jump-target-inl.h"
47 46
48 namespace v8 { 47 namespace v8 {
49 namespace internal { 48 namespace internal {
50 49
51 // PositionStack is used for on-stack allocation of token positions for 50 // PositionStack is used for on-stack allocation of token positions for
52 // new expressions. Please look at ParseNewExpression. 51 // new expressions. Please look at ParseNewExpression.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 parent_(*variable) { 316 parent_(*variable) {
318 *variable = this; 317 *variable = this;
319 } 318 }
320 319
321 320
322 TemporaryScope::~TemporaryScope() { 321 TemporaryScope::~TemporaryScope() {
323 *variable_ = parent_; 322 *variable_ = parent_;
324 } 323 }
325 324
326 325
327 // A zone list wrapper lets code either access a access a zone list 326 Handle<String> Parser::LookupSymbol(int symbol_id,
328 // or appear to do so while actually ignoring all operations. 327 Vector<const char> string) {
329 template <typename T> 328 // Length of symbol cache is the number of identified symbols.
330 class ZoneListWrapper { 329 // If we are larger than that, or negative, it's not a cached symbol.
331 public: 330 // This might also happen if there is no preparser symbol data, even
332 ZoneListWrapper() : list_(NULL) { } 331 // if there is some preparser data.
333 explicit ZoneListWrapper(int size) : list_(new ZoneList<T*>(size)) { } 332 if (static_cast<unsigned>(symbol_id)
334 void Add(T* that) { if (list_) list_->Add(that); } 333 >= static_cast<unsigned>(symbol_cache_.length())) {
335 int length() { return list_->length(); } 334 return Factory::LookupSymbol(string);
336 ZoneList<T*>* elements() { return list_; } 335 }
337 T* at(int index) { return list_->at(index); } 336 return LookupCachedSymbol(symbol_id, string);
338 private: 337 }
339 ZoneList<T*>* list_;
340 };
341 338
342 339
343 // Allocation macro that should be used to allocate objects that must 340 Handle<String> Parser::LookupCachedSymbol(int symbol_id,
344 // only be allocated in real parsing mode. Note that in preparse mode 341 Vector<const char> string) {
345 // not only is the syntax tree not created but the constructor 342 // Make sure the cache is large enough to hold the symbol identifier.
346 // arguments are not evaluated. 343 if (symbol_cache_.length() <= symbol_id) {
347 #define NEW(expr) (is_pre_parsing_ ? NULL : new expr) 344 // Increase length to index + 1.
348 345 symbol_cache_.AddBlock(Handle<String>::null(),
349 346 symbol_id + 1 - symbol_cache_.length());
350 class ParserFactory BASE_EMBEDDED {
351 public:
352 explicit ParserFactory(bool is_pre_parsing) :
353 is_pre_parsing_(is_pre_parsing) { }
354
355 virtual ~ParserFactory() { }
356
357 virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with);
358
359 virtual Handle<String> LookupSymbol(int index, Vector<const char> string) {
360 return Handle<String>();
361 } 347 }
362 348 Handle<String> result = symbol_cache_.at(symbol_id);
363 virtual Handle<String> EmptySymbol() { 349 if (result.is_null()) {
364 return Handle<String>(); 350 result = Factory::LookupSymbol(string);
365 } 351 symbol_cache_.at(symbol_id) = result;
366
367 virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) {
368 if (obj == VariableProxySentinel::this_proxy()) {
369 return Property::this_property();
370 } else {
371 return ValidLeftHandSideSentinel::instance();
372 }
373 }
374
375 virtual Expression* NewCall(Expression* expression,
376 ZoneList<Expression*>* arguments,
377 int pos) {
378 return Call::sentinel();
379 }
380
381 virtual Statement* EmptyStatement() {
382 return NULL;
383 }
384
385 template <typename T> ZoneListWrapper<T> NewList(int size) {
386 return is_pre_parsing_ ? ZoneListWrapper<T>() : ZoneListWrapper<T>(size);
387 }
388
389 private:
390 bool is_pre_parsing_;
391 };
392
393
394 class ConditionalLogPauseScope {
395 public:
396 ConditionalLogPauseScope(bool pause, ParserLog* log)
397 : log_(log), pause_(pause) {
398 if (pause) log->PauseRecording();
399 }
400 ~ConditionalLogPauseScope() {
401 if (pause_) log_->ResumeRecording();
402 }
403 private:
404 ParserLog* log_;
405 bool pause_;
406 };
407
408
409 class AstBuildingParserFactory : public ParserFactory {
410 public:
411 explicit AstBuildingParserFactory(int expected_symbols)
412 : ParserFactory(false), symbol_cache_(expected_symbols) { }
413
414 virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with);
415
416 virtual Handle<String> LookupSymbol(int symbol_id,
417 Vector<const char> string) {
418 // Length of symbol cache is the number of identified symbols.
419 // If we are larger than that, or negative, it's not a cached symbol.
420 // This might also happen if there is no preparser symbol data, even
421 // if there is some preparser data.
422 if (static_cast<unsigned>(symbol_id)
423 >= static_cast<unsigned>(symbol_cache_.length())) {
424 return Factory::LookupSymbol(string);
425 }
426 return LookupCachedSymbol(symbol_id, string);
427 }
428
429 Handle<String> LookupCachedSymbol(int symbol_id,
430 Vector<const char> string) {
431 // Make sure the cache is large enough to hold the symbol identifier.
432 if (symbol_cache_.length() <= symbol_id) {
433 // Increase length to index + 1.
434 symbol_cache_.AddBlock(Handle<String>::null(),
435 symbol_id + 1 - symbol_cache_.length());
436 }
437 Handle<String> result = symbol_cache_.at(symbol_id);
438 if (result.is_null()) {
439 result = Factory::LookupSymbol(string);
440 symbol_cache_.at(symbol_id) = result;
441 return result;
442 }
443 Counters::total_preparse_symbols_skipped.Increment();
444 return result; 352 return result;
445 } 353 }
446 354 Counters::total_preparse_symbols_skipped.Increment();
447 virtual Handle<String> EmptySymbol() { 355 return result;
448 return Factory::empty_symbol(); 356 }
449 }
450
451 virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) {
452 return new Property(obj, key, pos);
453 }
454
455 virtual Expression* NewCall(Expression* expression,
456 ZoneList<Expression*>* arguments,
457 int pos) {
458 return new Call(expression, arguments, pos);
459 }
460
461 virtual Statement* EmptyStatement();
462 private:
463 List<Handle<String> > symbol_cache_;
464 };
465 357
466 358
467 Vector<unsigned> PartialParserRecorder::ExtractData() { 359 Vector<unsigned> PartialParserRecorder::ExtractData() {
468 int function_size = function_store_.size(); 360 int function_size = function_store_.size();
469 int total_size = ScriptDataImpl::kHeaderSize + function_size; 361 int total_size = ScriptDataImpl::kHeaderSize + function_size;
470 Vector<unsigned> data = Vector<unsigned>::New(total_size); 362 Vector<unsigned> data = Vector<unsigned>::New(total_size);
471 preamble_[ScriptDataImpl::kFunctionsSizeOffset] = function_size; 363 preamble_[ScriptDataImpl::kFunctionsSizeOffset] = function_size;
472 preamble_[ScriptDataImpl::kSymbolCountOffset] = 0; 364 preamble_[ScriptDataImpl::kSymbolCountOffset] = 0;
473 memcpy(data.start(), preamble_, sizeof(preamble_)); 365 memcpy(data.start(), preamble_, sizeof(preamble_));
474 int symbol_start = ScriptDataImpl::kHeaderSize + function_size; 366 int symbol_start = ScriptDataImpl::kHeaderSize + function_size;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 symbol_start)); 408 symbol_start));
517 } 409 }
518 if (!has_error()) { 410 if (!has_error()) {
519 symbol_store_.WriteTo( 411 symbol_store_.WriteTo(
520 Vector<byte>::cast(data.SubVector(symbol_start, total_size))); 412 Vector<byte>::cast(data.SubVector(symbol_start, total_size)));
521 } 413 }
522 return data; 414 return data;
523 } 415 }
524 416
525 417
526
527
528 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { 418 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) {
529 // The current pre-data entry must be a FunctionEntry with the given 419 // The current pre-data entry must be a FunctionEntry with the given
530 // start position. 420 // start position.
531 if ((function_index_ + FunctionEntry::kSize <= store_.length()) 421 if ((function_index_ + FunctionEntry::kSize <= store_.length())
532 && (static_cast<int>(store_[function_index_]) == start)) { 422 && (static_cast<int>(store_[function_index_]) == start)) {
533 int index = function_index_; 423 int index = function_index_;
534 function_index_ += FunctionEntry::kSize; 424 function_index_ += FunctionEntry::kSize;
535 return FunctionEntry(store_.SubVector(index, 425 return FunctionEntry(store_.SubVector(index,
536 index + FunctionEntry::kSize)); 426 index + FunctionEntry::kSize));
537 } 427 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 unsigned ScriptDataImpl::Read(int position) { 587 unsigned ScriptDataImpl::Read(int position) {
698 return store_[ScriptDataImpl::kHeaderSize + position]; 588 return store_[ScriptDataImpl::kHeaderSize + position];
699 } 589 }
700 590
701 591
702 unsigned* ScriptDataImpl::ReadAddress(int position) { 592 unsigned* ScriptDataImpl::ReadAddress(int position) {
703 return &store_[ScriptDataImpl::kHeaderSize + position]; 593 return &store_[ScriptDataImpl::kHeaderSize + position];
704 } 594 }
705 595
706 596
707 class AstBuildingParser : public Parser { 597 Scope* Parser::NewScope(Scope* parent, Scope::Type type, bool inside_with) {
708 public:
709 AstBuildingParser(Handle<Script> script, bool allow_natives_syntax,
710 v8::Extension* extension, ScriptDataImpl* pre_data)
711 : Parser(script,
712 allow_natives_syntax,
713 extension,
714 PARSE,
715 factory(),
716 log(),
717 pre_data),
718 factory_(pre_data ? pre_data->symbol_count() : 0) { }
719 virtual void ReportMessageAt(Scanner::Location loc, const char* message,
720 Vector<const char*> args);
721 virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode,
722 FunctionLiteral* fun, bool resolve, bool* ok);
723 AstBuildingParserFactory* factory() { return &factory_; }
724 ParserLog* log() { return &log_; }
725
726 private:
727 ParserLog log_;
728 AstBuildingParserFactory factory_;
729 };
730
731
732 class PreParser : public Parser {
733 public:
734 PreParser(Handle<Script> script, bool allow_natives_syntax,
735 v8::Extension* extension, ParserLog* recorder)
736 : Parser(script, allow_natives_syntax, extension, PREPARSE,
737 factory(), recorder, NULL),
738 factory_(true) { }
739 virtual void ReportMessageAt(Scanner::Location loc, const char* message,
740 Vector<const char*> args);
741 virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode,
742 FunctionLiteral* fun, bool resolve, bool* ok);
743 ParserFactory* factory() { return &factory_; }
744 virtual PartialParserRecorder* recorder() = 0;
745
746 private:
747 ParserFactory factory_;
748 };
749
750
751 class CompletePreParser : public PreParser {
752 public:
753 CompletePreParser(Handle<Script> script, bool allow_natives_syntax,
754 v8::Extension* extension)
755 : PreParser(script, allow_natives_syntax, extension, &recorder_),
756 recorder_() { }
757 virtual PartialParserRecorder* recorder() { return &recorder_; }
758 private:
759 CompleteParserRecorder recorder_;
760 };
761
762
763 class PartialPreParser : public PreParser {
764 public:
765 PartialPreParser(Handle<Script> script, bool allow_natives_syntax,
766 v8::Extension* extension)
767 : PreParser(script, allow_natives_syntax, extension, &recorder_),
768 recorder_() { }
769 virtual PartialParserRecorder* recorder() { return &recorder_; }
770 private:
771 PartialParserRecorder recorder_;
772 };
773
774
775 Scope* AstBuildingParserFactory::NewScope(Scope* parent, Scope::Type type,
776 bool inside_with) {
777 Scope* result = new Scope(parent, type); 598 Scope* result = new Scope(parent, type);
778 result->Initialize(inside_with); 599 result->Initialize(inside_with);
779 return result; 600 return result;
780 } 601 }
781 602
782
783 Statement* AstBuildingParserFactory::EmptyStatement() {
784 // Use a statically allocated empty statement singleton to avoid
785 // allocating lots and lots of empty statements.
786 static v8::internal::EmptyStatement empty;
787 return &empty;
788 }
789
790
791 Scope* ParserFactory::NewScope(Scope* parent, Scope::Type type,
792 bool inside_with) {
793 ASSERT(parent != NULL);
794 parent->type_ = type;
795 // Initialize function is hijacked by DummyScope to increment scope depth.
796 parent->Initialize(inside_with);
797 return parent;
798 }
799
800
801 VariableProxy* PreParser::Declare(Handle<String> name, Variable::Mode mode,
802 FunctionLiteral* fun, bool resolve,
803 bool* ok) {
804 return NULL;
805 }
806
807
808
809 // ---------------------------------------------------------------------------- 603 // ----------------------------------------------------------------------------
810 // Target is a support class to facilitate manipulation of the 604 // Target is a support class to facilitate manipulation of the
811 // Parser's target_stack_ (the stack of potential 'break' and 605 // Parser's target_stack_ (the stack of potential 'break' and
812 // 'continue' statement targets). Upon construction, a new target is 606 // 'continue' statement targets). Upon construction, a new target is
813 // added; it is removed upon destruction. 607 // added; it is removed upon destruction.
814 608
815 class Target BASE_EMBEDDED { 609 class Target BASE_EMBEDDED {
816 public: 610 public:
817 Target(Target** variable, AstNode* node) 611 Target(Target** variable, AstNode* node)
818 : variable_(variable), node_(node), previous_(*variable) { 612 : variable_(variable), node_(node), previous_(*variable) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 ((void)0 695 ((void)0
902 #define DUMMY ) // to make indentation work 696 #define DUMMY ) // to make indentation work
903 #undef DUMMY 697 #undef DUMMY
904 698
905 // ---------------------------------------------------------------------------- 699 // ----------------------------------------------------------------------------
906 // Implementation of Parser 700 // Implementation of Parser
907 701
908 Parser::Parser(Handle<Script> script, 702 Parser::Parser(Handle<Script> script,
909 bool allow_natives_syntax, 703 bool allow_natives_syntax,
910 v8::Extension* extension, 704 v8::Extension* extension,
911 ParserMode is_pre_parsing,
912 ParserFactory* factory,
913 ParserLog* log,
914 ScriptDataImpl* pre_data) 705 ScriptDataImpl* pre_data)
915 : script_(script), 706 : symbol_cache_(pre_data ? pre_data->symbol_count() : 0),
707 script_(script),
916 scanner_(), 708 scanner_(),
917 top_scope_(NULL), 709 top_scope_(NULL),
918 with_nesting_level_(0), 710 with_nesting_level_(0),
919 temp_scope_(NULL), 711 temp_scope_(NULL),
920 target_stack_(NULL), 712 target_stack_(NULL),
921 allow_natives_syntax_(allow_natives_syntax), 713 allow_natives_syntax_(allow_natives_syntax),
922 extension_(extension), 714 extension_(extension),
923 factory_(factory),
924 log_(log),
925 is_pre_parsing_(is_pre_parsing == PREPARSE),
926 pre_data_(pre_data), 715 pre_data_(pre_data),
927 fni_(NULL) { 716 fni_(NULL) {
928 } 717 }
929 718
930 719
931 FunctionLiteral* Parser::ParseProgram(Handle<String> source, 720 FunctionLiteral* Parser::ParseProgram(Handle<String> source,
932 bool in_global_context) { 721 bool in_global_context) {
933 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); 722 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
934 723
935 HistogramTimerScope timer(&Counters::parse); 724 HistogramTimerScope timer(&Counters::parse);
936 Counters::total_parse_size.Increment(source->length()); 725 Counters::total_parse_size.Increment(source->length());
937 fni_ = new FuncNameInferrer(); 726 fni_ = new FuncNameInferrer();
938 727
939 // Initialize parser state. 728 // Initialize parser state.
940 source->TryFlatten(); 729 source->TryFlatten();
941 scanner_.Initialize(source, JAVASCRIPT); 730 scanner_.Initialize(source, JAVASCRIPT);
942 ASSERT(target_stack_ == NULL); 731 ASSERT(target_stack_ == NULL);
943 if (pre_data_ != NULL) pre_data_->Initialize(); 732 if (pre_data_ != NULL) pre_data_->Initialize();
944 733
945 // Compute the parsing mode. 734 // Compute the parsing mode.
946 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; 735 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
947 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 736 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
948 737
949 Scope::Type type = 738 Scope::Type type =
950 in_global_context 739 in_global_context
951 ? Scope::GLOBAL_SCOPE 740 ? Scope::GLOBAL_SCOPE
952 : Scope::EVAL_SCOPE; 741 : Scope::EVAL_SCOPE;
953 Handle<String> no_name = factory()->EmptySymbol(); 742 Handle<String> no_name = Factory::empty_symbol();
954 743
955 FunctionLiteral* result = NULL; 744 FunctionLiteral* result = NULL;
956 { Scope* scope = factory()->NewScope(top_scope_, type, inside_with()); 745 { Scope* scope = NewScope(top_scope_, type, inside_with());
957 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 746 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
958 scope); 747 scope);
959 TemporaryScope temp_scope(&this->temp_scope_); 748 TemporaryScope temp_scope(&this->temp_scope_);
960 ZoneListWrapper<Statement> body(16); 749 ZoneList<Statement*>* body = new ZoneList<Statement*>(16);
961 bool ok = true; 750 bool ok = true;
962 ParseSourceElements(&body, Token::EOS, &ok); 751 ParseSourceElements(body, Token::EOS, &ok);
963 if (ok) { 752 if (ok) {
964 result = NEW(FunctionLiteral( 753 result = new FunctionLiteral(
965 no_name, 754 no_name,
966 top_scope_, 755 top_scope_,
967 body.elements(), 756 body,
968 temp_scope.materialized_literal_count(), 757 temp_scope.materialized_literal_count(),
969 temp_scope.expected_property_count(), 758 temp_scope.expected_property_count(),
970 temp_scope.only_simple_this_property_assignments(), 759 temp_scope.only_simple_this_property_assignments(),
971 temp_scope.this_property_assignments(), 760 temp_scope.this_property_assignments(),
972 0, 761 0,
973 0, 762 0,
974 source->length(), 763 source->length(),
975 false, 764 false,
976 temp_scope.ContainsLoops())); 765 temp_scope.ContainsLoops());
977 } else if (scanner().stack_overflow()) { 766 } else if (scanner().stack_overflow()) {
978 Top::StackOverflow(); 767 Top::StackOverflow();
979 } 768 }
980 } 769 }
981 770
982 // Make sure the target stack is empty. 771 // Make sure the target stack is empty.
983 ASSERT(target_stack_ == NULL); 772 ASSERT(target_stack_ == NULL);
984 773
985 // If there was a syntax error we have to get rid of the AST 774 // If there was a syntax error we have to get rid of the AST
986 // and it is not safe to do so before the scope has been deleted. 775 // and it is not safe to do so before the scope has been deleted.
(...skipping 17 matching lines...) Expand all
1004 scanner_.Initialize(source, info->start_position(), info->end_position(), 793 scanner_.Initialize(source, info->start_position(), info->end_position(),
1005 JAVASCRIPT); 794 JAVASCRIPT);
1006 ASSERT(target_stack_ == NULL); 795 ASSERT(target_stack_ == NULL);
1007 mode_ = PARSE_EAGERLY; 796 mode_ = PARSE_EAGERLY;
1008 797
1009 // Place holder for the result. 798 // Place holder for the result.
1010 FunctionLiteral* result = NULL; 799 FunctionLiteral* result = NULL;
1011 800
1012 { 801 {
1013 // Parse the function literal. 802 // Parse the function literal.
1014 Handle<String> no_name = factory()->EmptySymbol(); 803 Handle<String> no_name = Factory::empty_symbol();
1015 Scope* scope = 804 Scope* scope =
1016 factory()->NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 805 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
1017 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 806 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
1018 scope); 807 scope);
1019 TemporaryScope temp_scope(&this->temp_scope_); 808 TemporaryScope temp_scope(&this->temp_scope_);
1020 809
1021 FunctionLiteralType type = 810 FunctionLiteralType type =
1022 info->is_expression() ? EXPRESSION : DECLARATION; 811 info->is_expression() ? EXPRESSION : DECLARATION;
1023 bool ok = true; 812 bool ok = true;
1024 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); 813 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok);
1025 // Make sure the results agree. 814 // Make sure the results agree.
1026 ASSERT(ok == (result != NULL)); 815 ASSERT(ok == (result != NULL));
1027 // The only errors should be stack overflows. 816 // The only errors should be stack overflows.
1028 ASSERT(ok || scanner_.stack_overflow()); 817 ASSERT(ok || scanner_.stack_overflow());
1029 } 818 }
1030 819
1031 // Make sure the target stack is empty. 820 // Make sure the target stack is empty.
1032 ASSERT(target_stack_ == NULL); 821 ASSERT(target_stack_ == NULL);
1033 822
1034 // If there was a stack overflow we have to get rid of AST and it is 823 // If there was a stack overflow we have to get rid of AST and it is
1035 // not safe to do before scope has been deleted. 824 // not safe to do before scope has been deleted.
1036 if (result == NULL) { 825 if (result == NULL) {
1037 Top::StackOverflow(); 826 Top::StackOverflow();
1038 zone_scope.DeleteOnExit(); 827 zone_scope.DeleteOnExit();
1039 } 828 }
1040 return result; 829 return result;
1041 } 830 }
1042 831
1043 832
833 Handle<String> Parser::GetSymbol(bool* ok) {
834 int symbol_id = -1;
835 if (pre_data() != NULL) {
836 symbol_id = pre_data()->GetSymbolIdentifier();
837 }
838 return LookupSymbol(symbol_id, scanner_.literal());
839 }
840
841
1044 void Parser::ReportMessage(const char* type, Vector<const char*> args) { 842 void Parser::ReportMessage(const char* type, Vector<const char*> args) {
1045 Scanner::Location source_location = scanner_.location(); 843 Scanner::Location source_location = scanner_.location();
1046 ReportMessageAt(source_location, type, args); 844 ReportMessageAt(source_location, type, args);
1047 } 845 }
1048 846
1049 847
1050 Handle<String> Parser::GetSymbol(bool* ok) { 848 void Parser::ReportMessageAt(Scanner::Location source_location,
1051 if (is_pre_parsing_) { 849 const char* type,
1052 log()->LogSymbol(scanner_.location().beg_pos, scanner_.literal()); 850 Vector<const char*> args) {
1053 return Handle<String>::null();
1054 }
1055 int symbol_id = -1;
1056 if (pre_data() != NULL) {
1057 symbol_id = pre_data()->GetSymbolIdentifier();
1058 }
1059 return factory()->LookupSymbol(symbol_id, scanner_.literal());
1060 }
1061
1062
1063 void AstBuildingParser::ReportMessageAt(Scanner::Location source_location,
1064 const char* type,
1065 Vector<const char*> args) {
1066 MessageLocation location(script_, 851 MessageLocation location(script_,
1067 source_location.beg_pos, source_location.end_pos); 852 source_location.beg_pos, source_location.end_pos);
1068 Handle<JSArray> array = Factory::NewJSArray(args.length()); 853 Handle<JSArray> array = Factory::NewJSArray(args.length());
1069 for (int i = 0; i < args.length(); i++) { 854 for (int i = 0; i < args.length(); i++) {
1070 SetElement(array, i, Factory::NewStringFromUtf8(CStrVector(args[i]))); 855 SetElement(array, i, Factory::NewStringFromUtf8(CStrVector(args[i])));
1071 } 856 }
1072 Handle<Object> result = Factory::NewSyntaxError(type, array); 857 Handle<Object> result = Factory::NewSyntaxError(type, array);
1073 Top::Throw(*result, &location); 858 Top::Throw(*result, &location);
1074 } 859 }
1075 860
1076 861
1077 void PreParser::ReportMessageAt(Scanner::Location source_location,
1078 const char* type,
1079 Vector<const char*> args) {
1080 recorder()->LogMessage(source_location, type, args);
1081 }
1082
1083
1084 // Base class containing common code for the different finder classes used by 862 // Base class containing common code for the different finder classes used by
1085 // the parser. 863 // the parser.
1086 class ParserFinder { 864 class ParserFinder {
1087 protected: 865 protected:
1088 ParserFinder() {} 866 ParserFinder() {}
1089 static Assignment* AsAssignment(Statement* stat) { 867 static Assignment* AsAssignment(Statement* stat) {
1090 if (stat == NULL) return NULL; 868 if (stat == NULL) return NULL;
1091 ExpressionStatement* exp_stat = stat->AsExpressionStatement(); 869 ExpressionStatement* exp_stat = stat->AsExpressionStatement();
1092 if (exp_stat == NULL) return NULL; 870 if (exp_stat == NULL) return NULL;
1093 return exp_stat->expression()->AsAssignment(); 871 return exp_stat->expression()->AsAssignment();
(...skipping 21 matching lines...) Expand all
1115 EndBlock(); 893 EndBlock();
1116 } 894 }
1117 } 895 }
1118 if (!InBlock() && (assignment != NULL) && 896 if (!InBlock() && (assignment != NULL) &&
1119 (assignment->op() == Token::ASSIGN)) { 897 (assignment->op() == Token::ASSIGN)) {
1120 StartBlock(assignment); 898 StartBlock(assignment);
1121 } 899 }
1122 } 900 }
1123 901
1124 private: 902 private:
903 // The minimum number of contiguous assignment that will
904 // be treated as an initialization block. Benchmarks show that
905 // the overhead exceeds the savings below this limit.
906 static const int kMinInitializationBlock = 3;
907
1125 // Returns true if the expressions appear to denote the same object. 908 // Returns true if the expressions appear to denote the same object.
1126 // In the context of initialization blocks, we only consider expressions 909 // In the context of initialization blocks, we only consider expressions
1127 // of the form 'expr.x' or expr["x"]. 910 // of the form 'expr.x' or expr["x"].
1128 static bool SameObject(Expression* e1, Expression* e2) { 911 static bool SameObject(Expression* e1, Expression* e2) {
1129 VariableProxy* v1 = e1->AsVariableProxy(); 912 VariableProxy* v1 = e1->AsVariableProxy();
1130 VariableProxy* v2 = e2->AsVariableProxy(); 913 VariableProxy* v2 = e2->AsVariableProxy();
1131 if (v1 != NULL && v2 != NULL) { 914 if (v1 != NULL && v2 != NULL) {
1132 return v1->name()->Equals(*v2->name()); 915 return v1->name()->Equals(*v2->name());
1133 } 916 }
1134 Property* p1 = e1->AsProperty(); 917 Property* p1 = e1->AsProperty();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 last_in_block_ = assignment; 950 last_in_block_ = assignment;
1168 block_size_ = 1; 951 block_size_ = 1;
1169 } 952 }
1170 953
1171 void UpdateBlock(Assignment* assignment) { 954 void UpdateBlock(Assignment* assignment) {
1172 last_in_block_ = assignment; 955 last_in_block_ = assignment;
1173 ++block_size_; 956 ++block_size_;
1174 } 957 }
1175 958
1176 void EndBlock() { 959 void EndBlock() {
1177 if (block_size_ >= Parser::kMinInitializationBlock) { 960 if (block_size_ >= kMinInitializationBlock) {
1178 first_in_block_->mark_block_start(); 961 first_in_block_->mark_block_start();
1179 last_in_block_->mark_block_end(); 962 last_in_block_->mark_block_end();
1180 } 963 }
1181 last_in_block_ = first_in_block_ = NULL; 964 last_in_block_ = first_in_block_ = NULL;
1182 block_size_ = 0; 965 block_size_ = 0;
1183 } 966 }
1184 967
1185 bool InBlock() { return first_in_block_ != NULL; } 968 bool InBlock() { return first_in_block_ != NULL; }
1186 969
1187 Assignment* first_in_block_; 970 Assignment* first_in_block_;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 } 1108 }
1326 } 1109 }
1327 1110
1328 bool only_simple_this_property_assignments_; 1111 bool only_simple_this_property_assignments_;
1329 ZoneStringList* names_; 1112 ZoneStringList* names_;
1330 ZoneList<int>* assigned_arguments_; 1113 ZoneList<int>* assigned_arguments_;
1331 ZoneObjectList* assigned_constants_; 1114 ZoneObjectList* assigned_constants_;
1332 }; 1115 };
1333 1116
1334 1117
1335 void* Parser::ParseSourceElements(ZoneListWrapper<Statement>* processor, 1118 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
1336 int end_token, 1119 int end_token,
1337 bool* ok) { 1120 bool* ok) {
1338 // SourceElements :: 1121 // SourceElements ::
1339 // (Statement)* <end_token> 1122 // (Statement)* <end_token>
1340 1123
1341 // Allocate a target stack to use for this set of source 1124 // Allocate a target stack to use for this set of source
1342 // elements. This way, all scripts and functions get their own 1125 // elements. This way, all scripts and functions get their own
1343 // target stack thus avoiding illegal breaks and continues across 1126 // target stack thus avoiding illegal breaks and continues across
1344 // functions. 1127 // functions.
1345 TargetScope scope(&this->target_stack_); 1128 TargetScope scope(&this->target_stack_);
(...skipping 11 matching lines...) Expand all
1357 block_finder.Update(stat); 1140 block_finder.Update(stat);
1358 } 1141 }
1359 // Find and mark all assignments to named properties in this (this.x =) 1142 // Find and mark all assignments to named properties in this (this.x =)
1360 if (top_scope_->is_function_scope()) { 1143 if (top_scope_->is_function_scope()) {
1361 this_property_assignment_finder.Update(top_scope_, stat); 1144 this_property_assignment_finder.Update(top_scope_, stat);
1362 } 1145 }
1363 processor->Add(stat); 1146 processor->Add(stat);
1364 } 1147 }
1365 1148
1366 // Propagate the collected information on this property assignments. 1149 // Propagate the collected information on this property assignments.
1367 if (!is_pre_parsing_ && top_scope_->is_function_scope()) { 1150 if (top_scope_->is_function_scope()) {
1368 bool only_simple_this_property_assignments = 1151 bool only_simple_this_property_assignments =
1369 this_property_assignment_finder.only_simple_this_property_assignments() 1152 this_property_assignment_finder.only_simple_this_property_assignments()
1370 && top_scope_->declarations()->length() == 0; 1153 && top_scope_->declarations()->length() == 0;
1371 if (only_simple_this_property_assignments) { 1154 if (only_simple_this_property_assignments) {
1372 temp_scope_->SetThisPropertyAssignmentInfo( 1155 temp_scope_->SetThisPropertyAssignmentInfo(
1373 only_simple_this_property_assignments, 1156 only_simple_this_property_assignments,
1374 this_property_assignment_finder.GetThisPropertyAssignments()); 1157 this_property_assignment_finder.GetThisPropertyAssignments());
1375 } 1158 }
1376 } 1159 }
1377 return 0; 1160 return 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 case Token::LBRACE: 1193 case Token::LBRACE:
1411 return ParseBlock(labels, ok); 1194 return ParseBlock(labels, ok);
1412 1195
1413 case Token::CONST: // fall through 1196 case Token::CONST: // fall through
1414 case Token::VAR: 1197 case Token::VAR:
1415 stmt = ParseVariableStatement(ok); 1198 stmt = ParseVariableStatement(ok);
1416 break; 1199 break;
1417 1200
1418 case Token::SEMICOLON: 1201 case Token::SEMICOLON:
1419 Next(); 1202 Next();
1420 return factory()->EmptyStatement(); 1203 return EmptyStatement();
1421 1204
1422 case Token::IF: 1205 case Token::IF:
1423 stmt = ParseIfStatement(labels, ok); 1206 stmt = ParseIfStatement(labels, ok);
1424 break; 1207 break;
1425 1208
1426 case Token::DO: 1209 case Token::DO:
1427 stmt = ParseDoWhileStatement(labels, ok); 1210 stmt = ParseDoWhileStatement(labels, ok);
1428 break; 1211 break;
1429 1212
1430 case Token::WHILE: 1213 case Token::WHILE:
(...skipping 27 matching lines...) Expand all
1458 case Token::THROW: 1241 case Token::THROW:
1459 stmt = ParseThrowStatement(ok); 1242 stmt = ParseThrowStatement(ok);
1460 break; 1243 break;
1461 1244
1462 case Token::TRY: { 1245 case Token::TRY: {
1463 // NOTE: It is somewhat complicated to have labels on 1246 // NOTE: It is somewhat complicated to have labels on
1464 // try-statements. When breaking out of a try-finally statement, 1247 // try-statements. When breaking out of a try-finally statement,
1465 // one must take great care not to treat it as a 1248 // one must take great care not to treat it as a
1466 // fall-through. It is much easier just to wrap the entire 1249 // fall-through. It is much easier just to wrap the entire
1467 // try-statement in a statement block and put the labels there 1250 // try-statement in a statement block and put the labels there
1468 Block* result = NEW(Block(labels, 1, false)); 1251 Block* result = new Block(labels, 1, false);
1469 Target target(&this->target_stack_, result); 1252 Target target(&this->target_stack_, result);
1470 TryStatement* statement = ParseTryStatement(CHECK_OK); 1253 TryStatement* statement = ParseTryStatement(CHECK_OK);
1471 if (statement) { 1254 if (statement) {
1472 statement->set_statement_pos(statement_pos); 1255 statement->set_statement_pos(statement_pos);
1473 } 1256 }
1474 if (result) result->AddStatement(statement); 1257 if (result) result->AddStatement(statement);
1475 return result; 1258 return result;
1476 } 1259 }
1477 1260
1478 case Token::FUNCTION: 1261 case Token::FUNCTION:
1479 return ParseFunctionDeclaration(ok); 1262 return ParseFunctionDeclaration(ok);
1480 1263
1481 case Token::NATIVE: 1264 case Token::NATIVE:
1482 return ParseNativeDeclaration(ok); 1265 return ParseNativeDeclaration(ok);
1483 1266
1484 case Token::DEBUGGER: 1267 case Token::DEBUGGER:
1485 stmt = ParseDebuggerStatement(ok); 1268 stmt = ParseDebuggerStatement(ok);
1486 break; 1269 break;
1487 1270
1488 default: 1271 default:
1489 stmt = ParseExpressionOrLabelledStatement(labels, ok); 1272 stmt = ParseExpressionOrLabelledStatement(labels, ok);
1490 } 1273 }
1491 1274
1492 // Store the source position of the statement 1275 // Store the source position of the statement
1493 if (stmt != NULL) stmt->set_statement_pos(statement_pos); 1276 if (stmt != NULL) stmt->set_statement_pos(statement_pos);
1494 return stmt; 1277 return stmt;
1495 } 1278 }
1496 1279
1497 1280
1498 VariableProxy* AstBuildingParser::Declare(Handle<String> name, 1281 VariableProxy* Parser::Declare(Handle<String> name,
1499 Variable::Mode mode, 1282 Variable::Mode mode,
1500 FunctionLiteral* fun, 1283 FunctionLiteral* fun,
1501 bool resolve, 1284 bool resolve,
1502 bool* ok) { 1285 bool* ok) {
1503 Variable* var = NULL; 1286 Variable* var = NULL;
1504 // If we are inside a function, a declaration of a variable 1287 // If we are inside a function, a declaration of a variable
1505 // is a truly local variable, and the scope of the variable 1288 // is a truly local variable, and the scope of the variable
1506 // is always the function scope. 1289 // is always the function scope.
1507 1290
1508 // If a function scope exists, then we can statically declare this 1291 // If a function scope exists, then we can statically declare this
1509 // variable and also set its mode. In any case, a Declaration node 1292 // variable and also set its mode. In any case, a Declaration node
1510 // will be added to the scope so that the declaration can be added 1293 // will be added to the scope so that the declaration can be added
1511 // to the corresponding activation frame at runtime if necessary. 1294 // to the corresponding activation frame at runtime if necessary.
1512 // For instance declarations inside an eval scope need to be added 1295 // For instance declarations inside an eval scope need to be added
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 // parameters) if the proxy is needed or not. The proxy will be 1330 // parameters) if the proxy is needed or not. The proxy will be
1548 // bound during variable resolution time unless it was pre-bound 1331 // bound during variable resolution time unless it was pre-bound
1549 // below. 1332 // below.
1550 // 1333 //
1551 // WARNING: This will lead to multiple declaration nodes for the 1334 // WARNING: This will lead to multiple declaration nodes for the
1552 // same variable if it is declared several times. This is not a 1335 // same variable if it is declared several times. This is not a
1553 // semantic issue as long as we keep the source order, but it may be 1336 // semantic issue as long as we keep the source order, but it may be
1554 // a performance issue since it may lead to repeated 1337 // a performance issue since it may lead to repeated
1555 // Runtime::DeclareContextSlot() calls. 1338 // Runtime::DeclareContextSlot() calls.
1556 VariableProxy* proxy = top_scope_->NewUnresolved(name, inside_with()); 1339 VariableProxy* proxy = top_scope_->NewUnresolved(name, inside_with());
1557 top_scope_->AddDeclaration(NEW(Declaration(proxy, mode, fun))); 1340 top_scope_->AddDeclaration(new Declaration(proxy, mode, fun));
1558 1341
1559 // For global const variables we bind the proxy to a variable. 1342 // For global const variables we bind the proxy to a variable.
1560 if (mode == Variable::CONST && top_scope_->is_global_scope()) { 1343 if (mode == Variable::CONST && top_scope_->is_global_scope()) {
1561 ASSERT(resolve); // should be set by all callers 1344 ASSERT(resolve); // should be set by all callers
1562 Variable::Kind kind = Variable::NORMAL; 1345 Variable::Kind kind = Variable::NORMAL;
1563 var = NEW(Variable(top_scope_, name, Variable::CONST, true, kind)); 1346 var = new Variable(top_scope_, name, Variable::CONST, true, kind);
1564 } 1347 }
1565 1348
1566 // If requested and we have a local variable, bind the proxy to the variable 1349 // If requested and we have a local variable, bind the proxy to the variable
1567 // at parse-time. This is used for functions (and consts) declared inside 1350 // at parse-time. This is used for functions (and consts) declared inside
1568 // statements: the corresponding function (or const) variable must be in the 1351 // statements: the corresponding function (or const) variable must be in the
1569 // function scope and not a statement-local scope, e.g. as provided with a 1352 // function scope and not a statement-local scope, e.g. as provided with a
1570 // 'with' statement: 1353 // 'with' statement:
1571 // 1354 //
1572 // with (obj) { 1355 // with (obj) {
1573 // function f() {} 1356 // function f() {}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 while (!done) { 1395 while (!done) {
1613 ParseIdentifier(CHECK_OK); 1396 ParseIdentifier(CHECK_OK);
1614 done = (peek() == Token::RPAREN); 1397 done = (peek() == Token::RPAREN);
1615 if (!done) { 1398 if (!done) {
1616 Expect(Token::COMMA, CHECK_OK); 1399 Expect(Token::COMMA, CHECK_OK);
1617 } 1400 }
1618 } 1401 }
1619 Expect(Token::RPAREN, CHECK_OK); 1402 Expect(Token::RPAREN, CHECK_OK);
1620 Expect(Token::SEMICOLON, CHECK_OK); 1403 Expect(Token::SEMICOLON, CHECK_OK);
1621 1404
1622 if (is_pre_parsing_) return NULL;
1623
1624 // Make sure that the function containing the native declaration 1405 // Make sure that the function containing the native declaration
1625 // isn't lazily compiled. The extension structures are only 1406 // isn't lazily compiled. The extension structures are only
1626 // accessible while parsing the first time not when reparsing 1407 // accessible while parsing the first time not when reparsing
1627 // because of lazy compilation. 1408 // because of lazy compilation.
1628 top_scope_->ForceEagerCompilation(); 1409 top_scope_->ForceEagerCompilation();
1629 1410
1630 // Compute the function template for the native function. 1411 // Compute the function template for the native function.
1631 v8::Handle<v8::FunctionTemplate> fun_template = 1412 v8::Handle<v8::FunctionTemplate> fun_template =
1632 extension_->GetNativeFunction(v8::Utils::ToLocal(name)); 1413 extension_->GetNativeFunction(v8::Utils::ToLocal(name));
1633 ASSERT(!fun_template.IsEmpty()); 1414 ASSERT(!fun_template.IsEmpty());
1634 1415
1635 // Instantiate the function and create a shared function info from it. 1416 // Instantiate the function and create a shared function info from it.
1636 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction()); 1417 Handle<JSFunction> fun = Utils::OpenHandle(*fun_template->GetFunction());
1637 const int literals = fun->NumberOfLiterals(); 1418 const int literals = fun->NumberOfLiterals();
1638 Handle<Code> code = Handle<Code>(fun->shared()->code()); 1419 Handle<Code> code = Handle<Code>(fun->shared()->code());
1639 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); 1420 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
1640 Handle<SharedFunctionInfo> shared = 1421 Handle<SharedFunctionInfo> shared =
1641 Factory::NewSharedFunctionInfo(name, literals, code, 1422 Factory::NewSharedFunctionInfo(name, literals, code,
1642 Handle<SerializedScopeInfo>(fun->shared()->scope_info())); 1423 Handle<SerializedScopeInfo>(fun->shared()->scope_info()));
1643 shared->set_construct_stub(*construct_stub); 1424 shared->set_construct_stub(*construct_stub);
1644 1425
1645 // Copy the function data to the shared function info. 1426 // Copy the function data to the shared function info.
1646 shared->set_function_data(fun->shared()->function_data()); 1427 shared->set_function_data(fun->shared()->function_data());
1647 int parameters = fun->shared()->formal_parameter_count(); 1428 int parameters = fun->shared()->formal_parameter_count();
1648 shared->set_formal_parameter_count(parameters); 1429 shared->set_formal_parameter_count(parameters);
1649 1430
1650 // TODO(1240846): It's weird that native function declarations are 1431 // TODO(1240846): It's weird that native function declarations are
1651 // introduced dynamically when we meet their declarations, whereas 1432 // introduced dynamically when we meet their declarations, whereas
1652 // other functions are setup when entering the surrounding scope. 1433 // other functions are setup when entering the surrounding scope.
1653 SharedFunctionInfoLiteral* lit = NEW(SharedFunctionInfoLiteral(shared)); 1434 SharedFunctionInfoLiteral* lit = new SharedFunctionInfoLiteral(shared);
1654 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK); 1435 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK);
1655 return NEW(ExpressionStatement( 1436 return new ExpressionStatement(
1656 new Assignment(Token::INIT_VAR, var, lit, RelocInfo::kNoPosition))); 1437 new Assignment(Token::INIT_VAR, var, lit, RelocInfo::kNoPosition));
1657 } 1438 }
1658 1439
1659 1440
1660 Statement* Parser::ParseFunctionDeclaration(bool* ok) { 1441 Statement* Parser::ParseFunctionDeclaration(bool* ok) {
1661 // FunctionDeclaration :: 1442 // FunctionDeclaration ::
1662 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' 1443 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
1663 Expect(Token::FUNCTION, CHECK_OK); 1444 Expect(Token::FUNCTION, CHECK_OK);
1664 int function_token_position = scanner().location().beg_pos; 1445 int function_token_position = scanner().location().beg_pos;
1665 Handle<String> name = ParseIdentifier(CHECK_OK); 1446 Handle<String> name = ParseIdentifier(CHECK_OK);
1666 FunctionLiteral* fun = ParseFunctionLiteral(name, 1447 FunctionLiteral* fun = ParseFunctionLiteral(name,
1667 function_token_position, 1448 function_token_position,
1668 DECLARATION, 1449 DECLARATION,
1669 CHECK_OK); 1450 CHECK_OK);
1670 // Even if we're not at the top-level of the global or a function 1451 // Even if we're not at the top-level of the global or a function
1671 // scope, we treat is as such and introduce the function with it's 1452 // scope, we treat is as such and introduce the function with it's
1672 // initial value upon entering the corresponding scope. 1453 // initial value upon entering the corresponding scope.
1673 Declare(name, Variable::VAR, fun, true, CHECK_OK); 1454 Declare(name, Variable::VAR, fun, true, CHECK_OK);
1674 return factory()->EmptyStatement(); 1455 return EmptyStatement();
1675 } 1456 }
1676 1457
1677 1458
1678 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1459 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
1679 // Block :: 1460 // Block ::
1680 // '{' Statement* '}' 1461 // '{' Statement* '}'
1681 1462
1682 // Note that a Block does not introduce a new execution scope! 1463 // Note that a Block does not introduce a new execution scope!
1683 // (ECMA-262, 3rd, 12.2) 1464 // (ECMA-262, 3rd, 12.2)
1684 // 1465 //
1685 // Construct block expecting 16 statements. 1466 // Construct block expecting 16 statements.
1686 Block* result = NEW(Block(labels, 16, false)); 1467 Block* result = new Block(labels, 16, false);
1687 Target target(&this->target_stack_, result); 1468 Target target(&this->target_stack_, result);
1688 Expect(Token::LBRACE, CHECK_OK); 1469 Expect(Token::LBRACE, CHECK_OK);
1689 while (peek() != Token::RBRACE) { 1470 while (peek() != Token::RBRACE) {
1690 Statement* stat = ParseStatement(NULL, CHECK_OK); 1471 Statement* stat = ParseStatement(NULL, CHECK_OK);
1691 if (stat && !stat->IsEmpty()) result->AddStatement(stat); 1472 if (stat && !stat->IsEmpty()) result->AddStatement(stat);
1692 } 1473 }
1693 Expect(Token::RBRACE, CHECK_OK); 1474 Expect(Token::RBRACE, CHECK_OK);
1694 return result; 1475 return result;
1695 } 1476 }
1696 1477
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 // Scope declaration, and rewrite the source-level initialization into an 1516 // Scope declaration, and rewrite the source-level initialization into an
1736 // assignment statement. We use a block to collect multiple assignments. 1517 // assignment statement. We use a block to collect multiple assignments.
1737 // 1518 //
1738 // We mark the block as initializer block because we don't want the 1519 // We mark the block as initializer block because we don't want the
1739 // rewriter to add a '.result' assignment to such a block (to get compliant 1520 // rewriter to add a '.result' assignment to such a block (to get compliant
1740 // behavior for code such as print(eval('var x = 7')), and for cosmetic 1521 // behavior for code such as print(eval('var x = 7')), and for cosmetic
1741 // reasons when pretty-printing. Also, unless an assignment (initialization) 1522 // reasons when pretty-printing. Also, unless an assignment (initialization)
1742 // is inside an initializer block, it is ignored. 1523 // is inside an initializer block, it is ignored.
1743 // 1524 //
1744 // Create new block with one expected declaration. 1525 // Create new block with one expected declaration.
1745 Block* block = NEW(Block(NULL, 1, true)); 1526 Block* block = new Block(NULL, 1, true);
1746 VariableProxy* last_var = NULL; // the last variable declared 1527 VariableProxy* last_var = NULL; // the last variable declared
1747 int nvars = 0; // the number of variables declared 1528 int nvars = 0; // the number of variables declared
1748 do { 1529 do {
1749 if (fni_ != NULL) fni_->Enter(); 1530 if (fni_ != NULL) fni_->Enter();
1750 1531
1751 // Parse variable name. 1532 // Parse variable name.
1752 if (nvars > 0) Consume(Token::COMMA); 1533 if (nvars > 0) Consume(Token::COMMA);
1753 Handle<String> name = ParseIdentifier(CHECK_OK); 1534 Handle<String> name = ParseIdentifier(CHECK_OK);
1754 if (fni_ != NULL) fni_->PushVariableName(name); 1535 if (fni_ != NULL) fni_->PushVariableName(name);
1755 1536
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 // 1607 //
1827 // Executing the variable declaration statement will always 1608 // Executing the variable declaration statement will always
1828 // guarantee to give the global object a "local" variable; a 1609 // guarantee to give the global object a "local" variable; a
1829 // variable defined in the global object and not in any 1610 // variable defined in the global object and not in any
1830 // prototype. This way, global variable declarations can shadow 1611 // prototype. This way, global variable declarations can shadow
1831 // properties in the prototype chain, but only after the variable 1612 // properties in the prototype chain, but only after the variable
1832 // declaration statement has been executed. This is important in 1613 // declaration statement has been executed. This is important in
1833 // browsers where the global object (window) has lots of 1614 // browsers where the global object (window) has lots of
1834 // properties defined in prototype objects. 1615 // properties defined in prototype objects.
1835 1616
1836 if (!is_pre_parsing_ && top_scope_->is_global_scope()) { 1617 if (top_scope_->is_global_scope()) {
1837 // Compute the arguments for the runtime call. 1618 // Compute the arguments for the runtime call.
1838 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(2); 1619 ZoneList<Expression*>* arguments = new ZoneList<Expression*>(2);
1839 // Be careful not to assign a value to the global variable if 1620 // Be careful not to assign a value to the global variable if
1840 // we're in a with. The initialization value should not 1621 // we're in a with. The initialization value should not
1841 // necessarily be stored in the global object in that case, 1622 // necessarily be stored in the global object in that case,
1842 // which is why we need to generate a separate assignment node. 1623 // which is why we need to generate a separate assignment node.
1843 arguments->Add(NEW(Literal(name))); // we have at least 1 parameter 1624 arguments->Add(new Literal(name)); // we have at least 1 parameter
1844 if (is_const || (value != NULL && !inside_with())) { 1625 if (is_const || (value != NULL && !inside_with())) {
1845 arguments->Add(value); 1626 arguments->Add(value);
1846 value = NULL; // zap the value to avoid the unnecessary assignment 1627 value = NULL; // zap the value to avoid the unnecessary assignment
1847 } 1628 }
1848 // Construct the call to Runtime::DeclareGlobal{Variable,Const}Locally 1629 // Construct the call to Runtime::DeclareGlobal{Variable,Const}Locally
1849 // and add it to the initialization statement block. Note that 1630 // and add it to the initialization statement block. Note that
1850 // this function does different things depending on if we have 1631 // this function does different things depending on if we have
1851 // 1 or 2 parameters. 1632 // 1 or 2 parameters.
1852 CallRuntime* initialize; 1633 CallRuntime* initialize;
1853 if (is_const) { 1634 if (is_const) {
1854 initialize = 1635 initialize =
1855 NEW(CallRuntime( 1636 new CallRuntime(
1856 Factory::InitializeConstGlobal_symbol(), 1637 Factory::InitializeConstGlobal_symbol(),
1857 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), 1638 Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
1858 arguments)); 1639 arguments);
1859 } else { 1640 } else {
1860 initialize = 1641 initialize =
1861 NEW(CallRuntime( 1642 new CallRuntime(
1862 Factory::InitializeVarGlobal_symbol(), 1643 Factory::InitializeVarGlobal_symbol(),
1863 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 1644 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
1864 arguments)); 1645 arguments);
1865 } 1646 }
1866 block->AddStatement(NEW(ExpressionStatement(initialize))); 1647 block->AddStatement(new ExpressionStatement(initialize));
1867 } 1648 }
1868 1649
1869 // Add an assignment node to the initialization statement block if 1650 // Add an assignment node to the initialization statement block if
1870 // we still have a pending initialization value. We must distinguish 1651 // we still have a pending initialization value. We must distinguish
1871 // between variables and constants: Variable initializations are simply 1652 // between variables and constants: Variable initializations are simply
1872 // assignments (with all the consequences if they are inside a 'with' 1653 // assignments (with all the consequences if they are inside a 'with'
1873 // statement - they may change a 'with' object property). Constant 1654 // statement - they may change a 'with' object property). Constant
1874 // initializations always assign to the declared constant which is 1655 // initializations always assign to the declared constant which is
1875 // always at the function scope level. This is only relevant for 1656 // always at the function scope level. This is only relevant for
1876 // dynamically looked-up variables and constants (the start context 1657 // dynamically looked-up variables and constants (the start context
1877 // for constant lookups is always the function context, while it is 1658 // for constant lookups is always the function context, while it is
1878 // the top context for variables). Sigh... 1659 // the top context for variables). Sigh...
1879 if (value != NULL) { 1660 if (value != NULL) {
1880 Token::Value op = (is_const ? Token::INIT_CONST : Token::INIT_VAR); 1661 Token::Value op = (is_const ? Token::INIT_CONST : Token::INIT_VAR);
1881 Assignment* assignment = NEW(Assignment(op, last_var, value, position)); 1662 Assignment* assignment = new Assignment(op, last_var, value, position);
1882 if (block) block->AddStatement(NEW(ExpressionStatement(assignment))); 1663 if (block) block->AddStatement(new ExpressionStatement(assignment));
1883 } 1664 }
1884 1665
1885 if (fni_ != NULL) fni_->Leave(); 1666 if (fni_ != NULL) fni_->Leave();
1886 } while (peek() == Token::COMMA); 1667 } while (peek() == Token::COMMA);
1887 1668
1888 if (!is_const && nvars == 1) { 1669 if (!is_const && nvars == 1) {
1889 // We have a single, non-const variable. 1670 // We have a single, non-const variable.
1890 if (is_pre_parsing_) { 1671 ASSERT(last_var != NULL);
1891 // If we're preparsing then we need to set the var to something 1672 *var = last_var;
1892 // in order for for-in loops to parse correctly.
1893 *var = ValidLeftHandSideSentinel::instance();
1894 } else {
1895 ASSERT(last_var != NULL);
1896 *var = last_var;
1897 }
1898 } 1673 }
1899 1674
1900 return block; 1675 return block;
1901 } 1676 }
1902 1677
1903 1678
1904 static bool ContainsLabel(ZoneStringList* labels, Handle<String> label) { 1679 static bool ContainsLabel(ZoneStringList* labels, Handle<String> label) {
1905 ASSERT(!label.is_null()); 1680 ASSERT(!label.is_null());
1906 if (labels != NULL) 1681 if (labels != NULL)
1907 for (int i = labels->length(); i-- > 0; ) 1682 for (int i = labels->length(); i-- > 0; )
(...skipping 14 matching lines...) Expand all
1922 if (peek() == Token::COLON && expr && 1697 if (peek() == Token::COLON && expr &&
1923 expr->AsVariableProxy() != NULL && 1698 expr->AsVariableProxy() != NULL &&
1924 !expr->AsVariableProxy()->is_this()) { 1699 !expr->AsVariableProxy()->is_this()) {
1925 VariableProxy* var = expr->AsVariableProxy(); 1700 VariableProxy* var = expr->AsVariableProxy();
1926 Handle<String> label = var->name(); 1701 Handle<String> label = var->name();
1927 // TODO(1240780): We don't check for redeclaration of labels 1702 // TODO(1240780): We don't check for redeclaration of labels
1928 // during preparsing since keeping track of the set of active 1703 // during preparsing since keeping track of the set of active
1929 // labels requires nontrivial changes to the way scopes are 1704 // labels requires nontrivial changes to the way scopes are
1930 // structured. However, these are probably changes we want to 1705 // structured. However, these are probably changes we want to
1931 // make later anyway so we should go back and fix this then. 1706 // make later anyway so we should go back and fix this then.
1932 if (!is_pre_parsing_) { 1707 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
1933 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 1708 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
1934 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS); 1709 const char* elms[2] = { "Label", *c_string };
1935 const char* elms[2] = { "Label", *c_string }; 1710 Vector<const char*> args(elms, 2);
1936 Vector<const char*> args(elms, 2); 1711 ReportMessage("redeclaration", args);
1937 ReportMessage("redeclaration", args); 1712 *ok = false;
1938 *ok = false; 1713 return NULL;
1939 return NULL;
1940 }
1941 if (labels == NULL) labels = new ZoneStringList(4);
1942 labels->Add(label);
1943 // Remove the "ghost" variable that turned out to be a label
1944 // from the top scope. This way, we don't try to resolve it
1945 // during the scope processing.
1946 top_scope_->RemoveUnresolved(var);
1947 } 1714 }
1715 if (labels == NULL) labels = new ZoneStringList(4);
1716 labels->Add(label);
1717 // Remove the "ghost" variable that turned out to be a label
1718 // from the top scope. This way, we don't try to resolve it
1719 // during the scope processing.
1720 top_scope_->RemoveUnresolved(var);
1948 Expect(Token::COLON, CHECK_OK); 1721 Expect(Token::COLON, CHECK_OK);
1949 return ParseStatement(labels, ok); 1722 return ParseStatement(labels, ok);
1950 } 1723 }
1951 1724
1952 // Parsed expression statement. 1725 // Parsed expression statement.
1953 ExpectSemicolon(CHECK_OK); 1726 ExpectSemicolon(CHECK_OK);
1954 return NEW(ExpressionStatement(expr)); 1727 return new ExpressionStatement(expr);
1955 } 1728 }
1956 1729
1957 1730
1958 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 1731 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
1959 // IfStatement :: 1732 // IfStatement ::
1960 // 'if' '(' Expression ')' Statement ('else' Statement)? 1733 // 'if' '(' Expression ')' Statement ('else' Statement)?
1961 1734
1962 Expect(Token::IF, CHECK_OK); 1735 Expect(Token::IF, CHECK_OK);
1963 Expect(Token::LPAREN, CHECK_OK); 1736 Expect(Token::LPAREN, CHECK_OK);
1964 Expression* condition = ParseExpression(true, CHECK_OK); 1737 Expression* condition = ParseExpression(true, CHECK_OK);
1965 Expect(Token::RPAREN, CHECK_OK); 1738 Expect(Token::RPAREN, CHECK_OK);
1966 Statement* then_statement = ParseStatement(labels, CHECK_OK); 1739 Statement* then_statement = ParseStatement(labels, CHECK_OK);
1967 Statement* else_statement = NULL; 1740 Statement* else_statement = NULL;
1968 if (peek() == Token::ELSE) { 1741 if (peek() == Token::ELSE) {
1969 Next(); 1742 Next();
1970 else_statement = ParseStatement(labels, CHECK_OK); 1743 else_statement = ParseStatement(labels, CHECK_OK);
1971 } else if (!is_pre_parsing_) { 1744 } else {
1972 else_statement = factory()->EmptyStatement(); 1745 else_statement = EmptyStatement();
1973 } 1746 }
1974 return NEW(IfStatement(condition, then_statement, else_statement)); 1747 return new IfStatement(condition, then_statement, else_statement);
1975 } 1748 }
1976 1749
1977 1750
1978 Statement* Parser::ParseContinueStatement(bool* ok) { 1751 Statement* Parser::ParseContinueStatement(bool* ok) {
1979 // ContinueStatement :: 1752 // ContinueStatement ::
1980 // 'continue' Identifier? ';' 1753 // 'continue' Identifier? ';'
1981 1754
1982 Expect(Token::CONTINUE, CHECK_OK); 1755 Expect(Token::CONTINUE, CHECK_OK);
1983 Handle<String> label = Handle<String>::null(); 1756 Handle<String> label = Handle<String>::null();
1984 Token::Value tok = peek(); 1757 Token::Value tok = peek();
1985 if (!scanner_.has_line_terminator_before_next() && 1758 if (!scanner_.has_line_terminator_before_next() &&
1986 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 1759 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
1987 label = ParseIdentifier(CHECK_OK); 1760 label = ParseIdentifier(CHECK_OK);
1988 } 1761 }
1989 IterationStatement* target = NULL; 1762 IterationStatement* target = NULL;
1990 if (!is_pre_parsing_) { 1763 target = LookupContinueTarget(label, CHECK_OK);
1991 target = LookupContinueTarget(label, CHECK_OK); 1764 if (target == NULL) {
1992 if (target == NULL) { 1765 // Illegal continue statement. To be consistent with KJS we delay
1993 // Illegal continue statement. To be consistent with KJS we delay 1766 // reporting of the syntax error until runtime.
1994 // reporting of the syntax error until runtime. 1767 Handle<String> error_type = Factory::illegal_continue_symbol();
1995 Handle<String> error_type = Factory::illegal_continue_symbol(); 1768 if (!label.is_null()) error_type = Factory::unknown_label_symbol();
1996 if (!label.is_null()) error_type = Factory::unknown_label_symbol(); 1769 Expression* throw_error = NewThrowSyntaxError(error_type, label);
1997 Expression* throw_error = NewThrowSyntaxError(error_type, label); 1770 return new ExpressionStatement(throw_error);
1998 return NEW(ExpressionStatement(throw_error));
1999 }
2000 } 1771 }
2001 ExpectSemicolon(CHECK_OK); 1772 ExpectSemicolon(CHECK_OK);
2002 return NEW(ContinueStatement(target)); 1773 return new ContinueStatement(target);
2003 } 1774 }
2004 1775
2005 1776
2006 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 1777 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
2007 // BreakStatement :: 1778 // BreakStatement ::
2008 // 'break' Identifier? ';' 1779 // 'break' Identifier? ';'
2009 1780
2010 Expect(Token::BREAK, CHECK_OK); 1781 Expect(Token::BREAK, CHECK_OK);
2011 Handle<String> label; 1782 Handle<String> label;
2012 Token::Value tok = peek(); 1783 Token::Value tok = peek();
2013 if (!scanner_.has_line_terminator_before_next() && 1784 if (!scanner_.has_line_terminator_before_next() &&
2014 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 1785 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2015 label = ParseIdentifier(CHECK_OK); 1786 label = ParseIdentifier(CHECK_OK);
2016 } 1787 }
2017 // Parse labeled break statements that target themselves into 1788 // Parse labeled break statements that target themselves into
2018 // empty statements, e.g. 'l1: l2: l3: break l2;' 1789 // empty statements, e.g. 'l1: l2: l3: break l2;'
2019 if (!label.is_null() && ContainsLabel(labels, label)) { 1790 if (!label.is_null() && ContainsLabel(labels, label)) {
2020 return factory()->EmptyStatement(); 1791 return EmptyStatement();
2021 } 1792 }
2022 BreakableStatement* target = NULL; 1793 BreakableStatement* target = NULL;
2023 if (!is_pre_parsing_) { 1794 target = LookupBreakTarget(label, CHECK_OK);
2024 target = LookupBreakTarget(label, CHECK_OK); 1795 if (target == NULL) {
2025 if (target == NULL) { 1796 // Illegal break statement. To be consistent with KJS we delay
2026 // Illegal break statement. To be consistent with KJS we delay 1797 // reporting of the syntax error until runtime.
2027 // reporting of the syntax error until runtime. 1798 Handle<String> error_type = Factory::illegal_break_symbol();
2028 Handle<String> error_type = Factory::illegal_break_symbol(); 1799 if (!label.is_null()) error_type = Factory::unknown_label_symbol();
2029 if (!label.is_null()) error_type = Factory::unknown_label_symbol(); 1800 Expression* throw_error = NewThrowSyntaxError(error_type, label);
2030 Expression* throw_error = NewThrowSyntaxError(error_type, label); 1801 return new ExpressionStatement(throw_error);
2031 return NEW(ExpressionStatement(throw_error));
2032 }
2033 } 1802 }
2034 ExpectSemicolon(CHECK_OK); 1803 ExpectSemicolon(CHECK_OK);
2035 return NEW(BreakStatement(target)); 1804 return new BreakStatement(target);
2036 } 1805 }
2037 1806
2038 1807
2039 Statement* Parser::ParseReturnStatement(bool* ok) { 1808 Statement* Parser::ParseReturnStatement(bool* ok) {
2040 // ReturnStatement :: 1809 // ReturnStatement ::
2041 // 'return' Expression? ';' 1810 // 'return' Expression? ';'
2042 1811
2043 // Consume the return token. It is necessary to do the before 1812 // Consume the return token. It is necessary to do the before
2044 // reporting any errors on it, because of the way errors are 1813 // reporting any errors on it, because of the way errors are
2045 // reported (underlining). 1814 // reported (underlining).
2046 Expect(Token::RETURN, CHECK_OK); 1815 Expect(Token::RETURN, CHECK_OK);
2047 1816
2048 // An ECMAScript program is considered syntactically incorrect if it 1817 // An ECMAScript program is considered syntactically incorrect if it
2049 // contains a return statement that is not within the body of a 1818 // contains a return statement that is not within the body of a
2050 // function. See ECMA-262, section 12.9, page 67. 1819 // function. See ECMA-262, section 12.9, page 67.
2051 // 1820 //
2052 // To be consistent with KJS we report the syntax error at runtime. 1821 // To be consistent with KJS we report the syntax error at runtime.
2053 if (!is_pre_parsing_ && !top_scope_->is_function_scope()) { 1822 if (!top_scope_->is_function_scope()) {
2054 Handle<String> type = Factory::illegal_return_symbol(); 1823 Handle<String> type = Factory::illegal_return_symbol();
2055 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); 1824 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null());
2056 return NEW(ExpressionStatement(throw_error)); 1825 return new ExpressionStatement(throw_error);
2057 } 1826 }
2058 1827
2059 Token::Value tok = peek(); 1828 Token::Value tok = peek();
2060 if (scanner_.has_line_terminator_before_next() || 1829 if (scanner_.has_line_terminator_before_next() ||
2061 tok == Token::SEMICOLON || 1830 tok == Token::SEMICOLON ||
2062 tok == Token::RBRACE || 1831 tok == Token::RBRACE ||
2063 tok == Token::EOS) { 1832 tok == Token::EOS) {
2064 ExpectSemicolon(CHECK_OK); 1833 ExpectSemicolon(CHECK_OK);
2065 return NEW(ReturnStatement(GetLiteralUndefined())); 1834 return new ReturnStatement(GetLiteralUndefined());
2066 } 1835 }
2067 1836
2068 Expression* expr = ParseExpression(true, CHECK_OK); 1837 Expression* expr = ParseExpression(true, CHECK_OK);
2069 ExpectSemicolon(CHECK_OK); 1838 ExpectSemicolon(CHECK_OK);
2070 return NEW(ReturnStatement(expr)); 1839 return new ReturnStatement(expr);
2071 } 1840 }
2072 1841
2073 1842
2074 Block* Parser::WithHelper(Expression* obj, 1843 Block* Parser::WithHelper(Expression* obj,
2075 ZoneStringList* labels, 1844 ZoneStringList* labels,
2076 bool is_catch_block, 1845 bool is_catch_block,
2077 bool* ok) { 1846 bool* ok) {
2078 // Parse the statement and collect escaping labels. 1847 // Parse the statement and collect escaping labels.
2079 ZoneList<BreakTarget*>* target_list = NEW(ZoneList<BreakTarget*>(0)); 1848 ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0);
2080 TargetCollector collector(target_list); 1849 TargetCollector collector(target_list);
2081 Statement* stat; 1850 Statement* stat;
2082 { Target target(&this->target_stack_, &collector); 1851 { Target target(&this->target_stack_, &collector);
2083 with_nesting_level_++; 1852 with_nesting_level_++;
2084 top_scope_->RecordWithStatement(); 1853 top_scope_->RecordWithStatement();
2085 stat = ParseStatement(labels, CHECK_OK); 1854 stat = ParseStatement(labels, CHECK_OK);
2086 with_nesting_level_--; 1855 with_nesting_level_--;
2087 } 1856 }
2088 // Create resulting block with two statements. 1857 // Create resulting block with two statements.
2089 // 1: Evaluate the with expression. 1858 // 1: Evaluate the with expression.
2090 // 2: The try-finally block evaluating the body. 1859 // 2: The try-finally block evaluating the body.
2091 Block* result = NEW(Block(NULL, 2, false)); 1860 Block* result = new Block(NULL, 2, false);
2092 1861
2093 if (result != NULL) { 1862 if (result != NULL) {
2094 result->AddStatement(NEW(WithEnterStatement(obj, is_catch_block))); 1863 result->AddStatement(new WithEnterStatement(obj, is_catch_block));
2095 1864
2096 // Create body block. 1865 // Create body block.
2097 Block* body = NEW(Block(NULL, 1, false)); 1866 Block* body = new Block(NULL, 1, false);
2098 body->AddStatement(stat); 1867 body->AddStatement(stat);
2099 1868
2100 // Create exit block. 1869 // Create exit block.
2101 Block* exit = NEW(Block(NULL, 1, false)); 1870 Block* exit = new Block(NULL, 1, false);
2102 exit->AddStatement(NEW(WithExitStatement())); 1871 exit->AddStatement(new WithExitStatement());
2103 1872
2104 // Return a try-finally statement. 1873 // Return a try-finally statement.
2105 TryFinallyStatement* wrapper = NEW(TryFinallyStatement(body, exit)); 1874 TryFinallyStatement* wrapper = new TryFinallyStatement(body, exit);
2106 wrapper->set_escaping_targets(collector.targets()); 1875 wrapper->set_escaping_targets(collector.targets());
2107 result->AddStatement(wrapper); 1876 result->AddStatement(wrapper);
2108 } 1877 }
2109 return result; 1878 return result;
2110 } 1879 }
2111 1880
2112 1881
2113 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 1882 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
2114 // WithStatement :: 1883 // WithStatement ::
2115 // 'with' '(' Expression ')' Statement 1884 // 'with' '(' Expression ')' Statement
(...skipping 21 matching lines...) Expand all
2137 if (*default_seen_ptr) { 1906 if (*default_seen_ptr) {
2138 ReportMessage("multiple_defaults_in_switch", 1907 ReportMessage("multiple_defaults_in_switch",
2139 Vector<const char*>::empty()); 1908 Vector<const char*>::empty());
2140 *ok = false; 1909 *ok = false;
2141 return NULL; 1910 return NULL;
2142 } 1911 }
2143 *default_seen_ptr = true; 1912 *default_seen_ptr = true;
2144 } 1913 }
2145 Expect(Token::COLON, CHECK_OK); 1914 Expect(Token::COLON, CHECK_OK);
2146 1915
2147 ZoneListWrapper<Statement> statements = factory()->NewList<Statement>(5); 1916 ZoneList<Statement*>* statements = new ZoneList<Statement*>(5);
2148 while (peek() != Token::CASE && 1917 while (peek() != Token::CASE &&
2149 peek() != Token::DEFAULT && 1918 peek() != Token::DEFAULT &&
2150 peek() != Token::RBRACE) { 1919 peek() != Token::RBRACE) {
2151 Statement* stat = ParseStatement(NULL, CHECK_OK); 1920 Statement* stat = ParseStatement(NULL, CHECK_OK);
2152 statements.Add(stat); 1921 statements->Add(stat);
2153 } 1922 }
2154 1923
2155 return NEW(CaseClause(label, statements.elements())); 1924 return new CaseClause(label, statements);
2156 } 1925 }
2157 1926
2158 1927
2159 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, 1928 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels,
2160 bool* ok) { 1929 bool* ok) {
2161 // SwitchStatement :: 1930 // SwitchStatement ::
2162 // 'switch' '(' Expression ')' '{' CaseClause* '}' 1931 // 'switch' '(' Expression ')' '{' CaseClause* '}'
2163 1932
2164 SwitchStatement* statement = NEW(SwitchStatement(labels)); 1933 SwitchStatement* statement = new SwitchStatement(labels);
2165 Target target(&this->target_stack_, statement); 1934 Target target(&this->target_stack_, statement);
2166 1935
2167 Expect(Token::SWITCH, CHECK_OK); 1936 Expect(Token::SWITCH, CHECK_OK);
2168 Expect(Token::LPAREN, CHECK_OK); 1937 Expect(Token::LPAREN, CHECK_OK);
2169 Expression* tag = ParseExpression(true, CHECK_OK); 1938 Expression* tag = ParseExpression(true, CHECK_OK);
2170 Expect(Token::RPAREN, CHECK_OK); 1939 Expect(Token::RPAREN, CHECK_OK);
2171 1940
2172 bool default_seen = false; 1941 bool default_seen = false;
2173 ZoneListWrapper<CaseClause> cases = factory()->NewList<CaseClause>(4); 1942 ZoneList<CaseClause*>* cases = new ZoneList<CaseClause*>(4);
2174 Expect(Token::LBRACE, CHECK_OK); 1943 Expect(Token::LBRACE, CHECK_OK);
2175 while (peek() != Token::RBRACE) { 1944 while (peek() != Token::RBRACE) {
2176 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); 1945 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK);
2177 cases.Add(clause); 1946 cases->Add(clause);
2178 } 1947 }
2179 Expect(Token::RBRACE, CHECK_OK); 1948 Expect(Token::RBRACE, CHECK_OK);
2180 1949
2181 if (statement) statement->Initialize(tag, cases.elements()); 1950 if (statement) statement->Initialize(tag, cases);
2182 return statement; 1951 return statement;
2183 } 1952 }
2184 1953
2185 1954
2186 Statement* Parser::ParseThrowStatement(bool* ok) { 1955 Statement* Parser::ParseThrowStatement(bool* ok) {
2187 // ThrowStatement :: 1956 // ThrowStatement ::
2188 // 'throw' Expression ';' 1957 // 'throw' Expression ';'
2189 1958
2190 Expect(Token::THROW, CHECK_OK); 1959 Expect(Token::THROW, CHECK_OK);
2191 int pos = scanner().location().beg_pos; 1960 int pos = scanner().location().beg_pos;
2192 if (scanner_.has_line_terminator_before_next()) { 1961 if (scanner_.has_line_terminator_before_next()) {
2193 ReportMessage("newline_after_throw", Vector<const char*>::empty()); 1962 ReportMessage("newline_after_throw", Vector<const char*>::empty());
2194 *ok = false; 1963 *ok = false;
2195 return NULL; 1964 return NULL;
2196 } 1965 }
2197 Expression* exception = ParseExpression(true, CHECK_OK); 1966 Expression* exception = ParseExpression(true, CHECK_OK);
2198 ExpectSemicolon(CHECK_OK); 1967 ExpectSemicolon(CHECK_OK);
2199 1968
2200 return NEW(ExpressionStatement(new Throw(exception, pos))); 1969 return new ExpressionStatement(new Throw(exception, pos));
2201 } 1970 }
2202 1971
2203 1972
2204 TryStatement* Parser::ParseTryStatement(bool* ok) { 1973 TryStatement* Parser::ParseTryStatement(bool* ok) {
2205 // TryStatement :: 1974 // TryStatement ::
2206 // 'try' Block Catch 1975 // 'try' Block Catch
2207 // 'try' Block Finally 1976 // 'try' Block Finally
2208 // 'try' Block Catch Finally 1977 // 'try' Block Catch Finally
2209 // 1978 //
2210 // Catch :: 1979 // Catch ::
2211 // 'catch' '(' Identifier ')' Block 1980 // 'catch' '(' Identifier ')' Block
2212 // 1981 //
2213 // Finally :: 1982 // Finally ::
2214 // 'finally' Block 1983 // 'finally' Block
2215 1984
2216 Expect(Token::TRY, CHECK_OK); 1985 Expect(Token::TRY, CHECK_OK);
2217 1986
2218 ZoneList<BreakTarget*>* target_list = NEW(ZoneList<BreakTarget*>(0)); 1987 ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0);
2219 TargetCollector collector(target_list); 1988 TargetCollector collector(target_list);
2220 Block* try_block; 1989 Block* try_block;
2221 1990
2222 { Target target(&this->target_stack_, &collector); 1991 { Target target(&this->target_stack_, &collector);
2223 try_block = ParseBlock(NULL, CHECK_OK); 1992 try_block = ParseBlock(NULL, CHECK_OK);
2224 } 1993 }
2225 1994
2226 Block* catch_block = NULL; 1995 Block* catch_block = NULL;
2227 VariableProxy* catch_var = NULL; 1996 VariableProxy* catch_var = NULL;
2228 Block* finally_block = NULL; 1997 Block* finally_block = NULL;
2229 1998
2230 Token::Value tok = peek(); 1999 Token::Value tok = peek();
2231 if (tok != Token::CATCH && tok != Token::FINALLY) { 2000 if (tok != Token::CATCH && tok != Token::FINALLY) {
2232 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); 2001 ReportMessage("no_catch_or_finally", Vector<const char*>::empty());
2233 *ok = false; 2002 *ok = false;
2234 return NULL; 2003 return NULL;
2235 } 2004 }
2236 2005
2237 // If we can break out from the catch block and there is a finally block, 2006 // If we can break out from the catch block and there is a finally block,
2238 // then we will need to collect jump targets from the catch block. Since 2007 // then we will need to collect jump targets from the catch block. Since
2239 // we don't know yet if there will be a finally block, we always collect 2008 // we don't know yet if there will be a finally block, we always collect
2240 // the jump targets. 2009 // the jump targets.
2241 ZoneList<BreakTarget*>* catch_target_list = NEW(ZoneList<BreakTarget*>(0)); 2010 ZoneList<BreakTarget*>* catch_target_list = new ZoneList<BreakTarget*>(0);
2242 TargetCollector catch_collector(catch_target_list); 2011 TargetCollector catch_collector(catch_target_list);
2243 bool has_catch = false; 2012 bool has_catch = false;
2244 if (tok == Token::CATCH) { 2013 if (tok == Token::CATCH) {
2245 has_catch = true; 2014 has_catch = true;
2246 Consume(Token::CATCH); 2015 Consume(Token::CATCH);
2247 2016
2248 Expect(Token::LPAREN, CHECK_OK); 2017 Expect(Token::LPAREN, CHECK_OK);
2249 Handle<String> name = ParseIdentifier(CHECK_OK); 2018 Handle<String> name = ParseIdentifier(CHECK_OK);
2250 Expect(Token::RPAREN, CHECK_OK); 2019 Expect(Token::RPAREN, CHECK_OK);
2251 2020
2252 if (peek() == Token::LBRACE) { 2021 if (peek() == Token::LBRACE) {
2253 // Allocate a temporary for holding the finally state while 2022 // Allocate a temporary for holding the finally state while
2254 // executing the finally block. 2023 // executing the finally block.
2255 catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol()); 2024 catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol());
2256 Literal* name_literal = NEW(Literal(name)); 2025 Literal* name_literal = new Literal(name);
2257 Expression* obj = NEW(CatchExtensionObject(name_literal, catch_var)); 2026 Expression* obj = new CatchExtensionObject(name_literal, catch_var);
2258 { Target target(&this->target_stack_, &catch_collector); 2027 { Target target(&this->target_stack_, &catch_collector);
2259 catch_block = WithHelper(obj, NULL, true, CHECK_OK); 2028 catch_block = WithHelper(obj, NULL, true, CHECK_OK);
2260 } 2029 }
2261 } else { 2030 } else {
2262 Expect(Token::LBRACE, CHECK_OK); 2031 Expect(Token::LBRACE, CHECK_OK);
2263 } 2032 }
2264 2033
2265 tok = peek(); 2034 tok = peek();
2266 } 2035 }
2267 2036
2268 if (tok == Token::FINALLY || !has_catch) { 2037 if (tok == Token::FINALLY || !has_catch) {
2269 Consume(Token::FINALLY); 2038 Consume(Token::FINALLY);
2270 // Declare a variable for holding the finally state while 2039 // Declare a variable for holding the finally state while
2271 // executing the finally block. 2040 // executing the finally block.
2272 finally_block = ParseBlock(NULL, CHECK_OK); 2041 finally_block = ParseBlock(NULL, CHECK_OK);
2273 } 2042 }
2274 2043
2275 // Simplify the AST nodes by converting: 2044 // Simplify the AST nodes by converting:
2276 // 'try { } catch { } finally { }' 2045 // 'try { } catch { } finally { }'
2277 // to: 2046 // to:
2278 // 'try { try { } catch { } } finally { }' 2047 // 'try { try { } catch { } } finally { }'
2279 2048
2280 if (!is_pre_parsing_ && catch_block != NULL && finally_block != NULL) { 2049 if (catch_block != NULL && finally_block != NULL) {
2281 TryCatchStatement* statement = 2050 TryCatchStatement* statement =
2282 NEW(TryCatchStatement(try_block, catch_var, catch_block)); 2051 new TryCatchStatement(try_block, catch_var, catch_block);
2283 statement->set_escaping_targets(collector.targets()); 2052 statement->set_escaping_targets(collector.targets());
2284 try_block = NEW(Block(NULL, 1, false)); 2053 try_block = new Block(NULL, 1, false);
2285 try_block->AddStatement(statement); 2054 try_block->AddStatement(statement);
2286 catch_block = NULL; 2055 catch_block = NULL;
2287 } 2056 }
2288 2057
2289 TryStatement* result = NULL; 2058 TryStatement* result = NULL;
2290 if (!is_pre_parsing_) { 2059 if (catch_block != NULL) {
2291 if (catch_block != NULL) { 2060 ASSERT(finally_block == NULL);
2292 ASSERT(finally_block == NULL); 2061 result = new TryCatchStatement(try_block, catch_var, catch_block);
2293 result = NEW(TryCatchStatement(try_block, catch_var, catch_block)); 2062 result->set_escaping_targets(collector.targets());
2294 result->set_escaping_targets(collector.targets()); 2063 } else {
2295 } else { 2064 ASSERT(finally_block != NULL);
2296 ASSERT(finally_block != NULL); 2065 result = new TryFinallyStatement(try_block, finally_block);
2297 result = NEW(TryFinallyStatement(try_block, finally_block)); 2066 // Add the jump targets of the try block and the catch block.
2298 // Add the jump targets of the try block and the catch block. 2067 for (int i = 0; i < collector.targets()->length(); i++) {
2299 for (int i = 0; i < collector.targets()->length(); i++) { 2068 catch_collector.AddTarget(collector.targets()->at(i));
2300 catch_collector.AddTarget(collector.targets()->at(i));
2301 }
2302 result->set_escaping_targets(catch_collector.targets());
2303 } 2069 }
2070 result->set_escaping_targets(catch_collector.targets());
2304 } 2071 }
2305 2072
2306 return result; 2073 return result;
2307 } 2074 }
2308 2075
2309 2076
2310 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, 2077 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
2311 bool* ok) { 2078 bool* ok) {
2312 // DoStatement :: 2079 // DoStatement ::
2313 // 'do' Statement 'while' '(' Expression ')' ';' 2080 // 'do' Statement 'while' '(' Expression ')' ';'
2314 2081
2315 temp_scope_->AddLoop(); 2082 temp_scope_->AddLoop();
2316 DoWhileStatement* loop = NEW(DoWhileStatement(labels)); 2083 DoWhileStatement* loop = new DoWhileStatement(labels);
2317 Target target(&this->target_stack_, loop); 2084 Target target(&this->target_stack_, loop);
2318 2085
2319 Expect(Token::DO, CHECK_OK); 2086 Expect(Token::DO, CHECK_OK);
2320 Statement* body = ParseStatement(NULL, CHECK_OK); 2087 Statement* body = ParseStatement(NULL, CHECK_OK);
2321 Expect(Token::WHILE, CHECK_OK); 2088 Expect(Token::WHILE, CHECK_OK);
2322 Expect(Token::LPAREN, CHECK_OK); 2089 Expect(Token::LPAREN, CHECK_OK);
2323 2090
2324 if (loop != NULL) { 2091 if (loop != NULL) {
2325 int position = scanner().location().beg_pos; 2092 int position = scanner().location().beg_pos;
2326 loop->set_condition_position(position); 2093 loop->set_condition_position(position);
(...skipping 12 matching lines...) Expand all
2339 if (loop != NULL) loop->Initialize(cond, body); 2106 if (loop != NULL) loop->Initialize(cond, body);
2340 return loop; 2107 return loop;
2341 } 2108 }
2342 2109
2343 2110
2344 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { 2111 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) {
2345 // WhileStatement :: 2112 // WhileStatement ::
2346 // 'while' '(' Expression ')' Statement 2113 // 'while' '(' Expression ')' Statement
2347 2114
2348 temp_scope_->AddLoop(); 2115 temp_scope_->AddLoop();
2349 WhileStatement* loop = NEW(WhileStatement(labels)); 2116 WhileStatement* loop = new WhileStatement(labels);
2350 Target target(&this->target_stack_, loop); 2117 Target target(&this->target_stack_, loop);
2351 2118
2352 Expect(Token::WHILE, CHECK_OK); 2119 Expect(Token::WHILE, CHECK_OK);
2353 Expect(Token::LPAREN, CHECK_OK); 2120 Expect(Token::LPAREN, CHECK_OK);
2354 Expression* cond = ParseExpression(true, CHECK_OK); 2121 Expression* cond = ParseExpression(true, CHECK_OK);
2355 if (cond != NULL) cond->set_is_loop_condition(true); 2122 if (cond != NULL) cond->set_is_loop_condition(true);
2356 Expect(Token::RPAREN, CHECK_OK); 2123 Expect(Token::RPAREN, CHECK_OK);
2357 Statement* body = ParseStatement(NULL, CHECK_OK); 2124 Statement* body = ParseStatement(NULL, CHECK_OK);
2358 2125
2359 if (loop != NULL) loop->Initialize(cond, body); 2126 if (loop != NULL) loop->Initialize(cond, body);
2360 return loop; 2127 return loop;
2361 } 2128 }
2362 2129
2363 2130
2364 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { 2131 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
2365 // ForStatement :: 2132 // ForStatement ::
2366 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 2133 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
2367 2134
2368 temp_scope_->AddLoop(); 2135 temp_scope_->AddLoop();
2369 Statement* init = NULL; 2136 Statement* init = NULL;
2370 2137
2371 Expect(Token::FOR, CHECK_OK); 2138 Expect(Token::FOR, CHECK_OK);
2372 Expect(Token::LPAREN, CHECK_OK); 2139 Expect(Token::LPAREN, CHECK_OK);
2373 if (peek() != Token::SEMICOLON) { 2140 if (peek() != Token::SEMICOLON) {
2374 if (peek() == Token::VAR || peek() == Token::CONST) { 2141 if (peek() == Token::VAR || peek() == Token::CONST) {
2375 Expression* each = NULL; 2142 Expression* each = NULL;
2376 Block* variable_statement = 2143 Block* variable_statement =
2377 ParseVariableDeclarations(false, &each, CHECK_OK); 2144 ParseVariableDeclarations(false, &each, CHECK_OK);
2378 if (peek() == Token::IN && each != NULL) { 2145 if (peek() == Token::IN && each != NULL) {
2379 ForInStatement* loop = NEW(ForInStatement(labels)); 2146 ForInStatement* loop = new ForInStatement(labels);
2380 Target target(&this->target_stack_, loop); 2147 Target target(&this->target_stack_, loop);
2381 2148
2382 Expect(Token::IN, CHECK_OK); 2149 Expect(Token::IN, CHECK_OK);
2383 Expression* enumerable = ParseExpression(true, CHECK_OK); 2150 Expression* enumerable = ParseExpression(true, CHECK_OK);
2384 Expect(Token::RPAREN, CHECK_OK); 2151 Expect(Token::RPAREN, CHECK_OK);
2385 2152
2386 Statement* body = ParseStatement(NULL, CHECK_OK); 2153 Statement* body = ParseStatement(NULL, CHECK_OK);
2387 if (is_pre_parsing_) { 2154 loop->Initialize(each, enumerable, body);
2388 return NULL; 2155 Block* result = new Block(NULL, 2, false);
2389 } else { 2156 result->AddStatement(variable_statement);
2390 loop->Initialize(each, enumerable, body); 2157 result->AddStatement(loop);
2391 Block* result = NEW(Block(NULL, 2, false)); 2158 // Parsed for-in loop w/ variable/const declaration.
2392 result->AddStatement(variable_statement); 2159 return result;
2393 result->AddStatement(loop);
2394 // Parsed for-in loop w/ variable/const declaration.
2395 return result;
2396 }
2397
2398 } else { 2160 } else {
2399 init = variable_statement; 2161 init = variable_statement;
2400 } 2162 }
2401 2163
2402 } else { 2164 } else {
2403 Expression* expression = ParseExpression(false, CHECK_OK); 2165 Expression* expression = ParseExpression(false, CHECK_OK);
2404 if (peek() == Token::IN) { 2166 if (peek() == Token::IN) {
2405 // Signal a reference error if the expression is an invalid 2167 // Signal a reference error if the expression is an invalid
2406 // left-hand side expression. We could report this as a syntax 2168 // left-hand side expression. We could report this as a syntax
2407 // error here but for compatibility with JSC we choose to report 2169 // error here but for compatibility with JSC we choose to report
2408 // the error at runtime. 2170 // the error at runtime.
2409 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2171 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2410 Handle<String> type = Factory::invalid_lhs_in_for_in_symbol(); 2172 Handle<String> type = Factory::invalid_lhs_in_for_in_symbol();
2411 expression = NewThrowReferenceError(type); 2173 expression = NewThrowReferenceError(type);
2412 } 2174 }
2413 ForInStatement* loop = NEW(ForInStatement(labels)); 2175 ForInStatement* loop = new ForInStatement(labels);
2414 Target target(&this->target_stack_, loop); 2176 Target target(&this->target_stack_, loop);
2415 2177
2416 Expect(Token::IN, CHECK_OK); 2178 Expect(Token::IN, CHECK_OK);
2417 Expression* enumerable = ParseExpression(true, CHECK_OK); 2179 Expression* enumerable = ParseExpression(true, CHECK_OK);
2418 Expect(Token::RPAREN, CHECK_OK); 2180 Expect(Token::RPAREN, CHECK_OK);
2419 2181
2420 Statement* body = ParseStatement(NULL, CHECK_OK); 2182 Statement* body = ParseStatement(NULL, CHECK_OK);
2421 if (loop) loop->Initialize(expression, enumerable, body); 2183 if (loop) loop->Initialize(expression, enumerable, body);
2422 // Parsed for-in loop. 2184 // Parsed for-in loop.
2423 return loop; 2185 return loop;
2424 2186
2425 } else { 2187 } else {
2426 init = NEW(ExpressionStatement(expression)); 2188 init = new ExpressionStatement(expression);
2427 } 2189 }
2428 } 2190 }
2429 } 2191 }
2430 2192
2431 // Standard 'for' loop 2193 // Standard 'for' loop
2432 ForStatement* loop = NEW(ForStatement(labels)); 2194 ForStatement* loop = new ForStatement(labels);
2433 Target target(&this->target_stack_, loop); 2195 Target target(&this->target_stack_, loop);
2434 2196
2435 // Parsed initializer at this point. 2197 // Parsed initializer at this point.
2436 Expect(Token::SEMICOLON, CHECK_OK); 2198 Expect(Token::SEMICOLON, CHECK_OK);
2437 2199
2438 Expression* cond = NULL; 2200 Expression* cond = NULL;
2439 if (peek() != Token::SEMICOLON) { 2201 if (peek() != Token::SEMICOLON) {
2440 cond = ParseExpression(true, CHECK_OK); 2202 cond = ParseExpression(true, CHECK_OK);
2441 if (cond != NULL) cond->set_is_loop_condition(true); 2203 if (cond != NULL) cond->set_is_loop_condition(true);
2442 } 2204 }
2443 Expect(Token::SEMICOLON, CHECK_OK); 2205 Expect(Token::SEMICOLON, CHECK_OK);
2444 2206
2445 Statement* next = NULL; 2207 Statement* next = NULL;
2446 if (peek() != Token::RPAREN) { 2208 if (peek() != Token::RPAREN) {
2447 Expression* exp = ParseExpression(true, CHECK_OK); 2209 Expression* exp = ParseExpression(true, CHECK_OK);
2448 next = NEW(ExpressionStatement(exp)); 2210 next = new ExpressionStatement(exp);
2449 } 2211 }
2450 Expect(Token::RPAREN, CHECK_OK); 2212 Expect(Token::RPAREN, CHECK_OK);
2451 2213
2452 Statement* body = ParseStatement(NULL, CHECK_OK); 2214 Statement* body = ParseStatement(NULL, CHECK_OK);
2453 if (loop) loop->Initialize(init, cond, next, body); 2215 if (loop) loop->Initialize(init, cond, next, body);
2454 return loop; 2216 return loop;
2455 } 2217 }
2456 2218
2457 2219
2458 // Precedence = 1 2220 // Precedence = 1
2459 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { 2221 Expression* Parser::ParseExpression(bool accept_IN, bool* ok) {
2460 // Expression :: 2222 // Expression ::
2461 // AssignmentExpression 2223 // AssignmentExpression
2462 // Expression ',' AssignmentExpression 2224 // Expression ',' AssignmentExpression
2463 2225
2464 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); 2226 Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK);
2465 while (peek() == Token::COMMA) { 2227 while (peek() == Token::COMMA) {
2466 Expect(Token::COMMA, CHECK_OK); 2228 Expect(Token::COMMA, CHECK_OK);
2467 int position = scanner().location().beg_pos; 2229 int position = scanner().location().beg_pos;
2468 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2230 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2469 result = NEW(BinaryOperation(Token::COMMA, result, right, position)); 2231 result = new BinaryOperation(Token::COMMA, result, right, position);
2470 } 2232 }
2471 return result; 2233 return result;
2472 } 2234 }
2473 2235
2474 2236
2475 // Precedence = 2 2237 // Precedence = 2
2476 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { 2238 Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
2477 // AssignmentExpression :: 2239 // AssignmentExpression ::
2478 // ConditionalExpression 2240 // ConditionalExpression
2479 // LeftHandSideExpression AssignmentOperator AssignmentExpression 2241 // LeftHandSideExpression AssignmentOperator AssignmentExpression
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 // expression. 2281 // expression.
2520 if ((op == Token::INIT_VAR 2282 if ((op == Token::INIT_VAR
2521 || op == Token::INIT_CONST 2283 || op == Token::INIT_CONST
2522 || op == Token::ASSIGN) 2284 || op == Token::ASSIGN)
2523 && (right->AsCall() == NULL)) { 2285 && (right->AsCall() == NULL)) {
2524 fni_->Infer(); 2286 fni_->Infer();
2525 } 2287 }
2526 fni_->Leave(); 2288 fni_->Leave();
2527 } 2289 }
2528 2290
2529 return NEW(Assignment(op, expression, right, pos)); 2291 return new Assignment(op, expression, right, pos);
2530 } 2292 }
2531 2293
2532 2294
2533 // Precedence = 3 2295 // Precedence = 3
2534 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { 2296 Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
2535 // ConditionalExpression :: 2297 // ConditionalExpression ::
2536 // LogicalOrExpression 2298 // LogicalOrExpression
2537 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression 2299 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
2538 2300
2539 // We start using the binary expression parser for prec >= 4 only! 2301 // We start using the binary expression parser for prec >= 4 only!
2540 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); 2302 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
2541 if (peek() != Token::CONDITIONAL) return expression; 2303 if (peek() != Token::CONDITIONAL) return expression;
2542 Consume(Token::CONDITIONAL); 2304 Consume(Token::CONDITIONAL);
2543 // In parsing the first assignment expression in conditional 2305 // In parsing the first assignment expression in conditional
2544 // expressions we always accept the 'in' keyword; see ECMA-262, 2306 // expressions we always accept the 'in' keyword; see ECMA-262,
2545 // section 11.12, page 58. 2307 // section 11.12, page 58.
2546 int left_position = scanner().peek_location().beg_pos; 2308 int left_position = scanner().peek_location().beg_pos;
2547 Expression* left = ParseAssignmentExpression(true, CHECK_OK); 2309 Expression* left = ParseAssignmentExpression(true, CHECK_OK);
2548 Expect(Token::COLON, CHECK_OK); 2310 Expect(Token::COLON, CHECK_OK);
2549 int right_position = scanner().peek_location().beg_pos; 2311 int right_position = scanner().peek_location().beg_pos;
2550 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2312 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2551 return NEW(Conditional(expression, left, right, 2313 return new Conditional(expression, left, right,
2552 left_position, right_position)); 2314 left_position, right_position);
2553 } 2315 }
2554 2316
2555 2317
2556 static int Precedence(Token::Value tok, bool accept_IN) { 2318 static int Precedence(Token::Value tok, bool accept_IN) {
2557 if (tok == Token::IN && !accept_IN) 2319 if (tok == Token::IN && !accept_IN)
2558 return 0; // 0 precedence will terminate binary expression parsing 2320 return 0; // 0 precedence will terminate binary expression parsing
2559 2321
2560 return Token::Precedence(tok); 2322 return Token::Precedence(tok);
2561 } 2323 }
2562 2324
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2649 // We have a comparison. 2411 // We have a comparison.
2650 Token::Value cmp = op; 2412 Token::Value cmp = op;
2651 switch (op) { 2413 switch (op) {
2652 case Token::NE: cmp = Token::EQ; break; 2414 case Token::NE: cmp = Token::EQ; break;
2653 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; 2415 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
2654 default: break; 2416 default: break;
2655 } 2417 }
2656 x = NewCompareNode(cmp, x, y, position); 2418 x = NewCompareNode(cmp, x, y, position);
2657 if (cmp != op) { 2419 if (cmp != op) {
2658 // The comparison was negated - add a NOT. 2420 // The comparison was negated - add a NOT.
2659 x = NEW(UnaryOperation(Token::NOT, x)); 2421 x = new UnaryOperation(Token::NOT, x);
2660 } 2422 }
2661 2423
2662 } else { 2424 } else {
2663 // We have a "normal" binary operation. 2425 // We have a "normal" binary operation.
2664 x = NEW(BinaryOperation(op, x, y, position)); 2426 x = new BinaryOperation(op, x, y, position);
2665 } 2427 }
2666 } 2428 }
2667 } 2429 }
2668 return x; 2430 return x;
2669 } 2431 }
2670 2432
2671 2433
2672 Expression* Parser::NewCompareNode(Token::Value op, 2434 Expression* Parser::NewCompareNode(Token::Value op,
2673 Expression* x, 2435 Expression* x,
2674 Expression* y, 2436 Expression* y,
2675 int position) { 2437 int position) {
2676 ASSERT(op != Token::NE && op != Token::NE_STRICT); 2438 ASSERT(op != Token::NE && op != Token::NE_STRICT);
2677 if (!is_pre_parsing_ && (op == Token::EQ || op == Token::EQ_STRICT)) { 2439 if (op == Token::EQ || op == Token::EQ_STRICT) {
2678 bool is_strict = (op == Token::EQ_STRICT); 2440 bool is_strict = (op == Token::EQ_STRICT);
2679 Literal* x_literal = x->AsLiteral(); 2441 Literal* x_literal = x->AsLiteral();
2680 if (x_literal != NULL && x_literal->IsNull()) { 2442 if (x_literal != NULL && x_literal->IsNull()) {
2681 return NEW(CompareToNull(is_strict, y)); 2443 return new CompareToNull(is_strict, y);
2682 } 2444 }
2683 2445
2684 Literal* y_literal = y->AsLiteral(); 2446 Literal* y_literal = y->AsLiteral();
2685 if (y_literal != NULL && y_literal->IsNull()) { 2447 if (y_literal != NULL && y_literal->IsNull()) {
2686 return NEW(CompareToNull(is_strict, x)); 2448 return new CompareToNull(is_strict, x);
2687 } 2449 }
2688 } 2450 }
2689 return NEW(CompareOperation(op, x, y, position)); 2451 return new CompareOperation(op, x, y, position);
2690 } 2452 }
2691 2453
2692 2454
2693 Expression* Parser::ParseUnaryExpression(bool* ok) { 2455 Expression* Parser::ParseUnaryExpression(bool* ok) {
2694 // UnaryExpression :: 2456 // UnaryExpression ::
2695 // PostfixExpression 2457 // PostfixExpression
2696 // 'delete' UnaryExpression 2458 // 'delete' UnaryExpression
2697 // 'void' UnaryExpression 2459 // 'void' UnaryExpression
2698 // 'typeof' UnaryExpression 2460 // 'typeof' UnaryExpression
2699 // '++' UnaryExpression 2461 // '++' UnaryExpression
(...skipping 16 matching lines...) Expand all
2716 case Token::ADD: 2478 case Token::ADD:
2717 return expression; 2479 return expression;
2718 case Token::SUB: 2480 case Token::SUB:
2719 return NewNumberLiteral(-value); 2481 return NewNumberLiteral(-value);
2720 case Token::BIT_NOT: 2482 case Token::BIT_NOT:
2721 return NewNumberLiteral(~DoubleToInt32(value)); 2483 return NewNumberLiteral(~DoubleToInt32(value));
2722 default: break; 2484 default: break;
2723 } 2485 }
2724 } 2486 }
2725 2487
2726 return NEW(UnaryOperation(op, expression)); 2488 return new UnaryOperation(op, expression);
2727 2489
2728 } else if (Token::IsCountOp(op)) { 2490 } else if (Token::IsCountOp(op)) {
2729 op = Next(); 2491 op = Next();
2730 Expression* expression = ParseUnaryExpression(CHECK_OK); 2492 Expression* expression = ParseUnaryExpression(CHECK_OK);
2731 // Signal a reference error if the expression is an invalid 2493 // Signal a reference error if the expression is an invalid
2732 // left-hand side expression. We could report this as a syntax 2494 // left-hand side expression. We could report this as a syntax
2733 // error here but for compatibility with JSC we choose to report the 2495 // error here but for compatibility with JSC we choose to report the
2734 // error at runtime. 2496 // error at runtime.
2735 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2497 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2736 Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol(); 2498 Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol();
2737 expression = NewThrowReferenceError(type); 2499 expression = NewThrowReferenceError(type);
2738 } 2500 }
2739 int position = scanner().location().beg_pos; 2501 int position = scanner().location().beg_pos;
2740 IncrementOperation* increment = NEW(IncrementOperation(op, expression)); 2502 IncrementOperation* increment = new IncrementOperation(op, expression);
2741 return NEW(CountOperation(true /* prefix */, increment, position)); 2503 return new CountOperation(true /* prefix */, increment, position);
2742 2504
2743 } else { 2505 } else {
2744 return ParsePostfixExpression(ok); 2506 return ParsePostfixExpression(ok);
2745 } 2507 }
2746 } 2508 }
2747 2509
2748 2510
2749 Expression* Parser::ParsePostfixExpression(bool* ok) { 2511 Expression* Parser::ParsePostfixExpression(bool* ok) {
2750 // PostfixExpression :: 2512 // PostfixExpression ::
2751 // LeftHandSideExpression ('++' | '--')? 2513 // LeftHandSideExpression ('++' | '--')?
2752 2514
2753 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); 2515 Expression* expression = ParseLeftHandSideExpression(CHECK_OK);
2754 if (!scanner_.has_line_terminator_before_next() && Token::IsCountOp(peek())) { 2516 if (!scanner_.has_line_terminator_before_next() && Token::IsCountOp(peek())) {
2755 // Signal a reference error if the expression is an invalid 2517 // Signal a reference error if the expression is an invalid
2756 // left-hand side expression. We could report this as a syntax 2518 // left-hand side expression. We could report this as a syntax
2757 // error here but for compatibility with JSC we choose to report the 2519 // error here but for compatibility with JSC we choose to report the
2758 // error at runtime. 2520 // error at runtime.
2759 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2521 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2760 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol(); 2522 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol();
2761 expression = NewThrowReferenceError(type); 2523 expression = NewThrowReferenceError(type);
2762 } 2524 }
2763 Token::Value next = Next(); 2525 Token::Value next = Next();
2764 int position = scanner().location().beg_pos; 2526 int position = scanner().location().beg_pos;
2765 IncrementOperation* increment = NEW(IncrementOperation(next, expression)); 2527 IncrementOperation* increment = new IncrementOperation(next, expression);
2766 expression = NEW(CountOperation(false /* postfix */, increment, position)); 2528 expression = new CountOperation(false /* postfix */, increment, position);
2767 } 2529 }
2768 return expression; 2530 return expression;
2769 } 2531 }
2770 2532
2771 2533
2772 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { 2534 Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
2773 // LeftHandSideExpression :: 2535 // LeftHandSideExpression ::
2774 // (NewExpression | MemberExpression) ... 2536 // (NewExpression | MemberExpression) ...
2775 2537
2776 Expression* result; 2538 Expression* result;
2777 if (peek() == Token::NEW) { 2539 if (peek() == Token::NEW) {
2778 result = ParseNewExpression(CHECK_OK); 2540 result = ParseNewExpression(CHECK_OK);
2779 } else { 2541 } else {
2780 result = ParseMemberExpression(CHECK_OK); 2542 result = ParseMemberExpression(CHECK_OK);
2781 } 2543 }
2782 2544
2783 while (true) { 2545 while (true) {
2784 switch (peek()) { 2546 switch (peek()) {
2785 case Token::LBRACK: { 2547 case Token::LBRACK: {
2786 Consume(Token::LBRACK); 2548 Consume(Token::LBRACK);
2787 int pos = scanner().location().beg_pos; 2549 int pos = scanner().location().beg_pos;
2788 Expression* index = ParseExpression(true, CHECK_OK); 2550 Expression* index = ParseExpression(true, CHECK_OK);
2789 result = factory()->NewProperty(result, index, pos); 2551 result = new Property(result, index, pos);
2790 Expect(Token::RBRACK, CHECK_OK); 2552 Expect(Token::RBRACK, CHECK_OK);
2791 break; 2553 break;
2792 } 2554 }
2793 2555
2794 case Token::LPAREN: { 2556 case Token::LPAREN: {
2795 int pos = scanner().location().beg_pos; 2557 int pos = scanner().location().beg_pos;
2796 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2558 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2797 2559
2798 // Keep track of eval() calls since they disable all local variable 2560 // Keep track of eval() calls since they disable all local variable
2799 // optimizations. 2561 // optimizations.
2800 // The calls that need special treatment are the 2562 // The calls that need special treatment are the
2801 // direct (i.e. not aliased) eval calls. These calls are all of the 2563 // direct (i.e. not aliased) eval calls. These calls are all of the
2802 // form eval(...) with no explicit receiver object where eval is not 2564 // form eval(...) with no explicit receiver object where eval is not
2803 // declared in the current scope chain. These calls are marked as 2565 // declared in the current scope chain. These calls are marked as
2804 // potentially direct eval calls. Whether they are actually direct calls 2566 // potentially direct eval calls. Whether they are actually direct calls
2805 // to eval is determined at run time. 2567 // to eval is determined at run time.
2806 if (!is_pre_parsing_) { 2568 VariableProxy* callee = result->AsVariableProxy();
2807 VariableProxy* callee = result->AsVariableProxy(); 2569 if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) {
2808 if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) { 2570 Handle<String> name = callee->name();
2809 Handle<String> name = callee->name(); 2571 Variable* var = top_scope_->Lookup(name);
2810 Variable* var = top_scope_->Lookup(name); 2572 if (var == NULL) {
2811 if (var == NULL) { 2573 top_scope_->RecordEvalCall();
2812 top_scope_->RecordEvalCall();
2813 }
2814 } 2574 }
2815 } 2575 }
2816 result = factory()->NewCall(result, args, pos); 2576 result = NewCall(result, args, pos);
2817 break; 2577 break;
2818 } 2578 }
2819 2579
2820 case Token::PERIOD: { 2580 case Token::PERIOD: {
2821 Consume(Token::PERIOD); 2581 Consume(Token::PERIOD);
2822 int pos = scanner().location().beg_pos; 2582 int pos = scanner().location().beg_pos;
2823 Handle<String> name = ParseIdentifierName(CHECK_OK); 2583 Handle<String> name = ParseIdentifierName(CHECK_OK);
2824 result = factory()->NewProperty(result, NEW(Literal(name)), pos); 2584 result = new Property(result, new Literal(name), pos);
2825 if (fni_ != NULL) fni_->PushLiteralName(name); 2585 if (fni_ != NULL) fni_->PushLiteralName(name);
2826 break; 2586 break;
2827 } 2587 }
2828 2588
2829 default: 2589 default:
2830 return result; 2590 return result;
2831 } 2591 }
2832 } 2592 }
2833 } 2593 }
2834 2594
2835 2595
2836
2837 Expression* Parser::ParseNewPrefix(PositionStack* stack, bool* ok) { 2596 Expression* Parser::ParseNewPrefix(PositionStack* stack, bool* ok) {
2838 // NewExpression :: 2597 // NewExpression ::
2839 // ('new')+ MemberExpression 2598 // ('new')+ MemberExpression
2840 2599
2841 // The grammar for new expressions is pretty warped. The keyword 2600 // The grammar for new expressions is pretty warped. The keyword
2842 // 'new' can either be a part of the new expression (where it isn't 2601 // 'new' can either be a part of the new expression (where it isn't
2843 // followed by an argument list) or a part of the member expression, 2602 // followed by an argument list) or a part of the member expression,
2844 // where it must be followed by an argument list. To accommodate 2603 // where it must be followed by an argument list. To accommodate
2845 // this, we parse the 'new' keywords greedily and keep track of how 2604 // this, we parse the 'new' keywords greedily and keep track of how
2846 // many we have parsed. This information is then passed on to the 2605 // many we have parsed. This information is then passed on to the
2847 // member expression parser, which is only allowed to match argument 2606 // member expression parser, which is only allowed to match argument
2848 // lists as long as it has 'new' prefixes left 2607 // lists as long as it has 'new' prefixes left
2849 Expect(Token::NEW, CHECK_OK); 2608 Expect(Token::NEW, CHECK_OK);
2850 PositionStack::Element pos(stack, scanner().location().beg_pos); 2609 PositionStack::Element pos(stack, scanner().location().beg_pos);
2851 2610
2852 Expression* result; 2611 Expression* result;
2853 if (peek() == Token::NEW) { 2612 if (peek() == Token::NEW) {
2854 result = ParseNewPrefix(stack, CHECK_OK); 2613 result = ParseNewPrefix(stack, CHECK_OK);
2855 } else { 2614 } else {
2856 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); 2615 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK);
2857 } 2616 }
2858 2617
2859 if (!stack->is_empty()) { 2618 if (!stack->is_empty()) {
2860 int last = stack->pop(); 2619 int last = stack->pop();
2861 result = NEW(CallNew(result, new ZoneList<Expression*>(0), last)); 2620 result = new CallNew(result, new ZoneList<Expression*>(0), last);
2862 } 2621 }
2863 return result; 2622 return result;
2864 } 2623 }
2865 2624
2866 2625
2867 Expression* Parser::ParseNewExpression(bool* ok) { 2626 Expression* Parser::ParseNewExpression(bool* ok) {
2868 PositionStack stack(ok); 2627 PositionStack stack(ok);
2869 return ParseNewPrefix(&stack, ok); 2628 return ParseNewPrefix(&stack, ok);
2870 } 2629 }
2871 2630
(...skipping 21 matching lines...) Expand all
2893 } else { 2652 } else {
2894 result = ParsePrimaryExpression(CHECK_OK); 2653 result = ParsePrimaryExpression(CHECK_OK);
2895 } 2654 }
2896 2655
2897 while (true) { 2656 while (true) {
2898 switch (peek()) { 2657 switch (peek()) {
2899 case Token::LBRACK: { 2658 case Token::LBRACK: {
2900 Consume(Token::LBRACK); 2659 Consume(Token::LBRACK);
2901 int pos = scanner().location().beg_pos; 2660 int pos = scanner().location().beg_pos;
2902 Expression* index = ParseExpression(true, CHECK_OK); 2661 Expression* index = ParseExpression(true, CHECK_OK);
2903 result = factory()->NewProperty(result, index, pos); 2662 result = new Property(result, index, pos);
2904 Expect(Token::RBRACK, CHECK_OK); 2663 Expect(Token::RBRACK, CHECK_OK);
2905 break; 2664 break;
2906 } 2665 }
2907 case Token::PERIOD: { 2666 case Token::PERIOD: {
2908 Consume(Token::PERIOD); 2667 Consume(Token::PERIOD);
2909 int pos = scanner().location().beg_pos; 2668 int pos = scanner().location().beg_pos;
2910 Handle<String> name = ParseIdentifierName(CHECK_OK); 2669 Handle<String> name = ParseIdentifierName(CHECK_OK);
2911 result = factory()->NewProperty(result, NEW(Literal(name)), pos); 2670 result = new Property(result, new Literal(name), pos);
2912 if (fni_ != NULL) fni_->PushLiteralName(name); 2671 if (fni_ != NULL) fni_->PushLiteralName(name);
2913 break; 2672 break;
2914 } 2673 }
2915 case Token::LPAREN: { 2674 case Token::LPAREN: {
2916 if ((stack == NULL) || stack->is_empty()) return result; 2675 if ((stack == NULL) || stack->is_empty()) return result;
2917 // Consume one of the new prefixes (already parsed). 2676 // Consume one of the new prefixes (already parsed).
2918 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 2677 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
2919 int last = stack->pop(); 2678 int last = stack->pop();
2920 result = NEW(CallNew(result, args, last)); 2679 result = new CallNew(result, args, last);
2921 break; 2680 break;
2922 } 2681 }
2923 default: 2682 default:
2924 return result; 2683 return result;
2925 } 2684 }
2926 } 2685 }
2927 } 2686 }
2928 2687
2929 2688
2930 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { 2689 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) {
2931 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser 2690 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser
2932 // contexts this is used as a statement which invokes the debugger as i a 2691 // contexts this is used as a statement which invokes the debugger as i a
2933 // break point is present. 2692 // break point is present.
2934 // DebuggerStatement :: 2693 // DebuggerStatement ::
2935 // 'debugger' ';' 2694 // 'debugger' ';'
2936 2695
2937 Expect(Token::DEBUGGER, CHECK_OK); 2696 Expect(Token::DEBUGGER, CHECK_OK);
2938 ExpectSemicolon(CHECK_OK); 2697 ExpectSemicolon(CHECK_OK);
2939 return NEW(DebuggerStatement()); 2698 return new DebuggerStatement();
2940 } 2699 }
2941 2700
2942 2701
2943 void Parser::ReportUnexpectedToken(Token::Value token) { 2702 void Parser::ReportUnexpectedToken(Token::Value token) {
2944 // We don't report stack overflows here, to avoid increasing the 2703 // We don't report stack overflows here, to avoid increasing the
2945 // stack depth even further. Instead we report it after parsing is 2704 // stack depth even further. Instead we report it after parsing is
2946 // over, in ParseProgram/ParseJson. 2705 // over, in ParseProgram/ParseJson.
2947 if (token == Token::ILLEGAL && scanner().stack_overflow()) 2706 if (token == Token::ILLEGAL && scanner().stack_overflow())
2948 return; 2707 return;
2949 // Four of the tokens are treated specially 2708 // Four of the tokens are treated specially
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2987 // String 2746 // String
2988 // ArrayLiteral 2747 // ArrayLiteral
2989 // ObjectLiteral 2748 // ObjectLiteral
2990 // RegExpLiteral 2749 // RegExpLiteral
2991 // '(' Expression ')' 2750 // '(' Expression ')'
2992 2751
2993 Expression* result = NULL; 2752 Expression* result = NULL;
2994 switch (peek()) { 2753 switch (peek()) {
2995 case Token::THIS: { 2754 case Token::THIS: {
2996 Consume(Token::THIS); 2755 Consume(Token::THIS);
2997 if (is_pre_parsing_) { 2756 VariableProxy* recv = top_scope_->receiver();
2998 result = VariableProxySentinel::this_proxy(); 2757 result = recv;
2999 } else {
3000 VariableProxy* recv = top_scope_->receiver();
3001 result = recv;
3002 }
3003 break; 2758 break;
3004 } 2759 }
3005 2760
3006 case Token::NULL_LITERAL: 2761 case Token::NULL_LITERAL:
3007 Consume(Token::NULL_LITERAL); 2762 Consume(Token::NULL_LITERAL);
3008 result = NEW(Literal(Factory::null_value())); 2763 result = new Literal(Factory::null_value());
3009 break; 2764 break;
3010 2765
3011 case Token::TRUE_LITERAL: 2766 case Token::TRUE_LITERAL:
3012 Consume(Token::TRUE_LITERAL); 2767 Consume(Token::TRUE_LITERAL);
3013 result = NEW(Literal(Factory::true_value())); 2768 result = new Literal(Factory::true_value());
3014 break; 2769 break;
3015 2770
3016 case Token::FALSE_LITERAL: 2771 case Token::FALSE_LITERAL:
3017 Consume(Token::FALSE_LITERAL); 2772 Consume(Token::FALSE_LITERAL);
3018 result = NEW(Literal(Factory::false_value())); 2773 result = new Literal(Factory::false_value());
3019 break; 2774 break;
3020 2775
3021 case Token::IDENTIFIER: { 2776 case Token::IDENTIFIER: {
3022 Handle<String> name = ParseIdentifier(CHECK_OK); 2777 Handle<String> name = ParseIdentifier(CHECK_OK);
3023 if (fni_ != NULL) fni_->PushVariableName(name); 2778 if (fni_ != NULL) fni_->PushVariableName(name);
3024 if (is_pre_parsing_) { 2779 result = top_scope_->NewUnresolved(name, inside_with());
3025 result = VariableProxySentinel::identifier_proxy();
3026 } else {
3027 result = top_scope_->NewUnresolved(name, inside_with());
3028 }
3029 break; 2780 break;
3030 } 2781 }
3031 2782
3032 case Token::NUMBER: { 2783 case Token::NUMBER: {
3033 Consume(Token::NUMBER); 2784 Consume(Token::NUMBER);
3034 double value = 2785 double value =
3035 StringToDouble(scanner_.literal(), ALLOW_HEX | ALLOW_OCTALS); 2786 StringToDouble(scanner_.literal(), ALLOW_HEX | ALLOW_OCTALS);
3036 result = NewNumberLiteral(value); 2787 result = NewNumberLiteral(value);
3037 break; 2788 break;
3038 } 2789 }
3039 2790
3040 case Token::STRING: { 2791 case Token::STRING: {
3041 Consume(Token::STRING); 2792 Consume(Token::STRING);
3042 Handle<String> symbol = GetSymbol(CHECK_OK); 2793 Handle<String> symbol = GetSymbol(CHECK_OK);
3043 result = NEW(Literal(symbol)); 2794 result = new Literal(symbol);
3044 if (fni_ != NULL) fni_->PushLiteralName(symbol); 2795 if (fni_ != NULL) fni_->PushLiteralName(symbol);
3045 break; 2796 break;
3046 } 2797 }
3047 2798
3048 case Token::ASSIGN_DIV: 2799 case Token::ASSIGN_DIV:
3049 result = ParseRegExpLiteral(true, CHECK_OK); 2800 result = ParseRegExpLiteral(true, CHECK_OK);
3050 break; 2801 break;
3051 2802
3052 case Token::DIV: 2803 case Token::DIV:
3053 result = ParseRegExpLiteral(false, CHECK_OK); 2804 result = ParseRegExpLiteral(false, CHECK_OK);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3111 2862
3112 *is_simple = is_simple_acc; 2863 *is_simple = is_simple_acc;
3113 *depth = depth_acc; 2864 *depth = depth_acc;
3114 } 2865 }
3115 2866
3116 2867
3117 Expression* Parser::ParseArrayLiteral(bool* ok) { 2868 Expression* Parser::ParseArrayLiteral(bool* ok) {
3118 // ArrayLiteral :: 2869 // ArrayLiteral ::
3119 // '[' Expression? (',' Expression?)* ']' 2870 // '[' Expression? (',' Expression?)* ']'
3120 2871
3121 ZoneListWrapper<Expression> values = factory()->NewList<Expression>(4); 2872 ZoneList<Expression*>* values = new ZoneList<Expression*>(4);
3122 Expect(Token::LBRACK, CHECK_OK); 2873 Expect(Token::LBRACK, CHECK_OK);
3123 while (peek() != Token::RBRACK) { 2874 while (peek() != Token::RBRACK) {
3124 Expression* elem; 2875 Expression* elem;
3125 if (peek() == Token::COMMA) { 2876 if (peek() == Token::COMMA) {
3126 elem = GetLiteralTheHole(); 2877 elem = GetLiteralTheHole();
3127 } else { 2878 } else {
3128 elem = ParseAssignmentExpression(true, CHECK_OK); 2879 elem = ParseAssignmentExpression(true, CHECK_OK);
3129 } 2880 }
3130 values.Add(elem); 2881 values->Add(elem);
3131 if (peek() != Token::RBRACK) { 2882 if (peek() != Token::RBRACK) {
3132 Expect(Token::COMMA, CHECK_OK); 2883 Expect(Token::COMMA, CHECK_OK);
3133 } 2884 }
3134 } 2885 }
3135 Expect(Token::RBRACK, CHECK_OK); 2886 Expect(Token::RBRACK, CHECK_OK);
3136 2887
3137 // Update the scope information before the pre-parsing bailout. 2888 // Update the scope information before the pre-parsing bailout.
3138 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 2889 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3139 2890
3140 if (is_pre_parsing_) return NULL;
3141
3142 // Allocate a fixed array with all the literals. 2891 // Allocate a fixed array with all the literals.
3143 Handle<FixedArray> literals = 2892 Handle<FixedArray> literals =
3144 Factory::NewFixedArray(values.length(), TENURED); 2893 Factory::NewFixedArray(values->length(), TENURED);
3145 2894
3146 // Fill in the literals. 2895 // Fill in the literals.
3147 bool is_simple = true; 2896 bool is_simple = true;
3148 int depth = 1; 2897 int depth = 1;
3149 for (int i = 0; i < values.length(); i++) { 2898 for (int i = 0, n = values->length(); i < n; i++) {
3150 MaterializedLiteral* m_literal = values.at(i)->AsMaterializedLiteral(); 2899 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral();
3151 if (m_literal != NULL && m_literal->depth() + 1 > depth) { 2900 if (m_literal != NULL && m_literal->depth() + 1 > depth) {
3152 depth = m_literal->depth() + 1; 2901 depth = m_literal->depth() + 1;
3153 } 2902 }
3154 Handle<Object> boilerplate_value = GetBoilerplateValue(values.at(i)); 2903 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i));
3155 if (boilerplate_value->IsUndefined()) { 2904 if (boilerplate_value->IsUndefined()) {
3156 literals->set_the_hole(i); 2905 literals->set_the_hole(i);
3157 is_simple = false; 2906 is_simple = false;
3158 } else { 2907 } else {
3159 literals->set(i, *boilerplate_value); 2908 literals->set(i, *boilerplate_value);
3160 } 2909 }
3161 } 2910 }
3162 2911
3163 // Simple and shallow arrays can be lazily copied, we transform the 2912 // Simple and shallow arrays can be lazily copied, we transform the
3164 // elements array to a copy-on-write array. 2913 // elements array to a copy-on-write array.
3165 if (is_simple && depth == 1 && values.length() > 0) { 2914 if (is_simple && depth == 1 && values->length() > 0) {
3166 literals->set_map(Heap::fixed_cow_array_map()); 2915 literals->set_map(Heap::fixed_cow_array_map());
3167 } 2916 }
3168 2917
3169 return NEW(ArrayLiteral(literals, values.elements(), 2918 return new ArrayLiteral(literals, values,
3170 literal_index, is_simple, depth)); 2919 literal_index, is_simple, depth);
3171 } 2920 }
3172 2921
3173 2922
3174 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { 2923 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) {
3175 return property != NULL && 2924 return property != NULL &&
3176 property->kind() != ObjectLiteral::Property::PROTOTYPE; 2925 property->kind() != ObjectLiteral::Property::PROTOTYPE;
3177 } 2926 }
3178 2927
3179 2928
3180 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 2929 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3307 Token::Value next = Next(); 3056 Token::Value next = Next();
3308 // TODO(820): Allow NUMBER and STRING as well (and handle array indices). 3057 // TODO(820): Allow NUMBER and STRING as well (and handle array indices).
3309 if (next == Token::IDENTIFIER || Token::IsKeyword(next)) { 3058 if (next == Token::IDENTIFIER || Token::IsKeyword(next)) {
3310 Handle<String> name = GetSymbol(CHECK_OK); 3059 Handle<String> name = GetSymbol(CHECK_OK);
3311 FunctionLiteral* value = 3060 FunctionLiteral* value =
3312 ParseFunctionLiteral(name, 3061 ParseFunctionLiteral(name,
3313 RelocInfo::kNoPosition, 3062 RelocInfo::kNoPosition,
3314 DECLARATION, 3063 DECLARATION,
3315 CHECK_OK); 3064 CHECK_OK);
3316 ObjectLiteral::Property* property = 3065 ObjectLiteral::Property* property =
3317 NEW(ObjectLiteral::Property(is_getter, value)); 3066 new ObjectLiteral::Property(is_getter, value);
3318 return property; 3067 return property;
3319 } else { 3068 } else {
3320 ReportUnexpectedToken(next); 3069 ReportUnexpectedToken(next);
3321 *ok = false; 3070 *ok = false;
3322 return NULL; 3071 return NULL;
3323 } 3072 }
3324 } 3073 }
3325 3074
3326 3075
3327 Expression* Parser::ParseObjectLiteral(bool* ok) { 3076 Expression* Parser::ParseObjectLiteral(bool* ok) {
3328 // ObjectLiteral :: 3077 // ObjectLiteral ::
3329 // '{' ( 3078 // '{' (
3330 // ((IdentifierName | String | Number) ':' AssignmentExpression) 3079 // ((IdentifierName | String | Number) ':' AssignmentExpression)
3331 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) 3080 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
3332 // )*[','] '}' 3081 // )*[','] '}'
3333 3082
3334 ZoneListWrapper<ObjectLiteral::Property> properties = 3083 ZoneList<ObjectLiteral::Property*>* properties =
3335 factory()->NewList<ObjectLiteral::Property>(4); 3084 new ZoneList<ObjectLiteral::Property*>(4);
3336 int number_of_boilerplate_properties = 0; 3085 int number_of_boilerplate_properties = 0;
3337 3086
3338 Expect(Token::LBRACE, CHECK_OK); 3087 Expect(Token::LBRACE, CHECK_OK);
3339 while (peek() != Token::RBRACE) { 3088 while (peek() != Token::RBRACE) {
3340 if (fni_ != NULL) fni_->Enter(); 3089 if (fni_ != NULL) fni_->Enter();
3341 3090
3342 Literal* key = NULL; 3091 Literal* key = NULL;
3343 Token::Value next = peek(); 3092 Token::Value next = peek();
3344 switch (next) { 3093 switch (next) {
3345 case Token::IDENTIFIER: { 3094 case Token::IDENTIFIER: {
3346 bool is_getter = false; 3095 bool is_getter = false;
3347 bool is_setter = false; 3096 bool is_setter = false;
3348 Handle<String> id = 3097 Handle<String> id =
3349 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); 3098 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK);
3350 if (fni_ != NULL) fni_->PushLiteralName(id); 3099 if (fni_ != NULL) fni_->PushLiteralName(id);
3351 3100
3352 if ((is_getter || is_setter) && peek() != Token::COLON) { 3101 if ((is_getter || is_setter) && peek() != Token::COLON) {
3353 ObjectLiteral::Property* property = 3102 ObjectLiteral::Property* property =
3354 ParseObjectLiteralGetSet(is_getter, CHECK_OK); 3103 ParseObjectLiteralGetSet(is_getter, CHECK_OK);
3355 if (IsBoilerplateProperty(property)) { 3104 if (IsBoilerplateProperty(property)) {
3356 number_of_boilerplate_properties++; 3105 number_of_boilerplate_properties++;
3357 } 3106 }
3358 properties.Add(property); 3107 properties->Add(property);
3359 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); 3108 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
3360 3109
3361 if (fni_ != NULL) { 3110 if (fni_ != NULL) {
3362 fni_->Infer(); 3111 fni_->Infer();
3363 fni_->Leave(); 3112 fni_->Leave();
3364 } 3113 }
3365 continue; // restart the while 3114 continue; // restart the while
3366 } 3115 }
3367 // Failed to parse as get/set property, so it's just a property 3116 // Failed to parse as get/set property, so it's just a property
3368 // called "get" or "set". 3117 // called "get" or "set".
3369 key = NEW(Literal(id)); 3118 key = new Literal(id);
3370 break; 3119 break;
3371 } 3120 }
3372 case Token::STRING: { 3121 case Token::STRING: {
3373 Consume(Token::STRING); 3122 Consume(Token::STRING);
3374 Handle<String> string = GetSymbol(CHECK_OK); 3123 Handle<String> string = GetSymbol(CHECK_OK);
3375 if (fni_ != NULL) fni_->PushLiteralName(string); 3124 if (fni_ != NULL) fni_->PushLiteralName(string);
3376 uint32_t index; 3125 uint32_t index;
3377 if (!string.is_null() && string->AsArrayIndex(&index)) { 3126 if (!string.is_null() && string->AsArrayIndex(&index)) {
3378 key = NewNumberLiteral(index); 3127 key = NewNumberLiteral(index);
3379 break; 3128 break;
3380 } 3129 }
3381 key = NEW(Literal(string)); 3130 key = new Literal(string);
3382 break; 3131 break;
3383 } 3132 }
3384 case Token::NUMBER: { 3133 case Token::NUMBER: {
3385 Consume(Token::NUMBER); 3134 Consume(Token::NUMBER);
3386 double value = 3135 double value =
3387 StringToDouble(scanner_.literal(), ALLOW_HEX | ALLOW_OCTALS); 3136 StringToDouble(scanner_.literal(), ALLOW_HEX | ALLOW_OCTALS);
3388 key = NewNumberLiteral(value); 3137 key = NewNumberLiteral(value);
3389 break; 3138 break;
3390 } 3139 }
3391 default: 3140 default:
3392 if (Token::IsKeyword(next)) { 3141 if (Token::IsKeyword(next)) {
3393 Consume(next); 3142 Consume(next);
3394 Handle<String> string = GetSymbol(CHECK_OK); 3143 Handle<String> string = GetSymbol(CHECK_OK);
3395 key = NEW(Literal(string)); 3144 key = new Literal(string);
3396 } else { 3145 } else {
3397 // Unexpected token. 3146 // Unexpected token.
3398 Token::Value next = Next(); 3147 Token::Value next = Next();
3399 ReportUnexpectedToken(next); 3148 ReportUnexpectedToken(next);
3400 *ok = false; 3149 *ok = false;
3401 return NULL; 3150 return NULL;
3402 } 3151 }
3403 } 3152 }
3404 3153
3405 Expect(Token::COLON, CHECK_OK); 3154 Expect(Token::COLON, CHECK_OK);
3406 Expression* value = ParseAssignmentExpression(true, CHECK_OK); 3155 Expression* value = ParseAssignmentExpression(true, CHECK_OK);
3407 3156
3408 ObjectLiteral::Property* property = 3157 ObjectLiteral::Property* property =
3409 NEW(ObjectLiteral::Property(key, value)); 3158 new ObjectLiteral::Property(key, value);
3410 3159
3411 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 3160 // Count CONSTANT or COMPUTED properties to maintain the enumeration order.
3412 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; 3161 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++;
3413 properties.Add(property); 3162 properties->Add(property);
3414 3163
3415 // TODO(1240767): Consider allowing trailing comma. 3164 // TODO(1240767): Consider allowing trailing comma.
3416 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); 3165 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
3417 3166
3418 if (fni_ != NULL) { 3167 if (fni_ != NULL) {
3419 fni_->Infer(); 3168 fni_->Infer();
3420 fni_->Leave(); 3169 fni_->Leave();
3421 } 3170 }
3422 } 3171 }
3423 Expect(Token::RBRACE, CHECK_OK); 3172 Expect(Token::RBRACE, CHECK_OK);
3424 // Computation of literal_index must happen before pre parse bailout. 3173 // Computation of literal_index must happen before pre parse bailout.
3425 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 3174 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3426 if (is_pre_parsing_) return NULL;
3427 3175
3428 Handle<FixedArray> constant_properties = 3176 Handle<FixedArray> constant_properties =
3429 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED); 3177 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED);
3430 3178
3431 bool is_simple = true; 3179 bool is_simple = true;
3432 bool fast_elements = true; 3180 bool fast_elements = true;
3433 int depth = 1; 3181 int depth = 1;
3434 BuildObjectLiteralConstantProperties(properties.elements(), 3182 BuildObjectLiteralConstantProperties(properties,
3435 constant_properties, 3183 constant_properties,
3436 &is_simple, 3184 &is_simple,
3437 &fast_elements, 3185 &fast_elements,
3438 &depth); 3186 &depth);
3439 return new ObjectLiteral(constant_properties, 3187 return new ObjectLiteral(constant_properties,
3440 properties.elements(), 3188 properties,
3441 literal_index, 3189 literal_index,
3442 is_simple, 3190 is_simple,
3443 fast_elements, 3191 fast_elements,
3444 depth); 3192 depth);
3445 } 3193 }
3446 3194
3447 3195
3448 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { 3196 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
3449 if (!scanner_.ScanRegExpPattern(seen_equal)) { 3197 if (!scanner_.ScanRegExpPattern(seen_equal)) {
3450 Next(); 3198 Next();
3451 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); 3199 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
3452 *ok = false; 3200 *ok = false;
3453 return NULL; 3201 return NULL;
3454 } 3202 }
3455 3203
3456 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 3204 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3457 3205
3458 if (is_pre_parsing_) {
3459 // If we're preparsing we just do all the parsing stuff without
3460 // building anything.
3461 if (!scanner_.ScanRegExpFlags()) {
3462 Next();
3463 ReportMessage("invalid_regexp_flags", Vector<const char*>::empty());
3464 *ok = false;
3465 return NULL;
3466 }
3467 Next();
3468 return NULL;
3469 }
3470
3471 Handle<String> js_pattern = 3206 Handle<String> js_pattern =
3472 Factory::NewStringFromUtf8(scanner_.next_literal(), TENURED); 3207 Factory::NewStringFromUtf8(scanner_.next_literal(), TENURED);
3473 scanner_.ScanRegExpFlags(); 3208 scanner_.ScanRegExpFlags();
3474 Handle<String> js_flags = 3209 Handle<String> js_flags =
3475 Factory::NewStringFromUtf8(scanner_.next_literal(), TENURED); 3210 Factory::NewStringFromUtf8(scanner_.next_literal(), TENURED);
3476 Next(); 3211 Next();
3477 3212
3478 return new RegExpLiteral(js_pattern, js_flags, literal_index); 3213 return new RegExpLiteral(js_pattern, js_flags, literal_index);
3479 } 3214 }
3480 3215
3481 3216
3482 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { 3217 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
3483 // Arguments :: 3218 // Arguments ::
3484 // '(' (AssignmentExpression)*[','] ')' 3219 // '(' (AssignmentExpression)*[','] ')'
3485 3220
3486 ZoneListWrapper<Expression> result = factory()->NewList<Expression>(4); 3221 ZoneList<Expression*>* result = new ZoneList<Expression*>(4);
3487 Expect(Token::LPAREN, CHECK_OK); 3222 Expect(Token::LPAREN, CHECK_OK);
3488 bool done = (peek() == Token::RPAREN); 3223 bool done = (peek() == Token::RPAREN);
3489 while (!done) { 3224 while (!done) {
3490 Expression* argument = ParseAssignmentExpression(true, CHECK_OK); 3225 Expression* argument = ParseAssignmentExpression(true, CHECK_OK);
3491 result.Add(argument); 3226 result->Add(argument);
3492 done = (peek() == Token::RPAREN); 3227 done = (peek() == Token::RPAREN);
3493 if (!done) Expect(Token::COMMA, CHECK_OK); 3228 if (!done) Expect(Token::COMMA, CHECK_OK);
3494 } 3229 }
3495 Expect(Token::RPAREN, CHECK_OK); 3230 Expect(Token::RPAREN, CHECK_OK);
3496 return result.elements(); 3231 return result;
3497 } 3232 }
3498 3233
3499 3234
3500 FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, 3235 FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
3501 int function_token_position, 3236 int function_token_position,
3502 FunctionLiteralType type, 3237 FunctionLiteralType type,
3503 bool* ok) { 3238 bool* ok) {
3504 // Function :: 3239 // Function ::
3505 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3240 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3506 bool is_named = !var_name.is_null(); 3241 bool is_named = !var_name.is_null();
3507 3242
3508 // The name associated with this function. If it's a function expression, 3243 // The name associated with this function. If it's a function expression,
3509 // this is the actual function name, otherwise this is the name of the 3244 // this is the actual function name, otherwise this is the name of the
3510 // variable declared and initialized with the function (expression). In 3245 // variable declared and initialized with the function (expression). In
3511 // that case, we don't have a function name (it's empty). 3246 // that case, we don't have a function name (it's empty).
3512 Handle<String> name = is_named ? var_name : factory()->EmptySymbol(); 3247 Handle<String> name = is_named ? var_name : Factory::empty_symbol();
3513 // The function name, if any. 3248 // The function name, if any.
3514 Handle<String> function_name = factory()->EmptySymbol(); 3249 Handle<String> function_name = Factory::empty_symbol();
3515 if (is_named && (type == EXPRESSION || type == NESTED)) { 3250 if (is_named && (type == EXPRESSION || type == NESTED)) {
3516 function_name = name; 3251 function_name = name;
3517 } 3252 }
3518 3253
3519 int num_parameters = 0; 3254 int num_parameters = 0;
3520 // Parse function body. 3255 // Parse function body.
3521 { Scope* scope = 3256 { Scope* scope =
3522 factory()->NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); 3257 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
3523 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 3258 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
3524 scope); 3259 scope);
3525 TemporaryScope temp_scope(&this->temp_scope_); 3260 TemporaryScope temp_scope(&this->temp_scope_);
3526 top_scope_->SetScopeName(name); 3261 top_scope_->SetScopeName(name);
3527 3262
3528 // FormalParameterList :: 3263 // FormalParameterList ::
3529 // '(' (Identifier)*[','] ')' 3264 // '(' (Identifier)*[','] ')'
3530 Expect(Token::LPAREN, CHECK_OK); 3265 Expect(Token::LPAREN, CHECK_OK);
3531 int start_pos = scanner_.location().beg_pos; 3266 int start_pos = scanner_.location().beg_pos;
3532 bool done = (peek() == Token::RPAREN); 3267 bool done = (peek() == Token::RPAREN);
3533 while (!done) { 3268 while (!done) {
3534 Handle<String> param_name = ParseIdentifier(CHECK_OK); 3269 Handle<String> param_name = ParseIdentifier(CHECK_OK);
3535 if (!is_pre_parsing_) { 3270 top_scope_->AddParameter(top_scope_->DeclareLocal(param_name,
3536 top_scope_->AddParameter(top_scope_->DeclareLocal(param_name, 3271 Variable::VAR));
3537 Variable::VAR)); 3272 num_parameters++;
3538 num_parameters++;
3539 }
3540 done = (peek() == Token::RPAREN); 3273 done = (peek() == Token::RPAREN);
3541 if (!done) Expect(Token::COMMA, CHECK_OK); 3274 if (!done) Expect(Token::COMMA, CHECK_OK);
3542 } 3275 }
3543 Expect(Token::RPAREN, CHECK_OK); 3276 Expect(Token::RPAREN, CHECK_OK);
3544 3277
3545 Expect(Token::LBRACE, CHECK_OK); 3278 Expect(Token::LBRACE, CHECK_OK);
3546 ZoneListWrapper<Statement> body = factory()->NewList<Statement>(8); 3279 ZoneList<Statement*>* body = new ZoneList<Statement*>(8);
3547 3280
3548 // If we have a named function expression, we add a local variable 3281 // If we have a named function expression, we add a local variable
3549 // declaration to the body of the function with the name of the 3282 // declaration to the body of the function with the name of the
3550 // function and let it refer to the function itself (closure). 3283 // function and let it refer to the function itself (closure).
3551 // NOTE: We create a proxy and resolve it here so that in the 3284 // NOTE: We create a proxy and resolve it here so that in the
3552 // future we can change the AST to only refer to VariableProxies 3285 // future we can change the AST to only refer to VariableProxies
3553 // instead of Variables and Proxis as is the case now. 3286 // instead of Variables and Proxis as is the case now.
3554 if (!is_pre_parsing_ 3287 if (!function_name.is_null() && function_name->length() > 0) {
3555 && !function_name.is_null()
3556 && function_name->length() > 0) {
3557 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); 3288 Variable* fvar = top_scope_->DeclareFunctionVar(function_name);
3558 VariableProxy* fproxy = 3289 VariableProxy* fproxy =
3559 top_scope_->NewUnresolved(function_name, inside_with()); 3290 top_scope_->NewUnresolved(function_name, inside_with());
3560 fproxy->BindTo(fvar); 3291 fproxy->BindTo(fvar);
3561 body.Add(new ExpressionStatement( 3292 body->Add(new ExpressionStatement(
3562 new Assignment(Token::INIT_CONST, fproxy, 3293 new Assignment(Token::INIT_CONST, fproxy,
3563 NEW(ThisFunction()), 3294 new ThisFunction(),
3564 RelocInfo::kNoPosition))); 3295 RelocInfo::kNoPosition)));
3565 } 3296 }
3566 3297
3567 // Determine if the function will be lazily compiled. The mode can 3298 // Determine if the function will be lazily compiled. The mode can
3568 // only be PARSE_LAZILY if the --lazy flag is true. 3299 // only be PARSE_LAZILY if the --lazy flag is true.
3569 bool is_lazily_compiled = 3300 bool is_lazily_compiled =
3570 mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext(); 3301 mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext();
3571 3302
3572 int function_block_pos = scanner_.location().beg_pos; 3303 int function_block_pos = scanner_.location().beg_pos;
3573 int materialized_literal_count; 3304 int materialized_literal_count;
3574 int expected_property_count; 3305 int expected_property_count;
(...skipping 11 matching lines...) Expand all
3586 ReportInvalidPreparseData(name, CHECK_OK); 3317 ReportInvalidPreparseData(name, CHECK_OK);
3587 } 3318 }
3588 Counters::total_preparse_skipped.Increment(end_pos - function_block_pos); 3319 Counters::total_preparse_skipped.Increment(end_pos - function_block_pos);
3589 scanner_.SeekForward(end_pos); 3320 scanner_.SeekForward(end_pos);
3590 materialized_literal_count = entry.literal_count(); 3321 materialized_literal_count = entry.literal_count();
3591 expected_property_count = entry.property_count(); 3322 expected_property_count = entry.property_count();
3592 only_simple_this_property_assignments = false; 3323 only_simple_this_property_assignments = false;
3593 this_property_assignments = Factory::empty_fixed_array(); 3324 this_property_assignments = Factory::empty_fixed_array();
3594 Expect(Token::RBRACE, CHECK_OK); 3325 Expect(Token::RBRACE, CHECK_OK);
3595 } else { 3326 } else {
3596 FunctionEntry entry; 3327 ParseSourceElements(body, Token::RBRACE, CHECK_OK);
3597 { 3328
3598 ConditionalLogPauseScope pause_if(is_lazily_compiled, log());
3599 ParseSourceElements(&body, Token::RBRACE, CHECK_OK);
3600 }
3601 materialized_literal_count = temp_scope.materialized_literal_count(); 3329 materialized_literal_count = temp_scope.materialized_literal_count();
3602 expected_property_count = temp_scope.expected_property_count(); 3330 expected_property_count = temp_scope.expected_property_count();
3603 only_simple_this_property_assignments = 3331 only_simple_this_property_assignments =
3604 temp_scope.only_simple_this_property_assignments(); 3332 temp_scope.only_simple_this_property_assignments();
3605 this_property_assignments = temp_scope.this_property_assignments(); 3333 this_property_assignments = temp_scope.this_property_assignments();
3606 3334
3607 Expect(Token::RBRACE, CHECK_OK); 3335 Expect(Token::RBRACE, CHECK_OK);
3608 end_pos = scanner_.location().end_pos; 3336 end_pos = scanner_.location().end_pos;
3609 if (is_pre_parsing_ && is_lazily_compiled) {
3610 ASSERT(is_pre_parsing_);
3611 log()->LogFunction(function_block_pos, end_pos,
3612 materialized_literal_count,
3613 expected_property_count);
3614 }
3615 } 3337 }
3616 3338
3617 FunctionLiteral* function_literal = 3339 FunctionLiteral* function_literal =
3618 NEW(FunctionLiteral(name, 3340 new FunctionLiteral(name,
3619 top_scope_, 3341 top_scope_,
3620 body.elements(), 3342 body,
3621 materialized_literal_count, 3343 materialized_literal_count,
3622 expected_property_count, 3344 expected_property_count,
3623 only_simple_this_property_assignments, 3345 only_simple_this_property_assignments,
3624 this_property_assignments, 3346 this_property_assignments,
3625 num_parameters, 3347 num_parameters,
3626 start_pos, 3348 start_pos,
3627 end_pos, 3349 end_pos,
3628 function_name->length() > 0, 3350 function_name->length() > 0,
3629 temp_scope.ContainsLoops())); 3351 temp_scope.ContainsLoops());
3630 if (!is_pre_parsing_) { 3352 function_literal->set_function_token_position(function_token_position);
3631 function_literal->set_function_token_position(function_token_position);
3632 }
3633 3353
3634 if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal); 3354 if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal);
3635 return function_literal; 3355 return function_literal;
3636 } 3356 }
3637 } 3357 }
3638 3358
3639 3359
3640 Expression* Parser::ParseV8Intrinsic(bool* ok) { 3360 Expression* Parser::ParseV8Intrinsic(bool* ok) {
3641 // CallRuntime :: 3361 // CallRuntime ::
3642 // '%' Identifier Arguments 3362 // '%' Identifier Arguments
3643 3363
3644 Expect(Token::MOD, CHECK_OK); 3364 Expect(Token::MOD, CHECK_OK);
3645 Handle<String> name = ParseIdentifier(CHECK_OK); 3365 Handle<String> name = ParseIdentifier(CHECK_OK);
3646 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 3366 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
3647 if (is_pre_parsing_) return NULL;
3648 3367
3649 if (extension_ != NULL) { 3368 if (extension_ != NULL) {
3650 // The extension structures are only accessible while parsing the 3369 // The extension structures are only accessible while parsing the
3651 // very first time not when reparsing because of lazy compilation. 3370 // very first time not when reparsing because of lazy compilation.
3652 top_scope_->ForceEagerCompilation(); 3371 top_scope_->ForceEagerCompilation();
3653 } 3372 }
3654 3373
3655 Runtime::Function* function = Runtime::FunctionForSymbol(name); 3374 Runtime::Function* function = Runtime::FunctionForSymbol(name);
3656 3375
3657 // Check for built-in IS_VAR macro. 3376 // Check for built-in IS_VAR macro.
(...skipping 15 matching lines...) Expand all
3673 // Check that the expected number of arguments are being passed. 3392 // Check that the expected number of arguments are being passed.
3674 if (function != NULL && 3393 if (function != NULL &&
3675 function->nargs != -1 && 3394 function->nargs != -1 &&
3676 function->nargs != args->length()) { 3395 function->nargs != args->length()) {
3677 ReportMessage("illegal_access", Vector<const char*>::empty()); 3396 ReportMessage("illegal_access", Vector<const char*>::empty());
3678 *ok = false; 3397 *ok = false;
3679 return NULL; 3398 return NULL;
3680 } 3399 }
3681 3400
3682 // We have a valid intrinsics call or a call to a builtin. 3401 // We have a valid intrinsics call or a call to a builtin.
3683 return NEW(CallRuntime(name, function, args)); 3402 return new CallRuntime(name, function, args);
3684 } 3403 }
3685 3404
3686 3405
3687 void Parser::Consume(Token::Value token) { 3406 void Parser::Consume(Token::Value token) {
3688 Token::Value next = Next(); 3407 Token::Value next = Next();
3689 USE(next); 3408 USE(next);
3690 USE(token); 3409 USE(token);
3691 ASSERT(next == token); 3410 ASSERT(next == token);
3692 } 3411 }
3693 3412
(...skipping 27 matching lines...) Expand all
3721 if (scanner_.has_line_terminator_before_next() || 3440 if (scanner_.has_line_terminator_before_next() ||
3722 tok == Token::RBRACE || 3441 tok == Token::RBRACE ||
3723 tok == Token::EOS) { 3442 tok == Token::EOS) {
3724 return; 3443 return;
3725 } 3444 }
3726 Expect(Token::SEMICOLON, ok); 3445 Expect(Token::SEMICOLON, ok);
3727 } 3446 }
3728 3447
3729 3448
3730 Literal* Parser::GetLiteralUndefined() { 3449 Literal* Parser::GetLiteralUndefined() {
3731 return NEW(Literal(Factory::undefined_value())); 3450 return new Literal(Factory::undefined_value());
3732 } 3451 }
3733 3452
3734 3453
3735 Literal* Parser::GetLiteralTheHole() { 3454 Literal* Parser::GetLiteralTheHole() {
3736 return NEW(Literal(Factory::the_hole_value())); 3455 return new Literal(Factory::the_hole_value());
3737 } 3456 }
3738 3457
3739 3458
3740 Literal* Parser::GetLiteralNumber(double value) { 3459 Literal* Parser::GetLiteralNumber(double value) {
3741 return NewNumberLiteral(value); 3460 return NewNumberLiteral(value);
3742 } 3461 }
3743 3462
3744 3463
3745 Handle<String> Parser::ParseIdentifier(bool* ok) { 3464 Handle<String> Parser::ParseIdentifier(bool* ok) {
3746 Expect(Token::IDENTIFIER, ok); 3465 Expect(Token::IDENTIFIER, ok);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3829 // target stack has been used from the top of the target stack. Add 3548 // target stack has been used from the top of the target stack. Add
3830 // the break target to any TargetCollectors passed on the stack. 3549 // the break target to any TargetCollectors passed on the stack.
3831 for (Target* t = target_stack_; t != stop; t = t->previous()) { 3550 for (Target* t = target_stack_; t != stop; t = t->previous()) {
3832 TargetCollector* collector = t->node()->AsTargetCollector(); 3551 TargetCollector* collector = t->node()->AsTargetCollector();
3833 if (collector != NULL) collector->AddTarget(target); 3552 if (collector != NULL) collector->AddTarget(target);
3834 } 3553 }
3835 } 3554 }
3836 3555
3837 3556
3838 Literal* Parser::NewNumberLiteral(double number) { 3557 Literal* Parser::NewNumberLiteral(double number) {
3839 return NEW(Literal(Factory::NewNumber(number, TENURED))); 3558 return new Literal(Factory::NewNumber(number, TENURED));
3840 } 3559 }
3841 3560
3842 3561
3843 Expression* Parser::NewThrowReferenceError(Handle<String> type) { 3562 Expression* Parser::NewThrowReferenceError(Handle<String> type) {
3844 return NewThrowError(Factory::MakeReferenceError_symbol(), 3563 return NewThrowError(Factory::MakeReferenceError_symbol(),
3845 type, HandleVector<Object>(NULL, 0)); 3564 type, HandleVector<Object>(NULL, 0));
3846 } 3565 }
3847 3566
3848 3567
3849 Expression* Parser::NewThrowSyntaxError(Handle<String> type, 3568 Expression* Parser::NewThrowSyntaxError(Handle<String> type,
(...skipping 11 matching lines...) Expand all
3861 Handle<Object> elements[] = { first, second }; 3580 Handle<Object> elements[] = { first, second };
3862 Vector< Handle<Object> > arguments = 3581 Vector< Handle<Object> > arguments =
3863 HandleVector<Object>(elements, ARRAY_SIZE(elements)); 3582 HandleVector<Object>(elements, ARRAY_SIZE(elements));
3864 return NewThrowError(Factory::MakeTypeError_symbol(), type, arguments); 3583 return NewThrowError(Factory::MakeTypeError_symbol(), type, arguments);
3865 } 3584 }
3866 3585
3867 3586
3868 Expression* Parser::NewThrowError(Handle<String> constructor, 3587 Expression* Parser::NewThrowError(Handle<String> constructor,
3869 Handle<String> type, 3588 Handle<String> type,
3870 Vector< Handle<Object> > arguments) { 3589 Vector< Handle<Object> > arguments) {
3871 if (is_pre_parsing_) return NULL;
3872
3873 int argc = arguments.length(); 3590 int argc = arguments.length();
3874 Handle<JSArray> array = Factory::NewJSArray(argc, TENURED); 3591 Handle<JSArray> array = Factory::NewJSArray(argc, TENURED);
3875 ASSERT(array->IsJSArray() && array->HasFastElements()); 3592 ASSERT(array->IsJSArray() && array->HasFastElements());
3876 for (int i = 0; i < argc; i++) { 3593 for (int i = 0; i < argc; i++) {
3877 Handle<Object> element = arguments[i]; 3594 Handle<Object> element = arguments[i];
3878 if (!element.is_null()) { 3595 if (!element.is_null()) {
3879 // We know this doesn't cause a GC here because we allocated the JSArray 3596 // We know this doesn't cause a GC here because we allocated the JSArray
3880 // large enough. 3597 // large enough.
3881 array->SetFastElement(i, *element)->ToObjectUnchecked(); 3598 array->SetFastElement(i, *element)->ToObjectUnchecked();
3882 } 3599 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
4050 return Factory::NewJSArrayWithElements(fast_elements); 3767 return Factory::NewJSArrayWithElements(fast_elements);
4051 } 3768 }
4052 3769
4053 // ---------------------------------------------------------------------------- 3770 // ----------------------------------------------------------------------------
4054 // Regular expressions 3771 // Regular expressions
4055 3772
4056 3773
4057 RegExpParser::RegExpParser(FlatStringReader* in, 3774 RegExpParser::RegExpParser(FlatStringReader* in,
4058 Handle<String>* error, 3775 Handle<String>* error,
4059 bool multiline) 3776 bool multiline)
4060 : current_(kEndMarker), 3777 : error_(error),
3778 captures_(NULL),
3779 in_(in),
3780 current_(kEndMarker),
3781 next_pos_(0),
3782 capture_count_(0),
4061 has_more_(true), 3783 has_more_(true),
4062 multiline_(multiline), 3784 multiline_(multiline),
4063 next_pos_(0),
4064 in_(in),
4065 error_(error),
4066 simple_(false), 3785 simple_(false),
4067 contains_anchor_(false), 3786 contains_anchor_(false),
4068 captures_(NULL),
4069 is_scanned_for_captures_(false), 3787 is_scanned_for_captures_(false),
4070 capture_count_(0),
4071 failed_(false) { 3788 failed_(false) {
4072 Advance(1); 3789 Advance(1);
4073 } 3790 }
4074 3791
4075 3792
4076 uc32 RegExpParser::Next() { 3793 uc32 RegExpParser::Next() {
4077 if (has_next()) { 3794 if (has_next()) {
4078 return in()->Get(next_pos_); 3795 return in()->Get(next_pos_);
4079 } else { 3796 } else {
4080 return kEndMarker; 3797 return kEndMarker;
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
4917 return result; 4634 return result;
4918 } 4635 }
4919 4636
4920 4637
4921 // Preparse, but only collect data that is immediately useful, 4638 // Preparse, but only collect data that is immediately useful,
4922 // even if the preparser data is only used once. 4639 // even if the preparser data is only used once.
4923 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source, 4640 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source,
4924 unibrow::CharacterStream* stream, 4641 unibrow::CharacterStream* stream,
4925 v8::Extension* extension) { 4642 v8::Extension* extension) {
4926 Handle<Script> no_script; 4643 Handle<Script> no_script;
4644 bool allow_lazy = FLAG_lazy && (extension == NULL);
4645 if (!allow_lazy) {
4646 // Partial preparsing is only about lazily compiled functions.
4647 // If we don't allow lazy compilation, the log data will be empty.
4648 return NULL;
4649 }
4927 preparser::PreParser<Scanner, PartialParserRecorder> parser; 4650 preparser::PreParser<Scanner, PartialParserRecorder> parser;
4928 Scanner scanner; 4651 Scanner scanner;
4929 scanner.Initialize(source, stream, JAVASCRIPT); 4652 scanner.Initialize(source, stream, JAVASCRIPT);
4930 bool allow_lazy = FLAG_lazy && (extension == NULL);
4931 PartialParserRecorder recorder; 4653 PartialParserRecorder recorder;
4932 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) { 4654 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) {
4933 Top::StackOverflow(); 4655 Top::StackOverflow();
4934 return NULL; 4656 return NULL;
4935 } 4657 }
4936 4658
4937 // Extract the accumulated data from the recorder as a single 4659 // Extract the accumulated data from the recorder as a single
4938 // contiguous vector that we are responsible for disposing. 4660 // contiguous vector that we are responsible for disposing.
4939 Vector<unsigned> store = recorder.ExtractData(); 4661 Vector<unsigned> store = recorder.ExtractData();
4940 return new ScriptDataImpl(store); 4662 return new ScriptDataImpl(store);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4981 } 4703 }
4982 return !parser.failed(); 4704 return !parser.failed();
4983 } 4705 }
4984 4706
4985 4707
4986 bool ParserApi::Parse(CompilationInfo* info) { 4708 bool ParserApi::Parse(CompilationInfo* info) {
4987 ASSERT(info->function() == NULL); 4709 ASSERT(info->function() == NULL);
4988 FunctionLiteral* result = NULL; 4710 FunctionLiteral* result = NULL;
4989 Handle<Script> script = info->script(); 4711 Handle<Script> script = info->script();
4990 if (info->is_lazy()) { 4712 if (info->is_lazy()) {
4991 AstBuildingParser parser(script, true, NULL, NULL); 4713 Parser parser(script, true, NULL, NULL);
4992 result = parser.ParseLazy(info->shared_info()); 4714 result = parser.ParseLazy(info->shared_info());
4993 } else { 4715 } else {
4994 bool allow_natives_syntax = 4716 bool allow_natives_syntax =
4995 FLAG_allow_natives_syntax || Bootstrapper::IsActive(); 4717 FLAG_allow_natives_syntax || Bootstrapper::IsActive();
4996 ScriptDataImpl* pre_data = info->pre_parse_data(); 4718 ScriptDataImpl* pre_data = info->pre_parse_data();
4997 AstBuildingParser parser(script, allow_natives_syntax, info->extension(), 4719 Parser parser(script, allow_natives_syntax, info->extension(), pre_data);
4998 pre_data);
4999 if (pre_data != NULL && pre_data->has_error()) { 4720 if (pre_data != NULL && pre_data->has_error()) {
5000 Scanner::Location loc = pre_data->MessageLocation(); 4721 Scanner::Location loc = pre_data->MessageLocation();
5001 const char* message = pre_data->BuildMessage(); 4722 const char* message = pre_data->BuildMessage();
5002 Vector<const char*> args = pre_data->BuildArgs(); 4723 Vector<const char*> args = pre_data->BuildArgs();
5003 parser.ReportMessageAt(loc, message, args); 4724 parser.ReportMessageAt(loc, message, args);
5004 DeleteArray(message); 4725 DeleteArray(message);
5005 for (int i = 0; i < args.length(); i++) { 4726 for (int i = 0; i < args.length(); i++) {
5006 DeleteArray(args[i]); 4727 DeleteArray(args[i]);
5007 } 4728 }
5008 DeleteArray(args.start()); 4729 DeleteArray(args.start());
5009 ASSERT(Top::has_pending_exception()); 4730 ASSERT(Top::has_pending_exception());
5010 } else { 4731 } else {
5011 Handle<String> source = Handle<String>(String::cast(script->source())); 4732 Handle<String> source = Handle<String>(String::cast(script->source()));
5012 result = parser.ParseProgram(source, info->is_global()); 4733 result = parser.ParseProgram(source, info->is_global());
5013 } 4734 }
5014 } 4735 }
5015 4736
5016 info->SetFunction(result); 4737 info->SetFunction(result);
5017 return (result != NULL); 4738 return (result != NULL);
5018 } 4739 }
5019 4740
5020 #undef NEW
5021
5022 } } // namespace v8::internal 4741 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698