Debian Codegraph @

js/src/jit-test/tests/debug/Environment-type-01.js

raw
1 // env.type is 'object' in global environments and with-blocks, and 'declarative' otherwise.
2
3 var g = newGlobal({newCompartment: true});
4 var dbg = Debugger(g);
5 function test(code, expected) {
6 var actual = '';
7 g.h = function () { actual += dbg.getNewestFrame().environment.type; }
8 g.eval(code);
9 assertEq(actual, expected);
10 }
11
12 test("h();", 'declarative');
13 test("(function (s) { eval(s); })('var v = h();')", 'declarative');
14 test("(function (s) { h(); })();", 'declarative');
15 test("{let x = 1, y = 2; h();}", 'declarative');
16 test("with({x: 1, y: 2}) h();", 'with');
17 test("(function (s) { with ({x: 1, y: 2}) h(); })();", 'with');
18 test("{ let x = 1; h(); }", 'declarative');
19 test("for (let x = 0; x < 1; x++) h();", 'declarative');
20 test("for (let x in h()) ;", 'declarative');
21 test("for (let x in {a:1}) h();", 'declarative');
22 test("try { throw new Error; } catch (x) { h(x) }", 'declarative');
23 test("'use strict'; eval('var z = 1; h();');", 'declarative');
24
25 dbg.onDebuggerStatement = function (frame) {
26 assertEq(frame.eval("h(), 2 + 2;").return, 4);
27 }
28 test("debugger;", 'declarative');
29 test("(function f() { debugger; })();", 'declarative');