tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_HeapSnapshot_takeCensus_06.js (3862B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Check HeapSnapshot.prototype.takeCensus handling of 'breakdown' argument.
      6 //
      7 // Ported from js/src/jit-test/tests/debug/Memory-takeCensus-06.js
      8 
      9 function run_test() {
     10  const Pattern = Match.Pattern;
     11 
     12  const g = newGlobal();
     13  const dbg = new Debugger(g);
     14 
     15  new Pattern({ count: Pattern.NATURAL, bytes: Pattern.NATURAL }).assert(
     16    saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "count" } })
     17  );
     18 
     19  let census = saveHeapSnapshotAndTakeCensus(dbg, {
     20    breakdown: { by: "count", count: false, bytes: false },
     21  });
     22  equal("count" in census, false);
     23  equal("bytes" in census, false);
     24 
     25  census = saveHeapSnapshotAndTakeCensus(dbg, {
     26    breakdown: { by: "count", count: true, bytes: false },
     27  });
     28  equal("count" in census, true);
     29  equal("bytes" in census, false);
     30 
     31  census = saveHeapSnapshotAndTakeCensus(dbg, {
     32    breakdown: { by: "count", count: false, bytes: true },
     33  });
     34  equal("count" in census, false);
     35  equal("bytes" in census, true);
     36 
     37  census = saveHeapSnapshotAndTakeCensus(dbg, {
     38    breakdown: { by: "count", count: true, bytes: true },
     39  });
     40  equal("count" in census, true);
     41  equal("bytes" in census, true);
     42 
     43  // Pattern doesn't mind objects with extra properties, so we'll restrict this
     44  // list to the object classes we're pretty sure are going to stick around for
     45  // the forseeable future.
     46  new Pattern({
     47    Function: { count: Pattern.NATURAL },
     48    Object: { count: Pattern.NATURAL },
     49    DebuggerPrototype: { count: Pattern.NATURAL },
     50    Sandbox: { count: Pattern.NATURAL },
     51  }).assert(
     52    saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "objectClass" } })
     53  );
     54 
     55  new Pattern({
     56    objects: { count: Pattern.NATURAL },
     57    scripts: { count: Pattern.NATURAL },
     58    strings: { count: Pattern.NATURAL },
     59    other: { count: Pattern.NATURAL },
     60  }).assert(
     61    saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "coarseType" } })
     62  );
     63 
     64  // As for { by: 'objectClass' }, restrict our pattern to the types
     65  // we predict will stick around for a long time.
     66  new Pattern({
     67    JSString: { count: Pattern.NATURAL },
     68    "js::Shape": { count: Pattern.NATURAL },
     69    JSObject: { count: Pattern.NATURAL },
     70  }).assert(
     71    saveHeapSnapshotAndTakeCensus(dbg, { breakdown: { by: "internalType" } })
     72  );
     73 
     74  // Nested breakdowns.
     75 
     76  const coarseTypePattern = {
     77    objects: { count: Pattern.NATURAL },
     78    scripts: { count: Pattern.NATURAL },
     79    strings: { count: Pattern.NATURAL },
     80    other: { count: Pattern.NATURAL },
     81  };
     82 
     83  new Pattern({
     84    JSString: coarseTypePattern,
     85    "js::Shape": coarseTypePattern,
     86    JSObject: coarseTypePattern,
     87  }).assert(
     88    saveHeapSnapshotAndTakeCensus(dbg, {
     89      breakdown: { by: "internalType", then: { by: "coarseType" } },
     90    })
     91  );
     92 
     93  new Pattern({
     94    Function: { count: Pattern.NATURAL },
     95    Object: { count: Pattern.NATURAL },
     96    DebuggerPrototype: { count: Pattern.NATURAL },
     97    Sandbox: { count: Pattern.NATURAL },
     98    other: coarseTypePattern,
     99  }).assert(
    100    saveHeapSnapshotAndTakeCensus(dbg, {
    101      breakdown: {
    102        by: "objectClass",
    103        then: { by: "count" },
    104        other: { by: "coarseType" },
    105      },
    106    })
    107  );
    108 
    109  new Pattern({
    110    objects: { count: Pattern.NATURAL, label: "object" },
    111    scripts: { count: Pattern.NATURAL, label: "scripts" },
    112    strings: { count: Pattern.NATURAL, label: "strings" },
    113    other: { count: Pattern.NATURAL, label: "other" },
    114  }).assert(
    115    saveHeapSnapshotAndTakeCensus(dbg, {
    116      breakdown: {
    117        by: "coarseType",
    118        objects: { by: "count", label: "object" },
    119        scripts: { by: "count", label: "scripts" },
    120        strings: { by: "count", label: "strings" },
    121        other: { by: "count", label: "other" },
    122      },
    123    })
    124  );
    125 
    126  do_test_finished();
    127 }