Environment-scopeKind-01.js (786B)
1 // Environment.prototype.scopeKind produces expected values. 2 3 load(libdir + 'eqArrayHelper.js'); 4 5 var g = newGlobal({ newCompartment: true }); 6 var dbg = Debugger(g); 7 8 function getScopeKinds(text) { 9 const kinds = []; 10 dbg.onDebuggerStatement = frame => { 11 let env = frame.environment; 12 while (env) { 13 kinds.push(env.scopeKind); 14 env = env.parent; 15 } 16 }; 17 g.eval(text); 18 return kinds; 19 } 20 21 assertEqArray(getScopeKinds("function f(x) { debugger; }; f()"), 22 ["function", "global", null]); 23 assertEqArray(getScopeKinds("function f(x) { let y = 0; debugger; }; f()"), 24 ["function lexical", "function", "global", null]); 25 assertEqArray(getScopeKinds("function f(x) { let y = 0; with(x) { debugger; } } f({})"), 26 [null, "function lexical", "function", "global", null]);