1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 class LiveHeapObject(object):
6 """Data structure for representing an object in the heap snapshot.
9 object_id: int, identifier for the object.
10 type_string: str, describes the type of the node.
11 class_name: str, describes the class of the JavaScript object
12 represented by this LiveHeapObject.
13 edges_to: [RetainingEdge], edges whose end point this LiveHeapObject is.
14 edges_from: [RetainingEdge], edges whose start point this LiveHeapObject is.
15 string: str, for string LiveHeapObjects, contains the string the
16 LiveHeapObject represents. Empty string for LiveHeapObjects which are
18 name: str, how to refer to this LiveHeapObject.
21 def __init__(self, object_id, type_string, class_name):
22 """Initializes the LiveHeapObject object.
25 object_id: int, identifier for the LiveHeapObject.
26 type_string: str, the type of the node.
27 class_name: str, the class of the object this LiveHeapObject represents.
29 self.object_id = object_id
30 self.type_string = type_string
31 self.class_name = class_name
37 def AddEdgeTo(self, edge):
38 """Associates an Edge with the LiveHeapObject (the end point).
41 edge: Edge, an edge whose end point this LiveHeapObject is.
43 self.edges_to.append(edge)
45 def AddEdgeFrom(self, edge):
46 """Associates an Edge with the LiveHeapObject (the start point).
49 edge: Edge, an edge whose start point this LiveHeapObject is.
51 self.edges_from.append(edge)
54 prefix = 'LiveHeapObject(' + str(self.object_id) + ' '
55 if self.type_string == 'object':
56 return prefix + self.class_name + ')'
57 return prefix + self.type_string + ')'