summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Environment-type-01.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/debug/Environment-type-01.js')
-rw-r--r--js/src/jit-test/tests/debug/Environment-type-01.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Environment-type-01.js b/js/src/jit-test/tests/debug/Environment-type-01.js
new file mode 100644
index 0000000000..39b339cb39
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Environment-type-01.js
@@ -0,0 +1,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');