diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc index dedf5437be..291c1a237a 100644 --- a/src/profiler/heap-snapshot-generator.cc +++ b/src/profiler/heap-snapshot-generator.cc @@ -942,11 +942,16 @@ void V8HeapExplorer::ExtractEphemeronHashTableReferences( table.OffsetOfElementAt(value_index)); HeapEntry* key_entry = GetEntry(key); HeapEntry* value_entry = GetEntry(value); - if (key_entry && value_entry) { - const char* edge_name = - names_->GetFormatted("key %s in WeakMap", key_entry->name()); + HeapEntry* table_entry = GetEntry(table); + if (key_entry && value_entry && !key.IsUndefined()) { + const char* edge_name = names_->GetFormatted( + "part of key (%s @%u) -> value (%s @%u) pair in WeakMap (table @%u)", + key_entry->name(), key_entry->id(), value_entry->name(), + value_entry->id(), table_entry->id()); key_entry->SetNamedAutoIndexReference(HeapGraphEdge::kInternal, edge_name, value_entry, names_); + table_entry->SetNamedAutoIndexReference(HeapGraphEdge::kInternal, + edge_name, value_entry, names_); } } } diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index a205c1decb..976395a407 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -839,13 +839,24 @@ TEST(HeapSnapshotEphemeron) { const v8::HeapGraphNode* key = GetProperty( env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "key"); CHECK(key); + const v8::HeapGraphNode* weakmap = GetProperty( + env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "wm"); + CHECK(weakmap); + const v8::HeapGraphNode* weakmap_table = GetProperty( + env->GetIsolate(), weakmap, v8::HeapGraphEdge::kInternal, "table"); + CHECK(weakmap_table); bool success = false; for (int i = 0, count = key->GetChildrenCount(); i < count; ++i) { const v8::HeapGraphEdge* edge = key->GetChild(i); const v8::HeapGraphNode* child = edge->GetToNode(); if (!strcmp("ValueClass", GetName(child))) { v8::String::Utf8Value edge_name(CcTest::isolate(), edge->GetName()); - CHECK(EndsWith(*edge_name, " / key KeyClass in WeakMap")); + std::stringstream end_of_label; + end_of_label << "/ part of key (KeyClass @" << key->GetId() + << ") -> value (ValueClass @" << child->GetId() + << ") pair in WeakMap (table @" << weakmap_table->GetId() + << ")"; + CHECK(EndsWith(*edge_name, end_of_label.str().c_str())); success = true; break; }