bug1675755-forceLexicalInitializationByName.js (1200B)
1 load(libdir + "asserts.js"); 2 3 var g = newGlobal({newCompartment: true}); 4 var dbg = new Debugger; 5 var gw = dbg.addDebuggee(g); 6 7 let errorOne, errorTwo; 8 9 function evalErrorStr(global, evalString) { 10 try { 11 global.evaluate(evalString); 12 return undefined; 13 } catch (e) { 14 return e.toString(); 15 } 16 } 17 18 19 assertEq(evalErrorStr(g, "let y = IDONTEXIST;"), "ReferenceError: IDONTEXIST is not defined"); 20 assertEq(evalErrorStr(g, "y = 1;"), 21 "ReferenceError: can't access lexical declaration 'y' before initialization"); 22 23 const LINEAR_SEARCHES_MAX = 3; 24 const SHAPE_CACHE_MIN_ENTRIES = 3; 25 26 // Give the lexical enough properties so that it isBigEnoughForAShapeTable(). 27 for (i in [...Array(SHAPE_CACHE_MIN_ENTRIES)]) 28 gw.executeInGlobal(`let x${i} = 1`); 29 30 // Search for y just enough times to cause the next search to trigger 31 // Shape::cachify(). 32 for (i in [...Array(LINEAR_SEARCHES_MAX - 1)]) 33 gw.executeInGlobal("y"); 34 35 // Here we flip the uninitialized binding to undefined. But in the process, we 36 // will do the lookup on y that will trigger Shape::cachify. Verify that it 37 // happens in the correct compartment. 38 assertEq(gw.forceLexicalInitializationByName("y"), true);