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: fix 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
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.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 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::EXPORT) {
968 return factory()->NewEmptyStatement(kNoSourcePosition); 969 return ParseExportDeclaration(ok);
969 case Token::EXPORT:
970 return ParseExportDeclaration(ok);
971 default:
972 return ParseStatementListItem(ok);
973 } 970 }
971
972 // We must be careful not to parse a dynamic import expression as an import
973 // declaration.
974 if (next == Token::IMPORT &&
975 (!allow_harmony_dynamic_import() || PeekAhead() != Token::LPAREN)) {
976 ParseImportDeclaration(CHECK_OK);
977 return factory()->NewEmptyStatement(kNoSourcePosition);
978 }
979
980 return ParseStatementListItem(ok);
974 } 981 }
975 982
976 983
977 void Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) { 984 void Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
978 // ecma262/#prod-Module 985 // ecma262/#prod-Module
979 // Module : 986 // Module :
980 // ModuleBody? 987 // ModuleBody?
981 // 988 //
982 // ecma262/#prod-ModuleItemList 989 // ecma262/#prod-ModuleItemList
983 // ModuleBody : 990 // ModuleBody :
(...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 reusable_preparser_ = new PreParser( 2792 reusable_preparser_ = new PreParser(
2786 zone(), &scanner_, stack_limit_, ast_value_factory(), 2793 zone(), &scanner_, stack_limit_, ast_value_factory(),
2787 &pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_); 2794 &pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_);
2788 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 2795 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
2789 SET_ALLOW(natives); 2796 SET_ALLOW(natives);
2790 SET_ALLOW(harmony_do_expressions); 2797 SET_ALLOW(harmony_do_expressions);
2791 SET_ALLOW(harmony_function_sent); 2798 SET_ALLOW(harmony_function_sent);
2792 SET_ALLOW(harmony_trailing_commas); 2799 SET_ALLOW(harmony_trailing_commas);
2793 SET_ALLOW(harmony_class_fields); 2800 SET_ALLOW(harmony_class_fields);
2794 SET_ALLOW(harmony_object_rest_spread); 2801 SET_ALLOW(harmony_object_rest_spread);
2802 SET_ALLOW(harmony_dynamic_import);
2795 #undef SET_ALLOW 2803 #undef SET_ALLOW
2796 } 2804 }
2797 // Aborting inner function preparsing would leave scopes in an inconsistent 2805 // Aborting inner function preparsing would leave scopes in an inconsistent
2798 // state; we don't parse inner functions in the abortable mode anyway. 2806 // state; we don't parse inner functions in the abortable mode anyway.
2799 DCHECK(!is_inner_function || !may_abort); 2807 DCHECK(!is_inner_function || !may_abort);
2800 2808
2801 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( 2809 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction(
2802 kind, function_scope, parsing_module_, is_inner_function, may_abort, 2810 kind, function_scope, parsing_module_, is_inner_function, may_abort,
2803 use_counts_); 2811 use_counts_);
2804 2812
(...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after
5021 5029
5022 return final_loop; 5030 return final_loop;
5023 } 5031 }
5024 5032
5025 #undef CHECK_OK 5033 #undef CHECK_OK
5026 #undef CHECK_OK_VOID 5034 #undef CHECK_OK_VOID
5027 #undef CHECK_FAILED 5035 #undef CHECK_FAILED
5028 5036
5029 } // namespace internal 5037 } // namespace internal
5030 } // namespace v8 5038 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698