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

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

Issue 2353633002: [modules] Explicitly keep track of module requests. (Closed)
Patch Set: Address comments. 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/objects-inl.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 5944 matching lines...) Expand 10 before | Expand all | Expand 10 after
5955 NULL 5955 NULL
5956 }; 5956 };
5957 // clang-format on 5957 // clang-format on
5958 const char* context_data[][2] = {{"", ""}, {NULL, NULL}}; 5958 const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
5959 5959
5960 RunModuleParserSyncTest(context_data, kErrorSources, kError); 5960 RunModuleParserSyncTest(context_data, kErrorSources, kError);
5961 } 5961 }
5962 5962
5963 static void CheckEntry(const i::ModuleDescriptor::Entry* entry, 5963 static void CheckEntry(const i::ModuleDescriptor::Entry* entry,
5964 const char* export_name, const char* local_name, 5964 const char* export_name, const char* local_name,
5965 const char* import_name, const char* module_request) { 5965 const char* import_name, int module_request) {
5966 CHECK_NOT_NULL(entry); 5966 CHECK_NOT_NULL(entry);
5967 if (export_name == nullptr) { 5967 if (export_name == nullptr) {
5968 CHECK_NULL(entry->export_name); 5968 CHECK_NULL(entry->export_name);
5969 } else { 5969 } else {
5970 CHECK(entry->export_name->IsOneByteEqualTo(export_name)); 5970 CHECK(entry->export_name->IsOneByteEqualTo(export_name));
5971 } 5971 }
5972 if (local_name == nullptr) { 5972 if (local_name == nullptr) {
5973 CHECK_NULL(entry->local_name); 5973 CHECK_NULL(entry->local_name);
5974 } else { 5974 } else {
5975 CHECK(entry->local_name->IsOneByteEqualTo(local_name)); 5975 CHECK(entry->local_name->IsOneByteEqualTo(local_name));
5976 } 5976 }
5977 if (import_name == nullptr) { 5977 if (import_name == nullptr) {
5978 CHECK_NULL(entry->import_name); 5978 CHECK_NULL(entry->import_name);
5979 } else { 5979 } else {
5980 CHECK(entry->import_name->IsOneByteEqualTo(import_name)); 5980 CHECK(entry->import_name->IsOneByteEqualTo(import_name));
5981 } 5981 }
5982 if (module_request == nullptr) { 5982 CHECK_EQ(entry->module_request, module_request);
5983 CHECK_NULL(entry->module_request);
5984 } else {
5985 CHECK(entry->module_request->IsOneByteEqualTo(module_request));
5986 }
5987 } 5983 }
5988 5984
5989 TEST(ModuleParsingInternals) { 5985 TEST(ModuleParsingInternals) {
5990 i::Isolate* isolate = CcTest::i_isolate(); 5986 i::Isolate* isolate = CcTest::i_isolate();
5991 i::Factory* factory = isolate->factory(); 5987 i::Factory* factory = isolate->factory();
5992 v8::HandleScope handles(CcTest::isolate()); 5988 v8::HandleScope handles(CcTest::isolate());
5993 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5989 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5994 v8::Context::Scope context_scope(context); 5990 v8::Context::Scope context_scope(context);
5995 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5991 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5996 128 * 1024); 5992 128 * 1024);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
6108 6104
6109 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob")); 6105 CHECK(declarations->at(12)->proxy()->raw_name()->IsOneByteEqualTo("foob"));
6110 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST); 6106 CHECK(declarations->at(12)->proxy()->var()->mode() == i::CONST);
6111 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init()); 6107 CHECK(!declarations->at(12)->proxy()->var()->binding_needs_init());
6112 CHECK(declarations->at(12)->proxy()->var()->location() == 6108 CHECK(declarations->at(12)->proxy()->var()->location() ==
6113 i::VariableLocation::MODULE); 6109 i::VariableLocation::MODULE);
6114 6110
6115 i::ModuleDescriptor* descriptor = module_scope->module(); 6111 i::ModuleDescriptor* descriptor = module_scope->module();
6116 CHECK_NOT_NULL(descriptor); 6112 CHECK_NOT_NULL(descriptor);
6117 6113
6114 CHECK_EQ(5, descriptor->module_requests().size());
6115 for (const auto& elem : descriptor->module_requests()) {
6116 if (elem.first->IsOneByteEqualTo("m.js"))
6117 CHECK_EQ(elem.second, 0);
6118 else if (elem.first->IsOneByteEqualTo("n.js"))
6119 CHECK_EQ(elem.second, 1);
6120 else if (elem.first->IsOneByteEqualTo("p.js"))
6121 CHECK_EQ(elem.second, 2);
6122 else if (elem.first->IsOneByteEqualTo("q.js"))
6123 CHECK_EQ(elem.second, 3);
6124 else if (elem.first->IsOneByteEqualTo("bar.js"))
6125 CHECK_EQ(elem.second, 4);
6126 else
6127 CHECK(false);
6128 }
6129
6118 CHECK_EQ(3, descriptor->special_exports().length()); 6130 CHECK_EQ(3, descriptor->special_exports().length());
6119 CheckEntry(descriptor->special_exports().at(0), "b", nullptr, "a", "m.js"); 6131 CheckEntry(descriptor->special_exports().at(0), "b", nullptr, "a", 0);
6120 CheckEntry(descriptor->special_exports().at(1), nullptr, nullptr, nullptr, 6132 CheckEntry(descriptor->special_exports().at(1), nullptr, nullptr, nullptr, 2);
6121 "p.js");
6122 CheckEntry(descriptor->special_exports().at(2), "bb", nullptr, "aa", 6133 CheckEntry(descriptor->special_exports().at(2), "bb", nullptr, "aa",
6123 "m.js"); // !!! 6134 0); // !!!
6124 6135
6125 CHECK_EQ(8, descriptor->regular_exports().size()); 6136 CHECK_EQ(8, descriptor->regular_exports().size());
6126 entry = descriptor->regular_exports() 6137 entry = descriptor->regular_exports()
6127 .find(declarations->at(3)->proxy()->raw_name()) 6138 .find(declarations->at(3)->proxy()->raw_name())
6128 ->second; 6139 ->second;
6129 CheckEntry(entry, "foo", "foo", nullptr, nullptr); 6140 CheckEntry(entry, "foo", "foo", nullptr, -1);
6130 entry = descriptor->regular_exports() 6141 entry = descriptor->regular_exports()
6131 .find(declarations->at(4)->proxy()->raw_name()) 6142 .find(declarations->at(4)->proxy()->raw_name())
6132 ->second; 6143 ->second;
6133 CheckEntry(entry, "goo", "goo", nullptr, nullptr); 6144 CheckEntry(entry, "goo", "goo", nullptr, -1);
6134 entry = descriptor->regular_exports() 6145 entry = descriptor->regular_exports()
6135 .find(declarations->at(5)->proxy()->raw_name()) 6146 .find(declarations->at(5)->proxy()->raw_name())
6136 ->second; 6147 ->second;
6137 CheckEntry(entry, "hoo", "hoo", nullptr, nullptr); 6148 CheckEntry(entry, "hoo", "hoo", nullptr, -1);
6138 entry = descriptor->regular_exports() 6149 entry = descriptor->regular_exports()
6139 .find(declarations->at(6)->proxy()->raw_name()) 6150 .find(declarations->at(6)->proxy()->raw_name())
6140 ->second; 6151 ->second;
6141 CheckEntry(entry, "joo", "joo", nullptr, nullptr); 6152 CheckEntry(entry, "joo", "joo", nullptr, -1);
6142 entry = descriptor->regular_exports() 6153 entry = descriptor->regular_exports()
6143 .find(declarations->at(7)->proxy()->raw_name()) 6154 .find(declarations->at(7)->proxy()->raw_name())
6144 ->second; 6155 ->second;
6145 CheckEntry(entry, "default", "*default*", nullptr, nullptr); 6156 CheckEntry(entry, "default", "*default*", nullptr, -1);
6146 entry = descriptor->regular_exports() 6157 entry = descriptor->regular_exports()
6147 .find(declarations->at(12)->proxy()->raw_name()) 6158 .find(declarations->at(12)->proxy()->raw_name())
6148 ->second; 6159 ->second;
6149 CheckEntry(entry, "foob", "foob", nullptr, nullptr); 6160 CheckEntry(entry, "foob", "foob", nullptr, -1);
6150 // TODO(neis): The next lines are terrible. Find a better way. 6161 // TODO(neis): The next lines are terrible. Find a better way.
6151 auto name_x = declarations->at(0)->proxy()->raw_name(); 6162 auto name_x = declarations->at(0)->proxy()->raw_name();
6152 CHECK_EQ(2, descriptor->regular_exports().count(name_x)); 6163 CHECK_EQ(2, descriptor->regular_exports().count(name_x));
6153 auto it = descriptor->regular_exports().equal_range(name_x).first; 6164 auto it = descriptor->regular_exports().equal_range(name_x).first;
6154 entry = it->second; 6165 entry = it->second;
6155 if (entry->export_name->IsOneByteEqualTo("y")) { 6166 if (entry->export_name->IsOneByteEqualTo("y")) {
6156 CheckEntry(entry, "y", "x", nullptr, nullptr); 6167 CheckEntry(entry, "y", "x", nullptr, -1);
6157 entry = (++it)->second; 6168 entry = (++it)->second;
6158 CheckEntry(entry, "x", "x", nullptr, nullptr); 6169 CheckEntry(entry, "x", "x", nullptr, -1);
6159 } else { 6170 } else {
6160 CheckEntry(entry, "x", "x", nullptr, nullptr); 6171 CheckEntry(entry, "x", "x", nullptr, -1);
6161 entry = (++it)->second; 6172 entry = (++it)->second;
6162 CheckEntry(entry, "y", "x", nullptr, nullptr); 6173 CheckEntry(entry, "y", "x", nullptr, -1);
6163 } 6174 }
6164 6175
6165 CHECK_EQ(3, descriptor->special_imports().length()); 6176 CHECK_EQ(3, descriptor->special_imports().length());
6166 CheckEntry(descriptor->special_imports().at(0), nullptr, nullptr, nullptr, 6177 CheckEntry(descriptor->special_imports().at(0), nullptr, nullptr, nullptr, 3);
6167 "q.js"); 6178 CheckEntry(descriptor->special_imports().at(1), nullptr, "loo", nullptr, 4);
6168 CheckEntry(descriptor->special_imports().at(1), nullptr, "loo", nullptr, 6179 CheckEntry(descriptor->special_imports().at(2), nullptr, "foob", nullptr, 4);
6169 "bar.js");
6170 CheckEntry(descriptor->special_imports().at(2), nullptr, "foob", nullptr,
6171 "bar.js");
6172 6180
6173 CHECK_EQ(4, descriptor->regular_imports().size()); 6181 CHECK_EQ(4, descriptor->regular_imports().size());
6174 entry = descriptor->regular_imports().find( 6182 entry = descriptor->regular_imports().find(
6175 declarations->at(1)->proxy()->raw_name())->second; 6183 declarations->at(1)->proxy()->raw_name())->second;
6176 CheckEntry(entry, nullptr, "z", "q", "m.js"); 6184 CheckEntry(entry, nullptr, "z", "q", 0);
6177 entry = descriptor->regular_imports().find( 6185 entry = descriptor->regular_imports().find(
6178 declarations->at(2)->proxy()->raw_name())->second; 6186 declarations->at(2)->proxy()->raw_name())->second;
6179 CheckEntry(entry, nullptr, "n", "default", "n.js"); 6187 CheckEntry(entry, nullptr, "n", "default", 1);
6180 entry = descriptor->regular_imports().find( 6188 entry = descriptor->regular_imports().find(
6181 declarations->at(9)->proxy()->raw_name())->second; 6189 declarations->at(9)->proxy()->raw_name())->second;
6182 CheckEntry(entry, nullptr, "mm", "m", "m.js"); 6190 CheckEntry(entry, nullptr, "mm", "m", 0);
6183 entry = descriptor->regular_imports().find( 6191 entry = descriptor->regular_imports().find(
6184 declarations->at(10)->proxy()->raw_name())->second; 6192 declarations->at(10)->proxy()->raw_name())->second;
6185 CheckEntry(entry, nullptr, "aa", "aa", "m.js"); 6193 CheckEntry(entry, nullptr, "aa", "aa", 0);
6186 } 6194 }
6187 6195
6188 6196
6189 TEST(DuplicateProtoError) { 6197 TEST(DuplicateProtoError) {
6190 const char* context_data[][2] = { 6198 const char* context_data[][2] = {
6191 {"({", "});"}, 6199 {"({", "});"},
6192 {"'use strict'; ({", "});"}, 6200 {"'use strict'; ({", "});"},
6193 {NULL, NULL} 6201 {NULL, NULL}
6194 }; 6202 };
6195 const char* error_data[] = { 6203 const char* error_data[] = {
(...skipping 2123 matching lines...) Expand 10 before | Expand all | Expand 10 after
8319 const char* data[] = { 8327 const char* data[] = {
8320 "const arguments = 1", 8328 "const arguments = 1",
8321 "let arguments", 8329 "let arguments",
8322 "var arguments", 8330 "var arguments",
8323 NULL 8331 NULL
8324 }; 8332 };
8325 // clang-format on 8333 // clang-format on
8326 RunParserSyncTest(context_data, data, kSuccess); 8334 RunParserSyncTest(context_data, data, kSuccess);
8327 } 8335 }
8328 } 8336 }
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698