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

Side by Side Diff: src/parser.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: 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
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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 // Parses the source code represented by the compilation info and sets its 655 // Parses the source code represented by the compilation info and sets its
656 // function literal. Returns false (and deallocates any allocated AST 656 // function literal. Returns false (and deallocates any allocated AST
657 // nodes) if parsing failed. 657 // nodes) if parsing failed.
658 static bool Parse(CompilationInfo* info, 658 static bool Parse(CompilationInfo* info,
659 bool allow_lazy = false) { 659 bool allow_lazy = false) {
660 ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(), 660 ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(),
661 info->isolate()->heap()->HashSeed(), 661 info->isolate()->heap()->HashSeed(),
662 info->isolate()->unicode_cache()}; 662 info->isolate()->unicode_cache()};
663 Parser parser(info, &parse_info); 663 Parser parser(info, &parse_info);
664 parser.set_allow_lazy(allow_lazy); 664 parser.set_allow_lazy(allow_lazy);
665 if (parser.Parse()) { 665 if (parser.ParseOnMainThread(info)) {
666 info->SetLanguageMode(info->function()->language_mode()); 666 info->SetLanguageMode(info->function()->language_mode());
667 return true; 667 return true;
668 } 668 }
669 return false; 669 return false;
670 } 670 }
671 bool Parse(); 671 bool ParseOnMainThread(CompilationInfo* info);
672 void ParseOnBackground(); 672 void ParseOnBackground(CompilationInfo* info);
673 673
674 // Handle errors detected during parsing, move statistics to Isolate, 674 // Handle errors detected during parsing, move statistics to Isolate,
675 // internalize strings (move them to the heap). 675 // internalize strings (move them to the heap).
676 void Internalize(); 676 void Internalize(CompilationInfo* info);
677 void HandleSourceURLComments(); 677 void HandleSourceURLComments(CompilationInfo* info);
678 678
679 private: 679 private:
680 friend class ParserTraits; 680 friend class ParserTraits;
681 681
682 // Limit the allowed number of local variables in a function. The hard limit 682 // Limit the allowed number of local variables in a function. The hard limit
683 // is that offsets computed by FullCodeGenerator::StackOperand and similar 683 // is that offsets computed by FullCodeGenerator::StackOperand and similar
684 // functions are ints, and they should not overflow. In addition, accessing 684 // functions are ints, and they should not overflow. In addition, accessing
685 // local variables creates user-controlled constants in the generated code, 685 // local variables creates user-controlled constants in the generated code,
686 // and we don't want too much user-controlled memory inside the code (this was 686 // and we don't want too much user-controlled memory inside the code (this was
687 // the reason why this limit was introduced in the first place; see 687 // the reason why this limit was introduced in the first place; see
688 // https://codereview.chromium.org/7003030/ ). 688 // https://codereview.chromium.org/7003030/ ).
689 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1 689 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1
690 690
691 enum VariableDeclarationContext { 691 enum VariableDeclarationContext {
692 kStatementListItem, 692 kStatementListItem,
693 kStatement, 693 kStatement,
694 kForStatement 694 kForStatement
695 }; 695 };
696 696
697 // If a list of variable declarations includes any initializers. 697 // If a list of variable declarations includes any initializers.
698 enum VariableDeclarationProperties { 698 enum VariableDeclarationProperties {
699 kHasInitializers, 699 kHasInitializers,
700 kHasNoInitializers 700 kHasNoInitializers
701 }; 701 };
702 702
703 // Returns NULL if parsing failed. 703 // Returns NULL if parsing failed.
704 FunctionLiteral* ParseProgram(); 704 FunctionLiteral* ParseProgram(CompilationInfo* info);
705 705
706 FunctionLiteral* ParseLazy(); 706 FunctionLiteral* ParseLazy(CompilationInfo* info);
707 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); 707 FunctionLiteral* ParseLazy(CompilationInfo* info,
708 708 Utf16CharacterStream* source);
709 Isolate* isolate() { return info_->isolate(); }
710 CompilationInfo* info() const { return info_; }
711 Handle<Script> script() const { return info_->script(); }
712 709
713 // Called by ParseProgram after setting up the scanner. 710 // Called by ParseProgram after setting up the scanner.
714 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope, 711 FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope,
715 Scope** ad_hoc_eval_scope); 712 Scope** ad_hoc_eval_scope);
716 713
717 void SetCachedData(); 714 void SetCachedData(CompilationInfo* info);
718 715
719 bool inside_with() const { return scope_->inside_with(); } 716 bool inside_with() const { return scope_->inside_with(); }
720 ScriptCompiler::CompileOptions compile_options() const { 717 ScriptCompiler::CompileOptions compile_options() const {
721 return info_->compile_options(); 718 return compile_options_;
722 } 719 }
723 bool consume_cached_parse_data() const { 720 bool consume_cached_parse_data() const {
724 return compile_options() == ScriptCompiler::kConsumeParserCache && 721 return compile_options_ == ScriptCompiler::kConsumeParserCache &&
725 cached_parse_data_ != NULL; 722 cached_parse_data_ != NULL;
726 } 723 }
727 bool produce_cached_parse_data() const { 724 bool produce_cached_parse_data() const {
728 return compile_options() == ScriptCompiler::kProduceParserCache; 725 return compile_options_ == ScriptCompiler::kProduceParserCache;
729 } 726 }
730 Scope* DeclarationScope(VariableMode mode) { 727 Scope* DeclarationScope(VariableMode mode) {
731 return IsLexicalVariableMode(mode) 728 return IsLexicalVariableMode(mode)
732 ? scope_ : scope_->DeclarationScope(); 729 ? scope_ : scope_->DeclarationScope();
733 } 730 }
734 731
735 // All ParseXXX functions take as the last argument an *ok parameter 732 // All ParseXXX functions take as the last argument an *ok parameter
736 // which is set to false if parsing failed; it is unchanged otherwise. 733 // which is set to false if parsing failed; it is unchanged otherwise.
737 // By making the 'exception handling' explicit, we are forced to check 734 // By making the 'exception handling' explicit, we are forced to check
738 // for failure at the call sites. 735 // for failure at the call sites.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 bool* ok); 849 bool* ok);
853 850
854 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser( 851 PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser(
855 SingletonLogger* logger); 852 SingletonLogger* logger);
856 853
857 // Consumes the ending }. 854 // Consumes the ending }.
858 ZoneList<Statement*>* ParseEagerFunctionBody( 855 ZoneList<Statement*>* ParseEagerFunctionBody(
859 const AstRawString* function_name, int pos, Variable* fvar, 856 const AstRawString* function_name, int pos, Variable* fvar,
860 Token::Value fvar_init_op, FunctionKind kind, bool* ok); 857 Token::Value fvar_init_op, FunctionKind kind, bool* ok);
861 858
862 void ThrowPendingError(); 859 void ThrowPendingError(Isolate* isolate, Handle<Script> script);
863 860
864 TemplateLiteralState OpenTemplateLiteral(int pos); 861 TemplateLiteralState OpenTemplateLiteral(int pos);
865 void AddTemplateSpan(TemplateLiteralState* state, bool tail); 862 void AddTemplateSpan(TemplateLiteralState* state, bool tail);
866 void AddTemplateExpression(TemplateLiteralState* state, 863 void AddTemplateExpression(TemplateLiteralState* state,
867 Expression* expression); 864 Expression* expression);
868 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, 865 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
869 Expression* tag); 866 Expression* tag);
870 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); 867 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
871 868
872 Scanner scanner_; 869 Scanner scanner_;
873 PreParser* reusable_preparser_; 870 PreParser* reusable_preparser_;
874 Scope* original_scope_; // for ES5 function declarations in sloppy eval 871 Scope* original_scope_; // for ES5 function declarations in sloppy eval
875 Target* target_stack_; // for break, continue statements 872 Target* target_stack_; // for break, continue statements
873 ScriptCompiler::CompileOptions compile_options_;
876 ParseData* cached_parse_data_; 874 ParseData* cached_parse_data_;
877 875
878 CompilationInfo* info_;
879 bool parsing_lazy_arrow_parameters_; // for lazily parsed arrow functions. 876 bool parsing_lazy_arrow_parameters_; // for lazily parsed arrow functions.
880 877
881 // Pending errors. 878 // Pending errors.
882 bool has_pending_error_; 879 bool has_pending_error_;
883 Scanner::Location pending_error_location_; 880 Scanner::Location pending_error_location_;
884 const char* pending_error_message_; 881 const char* pending_error_message_;
885 const AstRawString* pending_error_arg_; 882 const AstRawString* pending_error_arg_;
886 const char* pending_error_char_arg_; 883 const char* pending_error_char_arg_;
887 bool pending_error_is_reference_error_; 884 bool pending_error_is_reference_error_;
888 885
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 } 975 }
979 976
980 977
981 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, 978 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state,
982 int start, Expression* tag) { 979 int start, Expression* tag) {
983 return parser_->CloseTemplateLiteral(state, start, tag); 980 return parser_->CloseTemplateLiteral(state, start, tag);
984 } 981 }
985 } } // namespace v8::internal 982 } } // namespace v8::internal
986 983
987 #endif // V8_PARSER_H_ 984 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/background-parsing-task.cc ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698