summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Environment-type-01.js
blob: 39b339cb39ce5490408c2f94ce0d0d1f118ad9a3 (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
27
28
29
// env.type is 'object' in global environments and with-blocks, and 'declarative' otherwise.

var g = newGlobal({newCompartment: true});
var dbg = Debugger(g);
function test(code, expected) {
    var actual = '';
    g.h = function () { actual += dbg.getNewestFrame().environment.type; }
    g.eval(code);
    assertEq(actual, expected);
}

test("h();", 'declarative');
test("(function (s) { eval(s); })('var v = h();')", 'declarative');
test("(function (s) { h(); })();", 'declarative');
test("{let x = 1, y = 2; h();}", 'declarative');
test("with({x: 1, y: 2}) h();", 'with');
test("(function (s) { with ({x: 1, y: 2}) h(); })();", 'with');
test("{ let x = 1; h(); }", 'declarative');
test("for (let x = 0; x < 1; x++) h();", 'declarative');
test("for (let x in h()) ;", 'declarative');
test("for (let x in {a:1}) h();", 'declarative');
test("try { throw new Error; } catch (x) { h(x) }", 'declarative');
test("'use strict'; eval('var z = 1; h();');", 'declarative');

dbg.onDebuggerStatement = function (frame) {
    assertEq(frame.eval("h(), 2 + 2;").return, 4);
}
test("debugger;", 'declarative');
test("(function f() { debugger; })();", 'declarative');