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/parsing/parser.cc

Issue 2661933003: [ESnext] Parse dynamic import expression (Closed)
Patch Set: review fixes Created 3 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 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 info->extension() == nullptr && can_compile_lazily; 546 info->extension() == nullptr && can_compile_lazily;
547 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); 547 set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
548 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && 548 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() &&
549 info->isolate()->is_tail_call_elimination_enabled()); 549 info->isolate()->is_tail_call_elimination_enabled());
550 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); 550 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
551 set_allow_harmony_function_sent(FLAG_harmony_function_sent); 551 set_allow_harmony_function_sent(FLAG_harmony_function_sent);
552 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); 552 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators);
553 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); 553 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas);
554 set_allow_harmony_class_fields(FLAG_harmony_class_fields); 554 set_allow_harmony_class_fields(FLAG_harmony_class_fields);
555 set_allow_harmony_object_rest_spread(FLAG_harmony_object_rest_spread); 555 set_allow_harmony_object_rest_spread(FLAG_harmony_object_rest_spread);
556 set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import);
556 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 557 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
557 ++feature) { 558 ++feature) {
558 use_counts_[feature] = 0; 559 use_counts_[feature] = 0;
559 } 560 }
560 if (info->ast_value_factory() == NULL) { 561 if (info->ast_value_factory() == NULL) {
561 // info takes ownership of AstValueFactory. 562 // info takes ownership of AstValueFactory.
562 info->set_ast_value_factory(new AstValueFactory( 563 info->set_ast_value_factory(new AstValueFactory(
563 zone(), info->isolate()->ast_string_constants(), info->hash_seed())); 564 zone(), info->isolate()->ast_string_constants(), info->hash_seed()));
564 info->set_ast_value_factory_owned(); 565 info->set_ast_value_factory_owned();
565 ast_value_factory_ = info->ast_value_factory(); 566 ast_value_factory_ = info->ast_value_factory();
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 return result; 956 return result;
956 } 957 }
957 958
958 Statement* Parser::ParseModuleItem(bool* ok) { 959 Statement* Parser::ParseModuleItem(bool* ok) {
959 // ecma262/#prod-ModuleItem 960 // ecma262/#prod-ModuleItem
960 // ModuleItem : 961 // ModuleItem :
961 // ImportDeclaration 962 // ImportDeclaration
962 // ExportDeclaration 963 // ExportDeclaration
963 // StatementListItem 964 // StatementListItem
964 965
965 switch (peek()) { 966 Token::Value next = peek();
966 case Token::IMPORT: 967
967 ParseImportDeclaration(CHECK_OK); 968 if (next == Token::IMPORT) {
968 return factory()->NewEmptyStatement(kNoSourcePosition); 969 // This makes sure we don't parse a dynamic import expression as
969 case Token::EXPORT: 970 // an import declaration.
970 return ParseExportDeclaration(ok); 971 if (allow_harmony_dynamic_import() && PeekAhead() == Token::LPAREN) {
971 default:
972 return ParseStatementListItem(ok); 972 return ParseStatementListItem(ok);
973 }
974
975 ParseImportDeclaration(CHECK_OK);
976 return factory()->NewEmptyStatement(kNoSourcePosition);
973 } 977 }
978
979 if (next == Token::EXPORT) {
980 return ParseExportDeclaration(ok);
981 }
982
983 return ParseStatementListItem(ok);
974 } 984 }
neis 2017/01/31 10:47:57 Nit: I find this version a little nicer as it does
gsathya 2017/01/31 18:26:07 I did this initially and found the if conditional
975 985
976 986
977 void Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) { 987 void Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
978 // ecma262/#prod-Module 988 // ecma262/#prod-Module
979 // Module : 989 // Module :
980 // ModuleBody? 990 // ModuleBody?
981 // 991 //
982 // ecma262/#prod-ModuleItemList 992 // ecma262/#prod-ModuleItemList
983 // ModuleBody : 993 // ModuleBody :
984 // ModuleItem* 994 // ModuleItem*
(...skipping 1800 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 reusable_preparser_ = new PreParser( 2795 reusable_preparser_ = new PreParser(
2786 zone(), &scanner_, stack_limit_, ast_value_factory(), 2796 zone(), &scanner_, stack_limit_, ast_value_factory(),
2787 &pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_); 2797 &pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_);
2788 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 2798 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
2789 SET_ALLOW(natives); 2799 SET_ALLOW(natives);
2790 SET_ALLOW(harmony_do_expressions); 2800 SET_ALLOW(harmony_do_expressions);
2791 SET_ALLOW(harmony_function_sent); 2801 SET_ALLOW(harmony_function_sent);
2792 SET_ALLOW(harmony_trailing_commas); 2802 SET_ALLOW(harmony_trailing_commas);
2793 SET_ALLOW(harmony_class_fields); 2803 SET_ALLOW(harmony_class_fields);
2794 SET_ALLOW(harmony_object_rest_spread); 2804 SET_ALLOW(harmony_object_rest_spread);
2805 SET_ALLOW(harmony_dynamic_import);
2795 #undef SET_ALLOW 2806 #undef SET_ALLOW
2796 } 2807 }
2797 // Aborting inner function preparsing would leave scopes in an inconsistent 2808 // Aborting inner function preparsing would leave scopes in an inconsistent
2798 // state; we don't parse inner functions in the abortable mode anyway. 2809 // state; we don't parse inner functions in the abortable mode anyway.
2799 DCHECK(!is_inner_function || !may_abort); 2810 DCHECK(!is_inner_function || !may_abort);
2800 2811
2801 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( 2812 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction(
2802 kind, function_scope, parsing_module_, is_inner_function, may_abort, 2813 kind, function_scope, parsing_module_, is_inner_function, may_abort,
2803 use_counts_); 2814 use_counts_);
2804 2815
(...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after
5021 5032
5022 return final_loop; 5033 return final_loop;
5023 } 5034 }
5024 5035
5025 #undef CHECK_OK 5036 #undef CHECK_OK
5026 #undef CHECK_OK_VOID 5037 #undef CHECK_OK_VOID
5027 #undef CHECK_FAILED 5038 #undef CHECK_FAILED
5028 5039
5029 } // namespace internal 5040 } // namespace internal
5030 } // namespace v8 5041 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698