summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Environment-scopeKind-01.js
blob: 729573f730dc1af633fd380a0f0b4eeea15f0606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Environment.prototype.scopeKind produces expected values.

load(libdir + 'eqArrayHelper.js');

var g = newGlobal({ newCompartment: true });
var dbg = Debugger(g);

function getScopeKinds(text) {
  const kinds = [];
  dbg.onDebuggerStatement = frame => {
    let env = frame.environment;
    while (env) {
      kinds.push(env.scopeKind);
      env = env.parent;
    }
  };
  g.eval(text);
  return kinds;
}

assertEqArray(getScopeKinds("function f(x) { debugger; }; f()"),
  ["function", "global", null]);
assertEqArray(getScopeKinds("function f(x) { let y = 0; debugger; }; f()"),
  ["function lexical", "function", "global", null]);
assertEqArray(getScopeKinds("function f(x) { let y = 0; with(x) { debugger; } } f({})"),
  [null, "function lexical", "function", "global", null]);