mark.lam@apple.com | 7682413 | 2017-11-24 10:58:16 +0000 | [diff] [blame] | 1 | var SimpleObject = $vm.SimpleObject; |
| 2 | var setHiddenValue = $vm.setHiddenValue; |
| 3 | |
commit-queue@webkit.org | d38d068 | 2016-03-03 05:15:56 +0000 | [diff] [blame] | 4 | load("./driver/driver.js"); |
| 5 | |
| 6 | function excludeStructure(edges) { |
| 7 | return edges.filter((x) => x.to.className !== "Structure"); |
| 8 | } |
| 9 | |
| 10 | let simpleObject1NodeId; |
| 11 | let simpleObject2NodeId; |
| 12 | |
| 13 | let simpleObject1 = new SimpleObject; |
| 14 | let simpleObject2 = new SimpleObject; |
| 15 | |
| 16 | (function() { |
| 17 | let snapshot = createCheapHeapSnapshot(); |
| 18 | let nodes = snapshot.nodesWithClassName("SimpleObject"); |
| 19 | assert(nodes.length === 2, "Snapshot should contain 2 'SimpleObject' instances"); |
| 20 | let simpleObject1Node = nodes[0].outgoingEdges.length === 2 ? nodes[0] : nodes[1]; |
| 21 | let simpleObject2Node = nodes[0].outgoingEdges.length === 1 ? nodes[0] : nodes[1]; |
| 22 | assert(simpleObject1Node.outgoingEdges.length === 1, "'simpleObject1' should reference only its structure"); |
| 23 | assert(simpleObject2Node.outgoingEdges.length === 1, "'simpleObject2' should reference only its structure"); |
| 24 | })(); |
| 25 | |
| 26 | setHiddenValue(simpleObject1, simpleObject2); |
| 27 | |
| 28 | (function() { |
| 29 | let snapshot = createCheapHeapSnapshot(); |
| 30 | let nodes = snapshot.nodesWithClassName("SimpleObject"); |
| 31 | assert(nodes.length === 2, "Snapshot should contain 2 'SimpleObject' instances"); |
| 32 | let simpleObject1Node = nodes[0].outgoingEdges.length === 2 ? nodes[0] : nodes[1]; |
| 33 | let simpleObject2Node = nodes[0].outgoingEdges.length === 1 ? nodes[0] : nodes[1]; |
| 34 | assert(simpleObject1Node.outgoingEdges.length === 2, "'simpleObject1' should reference its structure and hidden value"); |
| 35 | assert(simpleObject2Node.outgoingEdges.length === 1, "'simpleObject2' should reference only its structure"); |
| 36 | assert(excludeStructure(simpleObject1Node.outgoingEdges)[0].to.id === simpleObject2Node.id, "'simpleObject1' should reference 'simpleObject2'"); |
| 37 | simpleObject1NodeId = simpleObject1Node.id; |
| 38 | simpleObject2NodeId = simpleObject2Node.id; |
| 39 | })(); |
| 40 | |
| 41 | simpleObject2 = null; |
| 42 | |
| 43 | (function() { |
| 44 | let snapshot = createCheapHeapSnapshot(); |
| 45 | let nodes = snapshot.nodesWithClassName("SimpleObject"); |
| 46 | assert(nodes.length === 2, "Snapshot should contain 2 'SimpleObject' instances"); |
| 47 | let simpleObject1Node = nodes[0].id === simpleObject1NodeId ? nodes[0] : nodes[1]; |
| 48 | let simpleObject2Node = nodes[0].id === simpleObject2NodeId ? nodes[0] : nodes[1]; |
| 49 | assert(simpleObject1Node.id === simpleObject1NodeId && simpleObject2Node.id === simpleObject2NodeId, "node identifiers were maintained"); |
| 50 | assert(simpleObject1Node.outgoingEdges.length === 2, "'simpleObject1' should reference its structure and hidden value"); |
| 51 | assert(simpleObject2Node.outgoingEdges.length === 1, "'simpleObject2' should reference only its structure"); |
| 52 | assert(excludeStructure(simpleObject1Node.outgoingEdges)[0].to.id === simpleObject2NodeId, "'simpleObject1' should reference 'simpleObject2'"); |
| 53 | })(); |
| 54 | |
| 55 | simpleObject1 = null; |
| 56 | |
| 57 | (function() { |
| 58 | let snapshot = createCheapHeapSnapshot(); |
| 59 | let nodes = snapshot.nodesWithClassName("SimpleObject"); |
| 60 | assert(nodes.length === 0, "Snapshot should not contain a 'SimpleObject' instance"); |
| 61 | })(); |