nursery-chars.js (2778B)
1 function TTN() { 2 let minors = this.currentgc ? currentgc()?.minorCount : undefined; 3 let NB3 = newString("bleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaggh!!!!! no no no no no no no no no no no no no no no no no", { tenured: false }); 4 if (this.stringRepresentation) { 5 const NB3rep = JSON.parse(stringRepresentation(NB3)); 6 if (!NB3rep.charsInNursery) { 7 printErr("Not testing what it is supposed to be testing"); 8 dumpStringRepresentation(NB3); 9 } 10 } 11 let TD2 = newDependentString(NB3, 1, { tenured: true }); 12 let TD1 = newDependentString(TD2, 4, 56, { tenured: true, 'suppress-contraction': true }); 13 const TD1rep = this.stringRepresentation ? JSON.parse(stringRepresentation(TD1)) : null; 14 NB3 = null; 15 let wrong_situation = minors === undefined || currentgc().minorCount > minors; 16 minorgc(); 17 print(TD1); 18 assertEq(TD1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaggh!!!!!"); 19 // Even with suppress-contraction, TD1 must point directly to NB3 as its base. 20 if (wrong_situation) { 21 printErr("unexpected minor GC or cannot determine, skipping whitebox tests"); 22 } else if (TD1rep !== null) { 23 assertEq(TD1rep.base.base, undefined); 24 assertEq(TD1rep.base.flags.includes("DEPENDED_ON_BIT"), true); 25 assertEq(TD1rep.base.flags.includes("DEPENDENT_BIT"), false); 26 } 27 } 28 29 TTN(); 30 31 function TTTN() { 32 let ext = newString("leafleafleafleafleafleafleaf", { capacity: 500 }); 33 let first = ext; // This will end up being the beginning of a long dependent chain. 34 35 // Create a long dependent chain. 36 let rope; 37 for (let i = 0; i < 10; i++) { 38 rope = newRope(ext, "y", { nursery: false }); 39 ensureLinearString(rope); // ext is now a dependent string pointing at rope 40 [ext, rope] = [rope, ext]; 41 } 42 43 // Add a final terminating link to the chain (the root base), but make it 44 // nursery-allocated. 45 rope = newRope(ext, "z", { nursery: true }); 46 ensureLinearString(rope); 47 [ext, rope] = [rope, ext] 48 49 // Sadly, the root base is nursery-allocated, but its chars are not. And 50 // there is no way to make them nursery-allocated, because the whole 51 // chain-making process requires an extensible string, and extensible string 52 // data cannot be allocated in the nursery. So this dependent chain cannot 53 // be used to try to create a tenured -> tenured -> nursery chars situation. 54 } 55 56 TTTN(); 57 58 function TTTN2() { 59 let s = newString("abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz", { tenured: false }); 60 61 let dep = s; 62 for (let i = 0; i < 20; i++) { 63 dep = dep.match(/.(.*)/)[1]; 64 } 65 66 // Regexp matches also avoid lengthening the chain, so cannot be used either. 67 } 68 69 TTTN2();