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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 2273013002: [modules] Split exports into regular and special, store regular ones in a multimap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: git cl format Created 4 years, 3 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/zone-containers.h ('k') | no next file » | 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 // 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 5834 matching lines...) Expand 10 before | Expand all | Expand 10 after
5845 RunModuleParserSyncTest(context_data, kErrorSources, kError); 5845 RunModuleParserSyncTest(context_data, kErrorSources, kError);
5846 } 5846 }
5847 5847
5848 static void CheckModuleEntry(const i::ModuleDescriptor::ModuleEntry* entry, 5848 static void CheckModuleEntry(const i::ModuleDescriptor::ModuleEntry* entry,
5849 const char* export_name, const char* local_name, const char* import_name, 5849 const char* export_name, const char* local_name, const char* import_name,
5850 const char* module_request) { 5850 const char* module_request) {
5851 CHECK_NOT_NULL(entry); 5851 CHECK_NOT_NULL(entry);
5852 if (export_name == nullptr) { 5852 if (export_name == nullptr) {
5853 CHECK_NULL(entry->export_name); 5853 CHECK_NULL(entry->export_name);
5854 } else { 5854 } else {
5855 entry->export_name->IsOneByteEqualTo(export_name); 5855 CHECK(entry->export_name->IsOneByteEqualTo(export_name));
5856 } 5856 }
5857 if (local_name == nullptr) { 5857 if (local_name == nullptr) {
5858 CHECK_NULL(entry->local_name); 5858 CHECK_NULL(entry->local_name);
5859 } else { 5859 } else {
5860 entry->local_name->IsOneByteEqualTo(local_name); 5860 CHECK(entry->local_name->IsOneByteEqualTo(local_name));
5861 } 5861 }
5862 if (import_name == nullptr) { 5862 if (import_name == nullptr) {
5863 CHECK_NULL(entry->import_name); 5863 CHECK_NULL(entry->import_name);
5864 } else { 5864 } else {
5865 entry->import_name->IsOneByteEqualTo(import_name); 5865 CHECK(entry->import_name->IsOneByteEqualTo(import_name));
5866 } 5866 }
5867 if (module_request == nullptr) { 5867 if (module_request == nullptr) {
5868 CHECK_NULL(entry->module_request); 5868 CHECK_NULL(entry->module_request);
5869 } else { 5869 } else {
5870 entry->module_request->IsOneByteEqualTo(module_request); 5870 CHECK(entry->module_request->IsOneByteEqualTo(module_request));
5871 } 5871 }
5872 } 5872 }
5873 5873
5874 TEST(ModuleParsingInternals) { 5874 TEST(ModuleParsingInternals) {
5875 i::Isolate* isolate = CcTest::i_isolate(); 5875 i::Isolate* isolate = CcTest::i_isolate();
5876 i::Factory* factory = isolate->factory(); 5876 i::Factory* factory = isolate->factory();
5877 v8::HandleScope handles(CcTest::isolate()); 5877 v8::HandleScope handles(CcTest::isolate());
5878 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5878 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5879 v8::Context::Scope context_scope(context); 5879 v8::Context::Scope context_scope(context);
5880 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5880 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
(...skipping 26 matching lines...) Expand all
5907 i::Parser parser(&info); 5907 i::Parser parser(&info);
5908 info.set_module(); 5908 info.set_module();
5909 CHECK(parser.Parse(&info)); 5909 CHECK(parser.Parse(&info));
5910 CHECK(i::Compiler::Analyze(&info)); 5910 CHECK(i::Compiler::Analyze(&info));
5911 i::FunctionLiteral* func = info.literal(); 5911 i::FunctionLiteral* func = info.literal();
5912 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); 5912 i::ModuleScope* module_scope = func->scope()->AsModuleScope();
5913 i::Scope* outer_scope = module_scope->outer_scope(); 5913 i::Scope* outer_scope = module_scope->outer_scope();
5914 CHECK(outer_scope->is_script_scope()); 5914 CHECK(outer_scope->is_script_scope());
5915 CHECK_NULL(outer_scope->outer_scope()); 5915 CHECK_NULL(outer_scope->outer_scope());
5916 CHECK(module_scope->is_module_scope()); 5916 CHECK(module_scope->is_module_scope());
5917 const i::ModuleDescriptor::ModuleEntry* entry;
5917 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations(); 5918 i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
5918 CHECK_EQ(13, declarations->length()); 5919 CHECK_EQ(13, declarations->length());
5919 5920
5920 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); 5921 CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
5921 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET); 5922 CHECK(declarations->at(0)->proxy()->var()->mode() == i::LET);
5922 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init()); 5923 CHECK(declarations->at(0)->proxy()->var()->binding_needs_init());
5923 CHECK(declarations->at(0)->proxy()->var()->location() == 5924 CHECK(declarations->at(0)->proxy()->var()->location() ==
5924 i::VariableLocation::MODULE); 5925 i::VariableLocation::MODULE);
5925 5926
5926 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z")); 5927 CHECK(declarations->at(1)->proxy()->raw_name()->IsOneByteEqualTo("z"));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
5992 5993
5993 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); 5994 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob"));
5994 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); 5995 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST);
5995 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); 5996 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init());
5996 CHECK(declarations->at(12)->proxy()->var()->location() == 5997 CHECK(declarations->at(12)->proxy()->var()->location() ==
5997 i::VariableLocation::MODULE); 5998 i::VariableLocation::MODULE);
5998 5999
5999 i::ModuleDescriptor* descriptor = module_scope->module(); 6000 i::ModuleDescriptor* descriptor = module_scope->module();
6000 CHECK_NOT_NULL(descriptor); 6001 CHECK_NOT_NULL(descriptor);
6001 6002
6002 CHECK_EQ(11, descriptor->exports().length()); 6003 CHECK_EQ(3, descriptor->special_exports().length());
6003 CheckModuleEntry( 6004 CheckModuleEntry(descriptor->special_exports().at(0), "b", nullptr, "a",
6004 descriptor->exports().at(0), "y", "x", nullptr, nullptr); 6005 "m.js");
6005 CheckModuleEntry( 6006 CheckModuleEntry(descriptor->special_exports().at(1), nullptr, nullptr,
6006 descriptor->exports().at(1), "b", nullptr, "a", "m.js"); 6007 nullptr, "p.js");
6007 CheckModuleEntry( 6008 CheckModuleEntry(descriptor->special_exports().at(2), "bb", nullptr, "aa",
6008 descriptor->exports().at(2), nullptr, nullptr, nullptr, "p.js"); 6009 "m.js"); // !!!
6009 CheckModuleEntry( 6010
6010 descriptor->exports().at(3), "foo", "foo", nullptr, nullptr); 6011 CHECK_EQ(8, descriptor->regular_exports().size());
6011 CheckModuleEntry( 6012 entry = descriptor->regular_exports()
6012 descriptor->exports().at(4), "goo", "goo", nullptr, nullptr); 6013 .find(declarations->at(3)->proxy()->raw_name())
6013 CheckModuleEntry( 6014 ->second;
6014 descriptor->exports().at(5), "hoo", "hoo", nullptr, nullptr); 6015 CheckModuleEntry(entry, "foo", "foo", nullptr, nullptr);
6015 CheckModuleEntry( 6016 entry = descriptor->regular_exports()
6016 descriptor->exports().at(6), "joo", "joo", nullptr, nullptr); 6017 .find(declarations->at(4)->proxy()->raw_name())
6017 CheckModuleEntry( 6018 ->second;
6018 descriptor->exports().at(7), "default", "*default*", nullptr, nullptr); 6019 CheckModuleEntry(entry, "goo", "goo", nullptr, nullptr);
6019 CheckModuleEntry( 6020 entry = descriptor->regular_exports()
6020 descriptor->exports().at(8), "bb", nullptr, "aa", "m.js"); // !!! 6021 .find(declarations->at(5)->proxy()->raw_name())
6021 CheckModuleEntry( 6022 ->second;
6022 descriptor->exports().at(9), "x", "x", nullptr, nullptr); 6023 CheckModuleEntry(entry, "hoo", "hoo", nullptr, nullptr);
6023 CheckModuleEntry( 6024 entry = descriptor->regular_exports()
6024 descriptor->exports().at(10), "foob", "foob", nullptr, nullptr); 6025 .find(declarations->at(6)->proxy()->raw_name())
6026 ->second;
6027 CheckModuleEntry(entry, "joo", "joo", nullptr, nullptr);
6028 entry = descriptor->regular_exports()
6029 .find(declarations->at(7)->proxy()->raw_name())
6030 ->second;
6031 CheckModuleEntry(entry, "default", "*default*", nullptr, nullptr);
6032 entry = descriptor->regular_exports()
6033 .find(declarations->at(12)->proxy()->raw_name())
6034 ->second;
6035 CheckModuleEntry(entry, "foob", "foob", nullptr, nullptr);
6036 // TODO(neis): The next lines are terrible. Find a better way.
6037 auto name_x = declarations->at(0)->proxy()->raw_name();
6038 CHECK_EQ(2, descriptor->regular_exports().count(name_x));
6039 auto it = descriptor->regular_exports().equal_range(name_x).first;
6040 entry = it->second;
6041 if (entry->export_name->IsOneByteEqualTo("y")) {
6042 CheckModuleEntry(entry, "y", "x", nullptr, nullptr);
6043 entry = (++it)->second;
6044 CheckModuleEntry(entry, "x", "x", nullptr, nullptr);
6045 } else {
6046 CheckModuleEntry(entry, "x", "x", nullptr, nullptr);
6047 entry = (++it)->second;
6048 CheckModuleEntry(entry, "y", "x", nullptr, nullptr);
6049 }
6025 6050
6026 CHECK_EQ(3, descriptor->special_imports().length()); 6051 CHECK_EQ(3, descriptor->special_imports().length());
6027 CheckModuleEntry( 6052 CheckModuleEntry(
6028 descriptor->special_imports().at(0), nullptr, nullptr, nullptr, "q.js"); 6053 descriptor->special_imports().at(0), nullptr, nullptr, nullptr, "q.js");
6029 CheckModuleEntry( 6054 CheckModuleEntry(
6030 descriptor->special_imports().at(1), nullptr, "loo", nullptr, "bar.js"); 6055 descriptor->special_imports().at(1), nullptr, "loo", nullptr, "bar.js");
6031 CheckModuleEntry( 6056 CheckModuleEntry(
6032 descriptor->special_imports().at(2), nullptr, "foob", nullptr, "bar.js"); 6057 descriptor->special_imports().at(2), nullptr, "foob", nullptr, "bar.js");
6033 6058
6034 CHECK_EQ(4, descriptor->regular_imports().size()); 6059 CHECK_EQ(4, descriptor->regular_imports().size());
6035 const i::ModuleDescriptor::ModuleEntry* entry;
6036 entry = descriptor->regular_imports().find( 6060 entry = descriptor->regular_imports().find(
6037 declarations->at(1)->proxy()->raw_name())->second; 6061 declarations->at(1)->proxy()->raw_name())->second;
6038 CheckModuleEntry(entry, nullptr, "z", "q", "m.js"); 6062 CheckModuleEntry(entry, nullptr, "z", "q", "m.js");
6039 entry = descriptor->regular_imports().find( 6063 entry = descriptor->regular_imports().find(
6040 declarations->at(2)->proxy()->raw_name())->second; 6064 declarations->at(2)->proxy()->raw_name())->second;
6041 CheckModuleEntry(entry, nullptr, "n", "default", "n.js"); 6065 CheckModuleEntry(entry, nullptr, "n", "default", "n.js");
6042 entry = descriptor->regular_imports().find( 6066 entry = descriptor->regular_imports().find(
6043 declarations->at(9)->proxy()->raw_name())->second; 6067 declarations->at(9)->proxy()->raw_name())->second;
6044 CheckModuleEntry(entry, nullptr, "mm", "m", "m.js"); 6068 CheckModuleEntry(entry, nullptr, "mm", "m", "m.js");
6045 entry = descriptor->regular_imports().find( 6069 entry = descriptor->regular_imports().find(
(...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after
8151 "(a,);", 8175 "(a,);",
8152 "(a,b,c,);", 8176 "(a,b,c,);",
8153 NULL 8177 NULL
8154 }; 8178 };
8155 // clang-format on 8179 // clang-format on
8156 8180
8157 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 8181 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
8158 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 8182 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
8159 arraysize(always_flags)); 8183 arraysize(always_flags));
8160 } 8184 }
OLDNEW
« no previous file with comments | « src/zone-containers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698