tor-browser

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

dedupe-02.js (1434B)


      1 // AutoStableStringChars needs to prevent the owner of its chars from being
      2 // deduplicated, even if they are held by a different string.
      3 
      4 gczeal(0);
      5 
      6 function makeExtensibleStrFrom(str) {
      7  var left = str.substr(0, str.length/2);
      8  var right = str.substr(str.length/2, str.length);
      9  var ropeStr = left + right;
     10  return ensureLinearString(ropeStr);
     11 }
     12 
     13 // Make a string to deduplicate to.
     14 var original = makeExtensibleStrFrom('{ "phbbbbbbbbbbbbbbttt!!!!??": [1] }\n\n');
     15 
     16 // Construct D2 -> D1 -> base
     17 var D2 = makeExtensibleStrFrom('{ "phbbbbbbbbbbbbbbttt!!!!??": [1] }');
     18 var D1 = newRope(D2, '\n', {nursery: true});
     19 ensureLinearString(D1);
     20 var base = newRope(D1, '\n', {nursery: true});
     21 ensureLinearString(base);
     22 
     23 // Make an AutoStableStringChars(D2) and do a minor GC within it. (This will do
     24 // a major GC, but it'll start out with a minor GC.) `base` would get
     25 // deduplicated to `original`, if it weren't for AutoStableStringChars marking
     26 // all of D2, D1, and base non-deduplicatable.
     27 
     28 // The first time JSON.parse runs, it will create several (14 in my test) GC
     29 // things before getting to the point where it does an allocation while holding
     30 // the chars pointer. Get them out of the way now.
     31 JSON.parse(D2);
     32 
     33 // Cause a minor GC to happen during JSON.parse after AutoStableStringChars
     34 // gives up its pointer.
     35 schedulegc(1);
     36 JSON.parse(D2);
     37 
     38 // Access `D2` to verify that it is not using the deduplicated chars.
     39 print(D2);