tor-browser

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

extensible-nursery-chars.js (1507B)


      1 gczeal(0);
      2 
      3 function assertStringFlag(s, flag) {
      4    if (typeof stringRepresentation === "function") {
      5        var rep = JSON.parse(stringRepresentation(s));
      6        assertEq(rep.flags.includes(flag), true, "Missing flag: " + flag);
      7    }
      8 }
      9 function test(extensibleTenured, ropeTenured) {
     10    var s1 = "12345678901234567890";
     11 
     12    // Create an extensible string with chars in the nursery.
     13    var s2 = ensureLinearString(newRope(newRope(newRope(s1, s1), s1), s1));
     14    if (extensibleTenured) {
     15        minorgc();
     16        minorgc();
     17    }
     18    assertEq(isNurseryAllocated(s2), !extensibleTenured);
     19    assertStringFlag(s2, "EXTENSIBLE");
     20 
     21    // Try to reuse its buffer.
     22    var s3 = ensureLinearString(newRope(s2, s1, {nursery: !ropeTenured}));
     23    assertEq(isNurseryAllocated(s3), !ropeTenured);
     24    assertStringFlag(s3, "EXTENSIBLE");
     25 
     26    // If the rope was tenured and the extensible string had nursery-allocated
     27    // chars, we don't reuse its buffer so both strings will be extensible.
     28    // In all other cases, s2 is now a dependent string.
     29    if (ropeTenured && !extensibleTenured) {
     30        assertStringFlag(s2, "EXTENSIBLE");
     31    } else {
     32        assertStringFlag(s2, "DEPENDENT_BIT");
     33    }
     34 
     35    assertEq(s2, "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
     36    assertEq(s3, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
     37 }
     38 test(false, false);
     39 test(false, true);
     40 test(true, false);
     41 test(true, true);