Reviewers: rossberg,
Description:
Allow lookup of module exports by export name.
This required fixing the exports_ hash map to use the appropriate
comparison function instead of pointer comparison.
BUG=v8:1569
LOG=n
Please review this at https://codereview.chromium.org/960793003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+26, -10 lines):
M src/modules.h
M src/modules.cc
M test/cctest/test-parsing.cc
Index: src/modules.cc
diff --git a/src/modules.cc b/src/modules.cc
index
5fab34dcbd30c43adc2ba20e4f61ec11d805b43f..267c398c472c74ac035c7880fa04d9773762a5dd
100644
--- a/src/modules.cc
+++ b/src/modules.cc
@@ -20,9 +20,8 @@ void ModuleDescriptor::AddLocalExport(const AstRawString*
export_name,
ZoneAllocationPolicy allocator(zone);
if (exports_ == nullptr) {
- exports_ = new (zone->New(sizeof(ZoneHashMap)))
- ZoneHashMap(ZoneHashMap::PointersMatch,
- ZoneHashMap::kDefaultHashMapCapacity, allocator);
+ exports_ = new (zone->New(sizeof(ZoneHashMap))) ZoneHashMap(
+ AstRawString::Compare, ZoneHashMap::kDefaultHashMapCapacity,
allocator);
}
ZoneHashMap::Entry* p =
@@ -33,5 +32,18 @@ void ModuleDescriptor::AddLocalExport(const
AstRawString* export_name,
p->value = const_cast<AstRawString*>(local_name);
}
+
+
+const AstRawString* ModuleDescriptor::LookupLocalExport(
+ const AstRawString* export_name, Zone* zone) {
+ if (exports_ == nullptr) return nullptr;
+ ZoneAllocationPolicy allocator(zone);
+ ZoneHashMap::Entry* entry =
+ exports_->Lookup(const_cast<AstRawString*>(export_name),
+ export_name->hash(), false, allocator);
+ if (entry == nullptr) return nullptr;
+ DCHECK_NOT_NULL(entry->value);
+ return static_cast<const AstRawString*>(entry->value);
+}
}
} // namespace v8::internal
Index: src/modules.h
diff --git a/src/modules.h b/src/modules.h
index
b7f5d19abc4c104f14aa2f9dec5760ab5880c700..7dd7e26716bbbdab086ba1ecb064f3773d5afe2c
100644
--- a/src/modules.h
+++ b/src/modules.h
@@ -58,6 +58,9 @@ class ModuleDescriptor : public ZoneObject {
return index_;
}
+ const AstRawString* LookupLocalExport(const AstRawString* export_name,
+ Zone* zone);
+
//
---------------------------------------------------------------------------
// Iterators.
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
02f8869c419fc4c70504c2ac87fa1cf8fe3e7ee3..fcc096af850221fe94e38828049f6036f58364ac
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -5223,6 +5223,8 @@ TEST(ModuleParsingInternals) {
i::Handle<i::String> source =
factory->NewStringFromAsciiChecked(kSource);
i::Handle<i::Script> script = factory->NewScript(source);
i::CompilationInfoWithZone info(script);
+ i::Zone* zone = info.zone();
+ i::AstValueFactory avf(zone, isolate->heap()->HashSeed());
i::Parser parser(&info, isolate->stack_guard()->real_climit(),
isolate->heap()->HashSeed(), isolate->unicode_cache());
parser.set_allow_harmony_modules(true);
@@ -5233,13 +5235,12 @@ TEST(ModuleParsingInternals) {
CHECK_EQ(i::MODULE_SCOPE, func->scope()->scope_type());
i::ModuleDescriptor* descriptor = func->scope()->module();
CHECK_NOT_NULL(descriptor);
- int num_exports = 0;
- for (auto it = descriptor->iterator(); !it.done(); it.Advance()) {
- ++num_exports;
- CHECK(it.local_name()->IsOneByteEqualTo("x"));
- CHECK(it.export_name()->IsOneByteEqualTo("y"));
- }
- CHECK_EQ(1, num_exports);
+ CHECK_EQ(1, descriptor->Length());
+ const i::AstRawString* export_name = avf.GetOneByteString("y");
+ const i::AstRawString* local_name =
+ descriptor->LookupLocalExport(export_name, zone);
+ CHECK_NOT_NULL(local_name);
+ CHECK(local_name->IsOneByteEqualTo("x"));
i::ZoneList<i::Declaration*>* declarations =
func->scope()->declarations();
CHECK_EQ(2, declarations->length());
CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x"));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.