Web Inspector: Native Memory Instrumentation: reportLeaf method doesn't report the...
[WebKit-https.git] / Source / WebCore / inspector / HeapGraphSerializer.cpp
index 1479517b3362b9e3ebd8cc6eb60e602119e75a45..dbe2bdc171ea5ff7f7daa02100bea49096b29cde 100644 (file)
 
 namespace WebCore {
 
-HeapGraphSerializer::HeapGraphSerializer(InspectorFrontend::Memory* frontend)
-    : m_frontend(frontend)
+HeapGraphSerializer::HeapGraphSerializer(Client* client)
+    : m_client(client)
     , m_strings(Strings::create())
     , m_edges(Edges::create())
     , m_nodeEdgesCount(0)
     , m_nodes(Nodes::create())
     , m_baseToRealNodeIdMap(BaseToRealNodeIdMap::create())
+    , m_leafCount(0)
 {
-    ASSERT(m_frontend);
+    ASSERT(m_client);
     m_strings->addItem(String()); // An empty string with 0 index.
 
     memset(m_edgeTypes, 0, sizeof(m_edgeTypes));
@@ -91,7 +92,7 @@ void HeapGraphSerializer::pushUpdate()
         .setEdges(m_edges.release())
         .setBaseToRealNodeId(m_baseToRealNodeIdMap.release());
 
-    m_frontend->addNativeSnapshotChunk(chunk);
+    m_client->addNativeSnapshotChunk(chunk.release());
 
     m_strings = Strings::create();
     m_edges = Edges::create();
@@ -101,6 +102,7 @@ void HeapGraphSerializer::pushUpdate()
 
 void HeapGraphSerializer::reportNode(const WTF::MemoryObjectInfo& info)
 {
+    ASSERT(info.reportedPointer());
     reportNodeImpl(info, m_nodeEdgesCount);
     m_nodeEdgesCount = 0;
     if (info.isRoot())
@@ -182,8 +184,10 @@ int HeapGraphSerializer::addString(const String& string)
 
 int HeapGraphSerializer::toNodeId(const void* to)
 {
-    ASSERT(to);
-    Address2NodeId::AddResult result = m_address2NodeIdMap.add(to, m_address2NodeIdMap.size());
+    if (!to)
+        return s_firstNodeId + m_address2NodeIdMap.size() + m_leafCount++;
+
+    Address2NodeId::AddResult result = m_address2NodeIdMap.add(to, s_firstNodeId + m_leafCount + m_address2NodeIdMap.size());
     return result.iterator->value;
 }
 
@@ -194,7 +198,7 @@ void HeapGraphSerializer::addRootNode()
 
     m_nodes->addItem(addString("Root"));
     m_nodes->addItem(0);
-    m_nodes->addItem(m_address2NodeIdMap.size());
+    m_nodes->addItem(s_firstNodeId + m_address2NodeIdMap.size() + m_leafCount);
     m_nodes->addItem(0);
     m_nodes->addItem(m_roots.size());
 }