tor-browser

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

dumpStringRepresentation.js (2693B)


      1 // |jit-test| skip-if: typeof dumpStringRepresentation !== 'function'
      2 
      3 // Try the dumpStringRepresentation shell function on various types of
      4 // strings, and make sure it doesn't crash.
      5 
      6 print("Empty string:");
      7 dumpStringRepresentation("");
      8 
      9 print("\nResult of coercion to string:");
     10 dumpStringRepresentation();
     11 
     12 print("\nString with an index value:");
     13 dumpStringRepresentation((12345).toString());
     14 
     15 print("\ns = Simple short atom:");
     16 var s = "xxxxxxxx";
     17 dumpStringRepresentation(s);
     18 
     19 // Simple non-atom flat.
     20 print("\ns + s: Non-atom flat:");
     21 var s2 = s + s;
     22 dumpStringRepresentation(s2);
     23 
     24 print("\nNon-Latin1 flat:");
     25 var j = "渋谷区";
     26 dumpStringRepresentation(j);
     27 
     28 print("\nt = Non-inline atom:");
     29 var t = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // 31 characters
     30 dumpStringRepresentation(t);
     31 
     32 print("\nr1 = t + s: Simple rope:");
     33 var r1 = t + s;
     34 dumpStringRepresentation(r1);
     35 
     36 // Flatten that rope, and re-examine the representations of both the result and
     37 // its former leaves. This should be an extensible string.
     38 print("\nr1, former rope after flattening, now extensible:");
     39 r1.match(/x/);
     40 dumpStringRepresentation(r1);
     41 
     42 print("\nt, s: Original leaves, representation unchanged:");
     43 dumpStringRepresentation(t);
     44 dumpStringRepresentation(s);
     45 
     46 // Create a new rope with the extensible string as its left child.
     47 print("\nr2 = r1 + s: Rope with extensible leftmost child:");
     48 var r2 = r1 + s;
     49 dumpStringRepresentation(r2);
     50 
     51 // Flatten that; this should re-use the extensible string's buffer.
     52 print("\nr2: flattened, stole r1's buffer:");
     53 r2.match(/x/);
     54 dumpStringRepresentation(r2);
     55 
     56 print("\nr1: mutated into a dependent string:");
     57 dumpStringRepresentation(r1);
     58 
     59 print("\nr3 = r2 + s: a new rope with an extensible leftmost child:");
     60 r3 = r2 + s;
     61 r3.match(/x/);
     62 dumpStringRepresentation(r3);
     63 
     64 print("\nr2: now mutated into a dependent string");
     65 dumpStringRepresentation(r2);
     66 
     67 print("\nr1: now a doubly-dependent string, because of r2's mutation:");
     68 dumpStringRepresentation(r1);
     69 
     70 print("\nt, s: Original leaves, representation unchanged:");
     71 dumpStringRepresentation(t);
     72 dumpStringRepresentation(s);
     73 
     74 // Extensible string, created directly.
     75 print("\nExtensible:");
     76 var e = newString("一二三四五六七八九*一二三四五六七八", { capacity: 80 });
     77 dumpStringRepresentation(e);
     78 
     79 // Reuse an extensible string's storage when flattening a rope whose DAG contains
     80 // the extensible string multiple times.
     81 print("\nFlattened dag with shared leaves:");
     82 var e_flat = newRope(e, newRope(e, "!"));
     83 ensureLinearString(e_flat);
     84 dumpStringRepresentation(e_flat);
     85 assertEq(e_flat.charAt(e.length), e_flat.charAt(0));
     86 
     87 for (var str of representativeStringArray())
     88    dumpStringRepresentation(str);