Memory-takeCensus-06.js (4628B)
1 // Check Debugger.Memory.prototype.takeCensus handling of 'breakdown' argument. 2 3 load(libdir + 'match.js'); 4 var Pattern = Match.Pattern; 5 6 var g = newGlobal({newCompartment: true}); 7 var dbg = new Debugger(g); 8 9 Pattern({ count: Pattern.NATURAL, 10 bytes: Pattern.NATURAL }) 11 .assert(dbg.memory.takeCensus({ breakdown: { by: 'count' } })); 12 13 let census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: false, bytes: false } }); 14 assertEq('count' in census, false); 15 assertEq('bytes' in census, false); 16 17 census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: true, bytes: false } }); 18 assertEq('count' in census, true); 19 assertEq('bytes' in census, false); 20 21 census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: false, bytes: true } }); 22 assertEq('count' in census, false); 23 assertEq('bytes' in census, true); 24 25 census = dbg.memory.takeCensus({ breakdown: { by: 'count', count: true, bytes: true } }); 26 assertEq('count' in census, true); 27 assertEq('bytes' in census, true); 28 29 30 // Pattern doesn't mind objects with extra properties, so we'll restrict this 31 // list to the object classes we're pretty sure are going to stick around for 32 // the forseeable future. 33 Pattern({ 34 Function: { count: Pattern.NATURAL }, 35 Object: { count: Pattern.NATURAL }, 36 DebuggerPrototype: { count: Pattern.NATURAL }, 37 global: { count: Pattern.NATURAL }, 38 }) 39 .assert(dbg.memory.takeCensus({ breakdown: { by: 'objectClass' } })); 40 41 Pattern({ 42 objects: { count: Pattern.NATURAL }, 43 scripts: { count: Pattern.NATURAL }, 44 strings: { count: Pattern.NATURAL }, 45 other: { count: Pattern.NATURAL } 46 }) 47 .assert(dbg.memory.takeCensus({ breakdown: { by: 'coarseType' } })); 48 49 // As for { by: 'objectClass' }, restrict our pattern to the types 50 // we predict will stick around for a long time. 51 Pattern({ 52 JSString: { count: Pattern.NATURAL }, 53 'js::Shape': { count: Pattern.NATURAL }, 54 JSObject: { count: Pattern.NATURAL }, 55 }) 56 .assert(dbg.memory.takeCensus({ breakdown: { by: 'internalType' } })); 57 58 59 // Nested breakdowns. 60 61 let coarse_type_pattern = { 62 objects: { count: Pattern.NATURAL }, 63 scripts: { count: Pattern.NATURAL }, 64 strings: { count: Pattern.NATURAL }, 65 other: { count: Pattern.NATURAL } 66 }; 67 68 Pattern({ 69 JSString: coarse_type_pattern, 70 'js::Shape': coarse_type_pattern, 71 JSObject: coarse_type_pattern, 72 }) 73 .assert(dbg.memory.takeCensus({ 74 breakdown: { by: 'internalType', 75 then: { by: 'coarseType' } 76 } 77 })); 78 79 Pattern({ 80 Function: { count: Pattern.NATURAL }, 81 Object: { count: Pattern.NATURAL }, 82 DebuggerPrototype: { count: Pattern.NATURAL }, 83 global: { count: Pattern.NATURAL }, 84 other: coarse_type_pattern 85 }) 86 .assert(dbg.memory.takeCensus({ 87 breakdown: { 88 by: 'objectClass', 89 then: { by: 'count' }, 90 other: { by: 'coarseType' } 91 } 92 })); 93 94 Pattern({ 95 objects: { count: Pattern.NATURAL, label: "object" }, 96 scripts: { count: Pattern.NATURAL, label: "scripts" }, 97 strings: { count: Pattern.NATURAL, label: "strings" }, 98 other: { count: Pattern.NATURAL, label: "other" } 99 }) 100 .assert(dbg.memory.takeCensus({ 101 breakdown: { 102 by: 'coarseType', 103 objects: { by: 'count', label: 'object' }, 104 scripts: { by: 'count', label: 'scripts' }, 105 strings: { by: 'count', label: 'strings' }, 106 other: { by: 'count', label: 'other' } 107 } 108 })); 109 110 try { 111 const breakdown = { by: "objectClass" }; 112 breakdown.then = breakdown; 113 dbg.memory.takeCensus({ breakdown }); 114 assertEq(true, false, "should not reach here"); 115 } catch (e) { 116 assertEq(e.message, "takeCensus breakdown 'by' value nested within itself: \"objectClass\""); 117 } 118 119 try { 120 const breakdown = { by: "objectClass", then: { by: "objectClass" } }; 121 dbg.memory.takeCensus({ breakdown }); 122 assertEq(true, false, "should not reach here"); 123 } catch (e) { 124 assertEq(e.message, "takeCensus breakdown 'by' value nested within itself: \"objectClass\""); 125 } 126 127 try { 128 const breakdown = { by: "coarseType", scripts: { by: "filename" } }; 129 breakdown.scripts.noFilename = breakdown; 130 dbg.memory.takeCensus({ breakdown }); 131 assertEq(true, false, "should not reach here"); 132 } catch (e) { 133 assertEq(e.message, "takeCensus breakdown 'by' value nested within itself: \"coarseType\""); 134 }