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

Side by Side Diff: src/parser.h

Issue 908173003: Parsing: Make Parser not know about Isolate during background parsing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: main thread check Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler.cc ('k') | src/parser.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSER_H_ 5 #ifndef V8_PARSER_H_
6 #define V8_PARSER_H_ 6 #define V8_PARSER_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/compiler.h" // For CachedDataMode 10 #include "src/compiler.h" // For CachedDataMode
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 ~Parser() { 640 ~Parser() {
641 delete reusable_preparser_; 641 delete reusable_preparser_;
642 reusable_preparser_ = NULL; 642 reusable_preparser_ = NULL;
643 delete cached_parse_data_; 643 delete cached_parse_data_;
644 cached_parse_data_ = NULL; 644 cached_parse_data_ = NULL;
645 } 645 }
646 646
647 // Parses the source code represented by the compilation info and sets its 647 // Parses the source code represented by the compilation info and sets its
648 // function literal. Returns false (and deallocates any allocated AST 648 // function literal. Returns false (and deallocates any allocated AST
649 // nodes) if parsing failed. 649 // nodes) if parsing failed.
650 static bool Parse(CompilationInfo* info, bool allow_lazy = false); 650 static bool ParseStatic(CompilationInfo* info, bool allow_lazy = false);
651 bool Parse(); 651 bool Parse(CompilationInfo* info);
652 void ParseOnBackground(); 652 void ParseOnBackground(CompilationInfo* info);
653 653
654 // Handle errors detected during parsing, move statistics to Isolate, 654 // Handle errors detected during parsing, move statistics to Isolate,
655 // internalize strings (move them to the heap). 655 // internalize strings (move them to the heap).
656 void Internalize(); 656 void Internalize(CompilationInfo* info);
657 void HandleSourceURLComments(); 657 void HandleSourceURLComments(CompilationInfo* info);
658 658
659 private: 659 private:
660 friend class ParserTraits; 660 friend class ParserTraits;
661 661
662 // Limit the allowed number of local variables in a function. The hard limit 662 // Limit the allowed number of local variables in a function. The hard limit
663 // is that offsets computed by FullCodeGenerator::StackOperand and similar 663 // is that offsets computed by FullCodeGenerator::StackOperand and similar
664 // functions are ints, and they should not overflow. In addition, accessing 664 // functions are ints, and they should not overflow. In addition, accessing
665 // local variables creates user-controlled constants in the generated code, 665 // local variables creates user-controlled constants in the generated code,
666 // and we don't want too much user-controlled memory inside the code (this was 666 // and we don't want too much user-controlled memory inside the code (this was
667 // the reason why this limit was introduced in the first place; see 667 // the reason why this limit was introduced in the first place; see
668 // https://codereview.chromium.org/7003030/ ). 668 // https://codereview.chromium.org/7003030/ ).
669 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1 669 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1
670 670
671 enum VariableDeclarationContext { 671 enum VariableDeclarationContext {
672 kStatementListItem, 672 kStatementListItem,
673 kStatement, 673 kStatement,
674 kForStatement 674 kForStatement
675 }; 675 };
676 676
677 // If a list of variable declarations includes any initializers. 677 // If a list of variable declarations includes any initializers.
678 enum VariableDeclarationProperties { 678 enum VariableDeclarationProperties {
679 kHasInitializers, 679 kHasInitializers,
680 kHasNoInitializers 680 kHasNoInitializers
681 }; 681 };
682 682
683 // Returns NULL if parsing failed. 683 // Returns NULL if parsing failed.
684 FunctionLiteral* ParseProgram(); 684 FunctionLiteral* ParseProgram(CompilationInfo* info);
685 685
686 FunctionLiteral* ParseLazy(); 686 FunctionLiteral* ParseLazy(CompilationInfo* info);
687 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); 687 FunctionLiteral* ParseLazy(CompilationInfo* info,
688 688 Utf16CharacterStream* source);
689 Isolate* isolate() { return info_->isolate(); }
690 CompilationInfo* info() const { return info_; }
691 Handle<Script> script() const { return info_->script(); }
692 689
693 // Called by ParseProgram after setting up the scanner. 690 // Called by ParseProgram after setting up the scanner.
694 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, 691 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope,
695 Scope** ad_hoc_eval_scope); 692 Scope** ad_hoc_eval_scope);
696 693
697 void SetCachedData(); 694 void SetCachedData(CompilationInfo* info);
698 695
699 bool inside_with() const { return scope_->inside_with(); } 696 bool inside_with() const { return scope_->inside_with(); }
700 ScriptCompiler::CompileOptions compile_options() const { 697 ScriptCompiler::CompileOptions compile_options() const {
701 return info_->compile_options(); 698 return compile_options_;
702 } 699 }
703 bool consume_cached_parse_data() const { 700 bool consume_cached_parse_data() const {
704 return compile_options() == ScriptCompiler::kConsumeParserCache && 701 return compile_options_ == ScriptCompiler::kConsumeParserCache &&
705 cached_parse_data_ != NULL; 702 cached_parse_data_ != NULL;
706 } 703 }
707 bool produce_cached_parse_data() const { 704 bool produce_cached_parse_data() const {
708 return compile_options() == ScriptCompiler::kProduceParserCache; 705 return compile_options_ == ScriptCompiler::kProduceParserCache;
709 } 706 }
710 Scope* DeclarationScope(VariableMode mode) { 707 Scope* DeclarationScope(VariableMode mode) {
711 return IsLexicalVariableMode(mode) 708 return IsLexicalVariableMode(mode)
712 ? scope_ : scope_->DeclarationScope(); 709 ? scope_ : scope_->DeclarationScope();
713 } 710 }
714 711
715 // All ParseXXX functions take as the last argument an *ok parameter 712 // All ParseXXX functions take as the last argument an *ok parameter
716 // which is set to false if parsing failed; it is unchanged otherwise. 713 // which is set to false if parsing failed; it is unchanged otherwise.
717 // By making the 'exception handling' explicit, we are forced to check 714 // By making the 'exception handling' explicit, we are forced to check
718 // for failure at the call sites. 715 // for failure at the call sites.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 bool* ok); 831 bool* ok);
835 832
836 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( 833 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser(
837 SingletonLogger* logger); 834 SingletonLogger* logger);
838 835
839 // Consumes the ending }. 836 // Consumes the ending }.
840 ZoneList<Statement*>* ParseEagerFunctionBody( 837 ZoneList<Statement*>* ParseEagerFunctionBody(
841 const AstRawString* function_name, int pos, Variable* fvar, 838 const AstRawString* function_name, int pos, Variable* fvar,
842 Token::Value fvar_init_op, FunctionKind kind, bool* ok); 839 Token::Value fvar_init_op, FunctionKind kind, bool* ok);
843 840
844 void ThrowPendingError(); 841 void ThrowPendingError(Isolate* isolate, Handle<Script> script);
845 842
846 TemplateLiteralState OpenTemplateLiteral(int pos); 843 TemplateLiteralState OpenTemplateLiteral(int pos);
847 void AddTemplateSpan(TemplateLiteralState* state, bool tail); 844 void AddTemplateSpan(TemplateLiteralState* state, bool tail);
848 void AddTemplateExpression(TemplateLiteralState* state, 845 void AddTemplateExpression(TemplateLiteralState* state,
849 Expression* expression); 846 Expression* expression);
850 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, 847 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
851 Expression* tag); 848 Expression* tag);
852 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); 849 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
853 850
854 Scanner scanner_; 851 Scanner scanner_;
855 PreParser* reusable_preparser_; 852 PreParser* reusable_preparser_;
856 Scope* original_scope_; // for ES5 function declarations in sloppy eval 853 Scope* original_scope_; // for ES5 function declarations in sloppy eval
857 Target* target_stack_; // for break, continue statements 854 Target* target_stack_; // for break, continue statements
855 ScriptCompiler::CompileOptions compile_options_;
858 ParseData* cached_parse_data_; 856 ParseData* cached_parse_data_;
859 857
860 CompilationInfo* info_;
861 bool parsing_lazy_arrow_parameters_; // for lazily parsed arrow functions. 858 bool parsing_lazy_arrow_parameters_; // for lazily parsed arrow functions.
862 859
863 // Pending errors. 860 // Pending errors.
864 bool has_pending_error_; 861 bool has_pending_error_;
865 Scanner::Location pending_error_location_; 862 Scanner::Location pending_error_location_;
866 const char* pending_error_message_; 863 const char* pending_error_message_;
867 const AstRawString* pending_error_arg_; 864 const AstRawString* pending_error_arg_;
868 const char* pending_error_char_arg_; 865 const char* pending_error_char_arg_;
869 bool pending_error_is_reference_error_; 866 bool pending_error_is_reference_error_;
870 867
871 // Other information which will be stored in Parser and moved to Isolate after 868 // Other information which will be stored in Parser and moved to Isolate after
872 // parsing. 869 // parsing.
873 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; 870 int use_counts_[v8::Isolate::kUseCounterFeatureCount];
874 int total_preparse_skipped_; 871 int total_preparse_skipped_;
875 HistogramTimer* pre_parse_timer_; 872 HistogramTimer* pre_parse_timer_;
873
874 bool parsing_on_main_thread_;
876 }; 875 };
877 876
878 877
879 bool ParserTraits::IsFutureStrictReserved( 878 bool ParserTraits::IsFutureStrictReserved(
880 const AstRawString* identifier) const { 879 const AstRawString* identifier) const {
881 return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); 880 return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
882 } 881 }
883 882
884 883
885 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type, 884 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 } 959 }
961 960
962 961
963 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, 962 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state,
964 int start, Expression* tag) { 963 int start, Expression* tag) {
965 return parser_->CloseTemplateLiteral(state, start, tag); 964 return parser_->CloseTemplateLiteral(state, start, tag);
966 } 965 }
967 } } // namespace v8::internal 966 } } // namespace v8::internal
968 967
969 #endif // V8_PARSER_H_ 968 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698