Bug 755778: Debugger.Environment.prototype.with should return "with" for 'with' statements' environments. r=jorendorff
authorJim Blandy <jimb@mozilla.com>
Wed, 16 May 2012 09:19:36 -0700
changeset 95585 2e7bd3c9bbb5f328859f94f313d20913de4c9e22
parent 95584 d89ad0b19ebbb4a53354da11a7804db179bab432
child 95586 14e6675d74e4285f588c5152bdd15ff0525b562a
push idunknown
push userunknown
push dateunknown
reviewersjorendorff
bugs755778
milestone15.0a1
Bug 755778: Debugger.Environment.prototype.with should return "with" for 'with' statements' environments. r=jorendorff
js/src/jit-test/tests/debug/Environment-find-01.js
js/src/jit-test/tests/debug/Environment-type-01.js
js/src/vm/Debugger.cpp
--- a/js/src/jit-test/tests/debug/Environment-find-01.js
+++ b/js/src/jit-test/tests/debug/Environment-find-01.js
@@ -1,15 +1,15 @@
 // find sees that vars are hoisted out of with statements.
 
 var g = newGlobal('new-compartment');
 var dbg = Debugger(g);
 var hits = 0;
 dbg.onDebuggerStatement = function (frame) {
-    assertEq(frame.environment.find("x").type, "object");
+    assertEq(frame.environment.find("x").type, "with");
     hits++;
 };
 
 assertEq(g.eval("(function () {\n" +
                 "    function g() { x = 1; }\n" +
                 "    with ({x: 2}) {\n" +
                 "        var x;\n" +
                 "        debugger;\n" +
--- a/js/src/jit-test/tests/debug/Environment-type-01.js
+++ b/js/src/jit-test/tests/debug/Environment-type-01.js
@@ -8,18 +8,18 @@ function test(code, expected) {
     g.eval(code);
     assertEq(actual, expected);
 }
 
 test("h();", 'object');
 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();", 'object');
-test("(function (s) { with ({x: 1, y: 2}) h(); })();", 'object');
+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("(let (x = 1) h());", 'declarative');
 test("for (let x = 0; x < 1; x++) h();", 'declarative');
 test("for (let x in h()) ;", 'object');
 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');
 test("for (var x in [h(m) for (m in [1])]) ;", 'declarative');
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -4254,16 +4254,18 @@ static JSBool
 DebuggerEnv_getType(JSContext *cx, unsigned argc, Value *vp)
 {
     THIS_DEBUGENV(cx, argc, vp, "get type", args, envobj, env);
 
     /* Don't bother switching compartments just to check env's class. */
     const char *s;
     if (env->isCall() || env->isBlock() || env->isDeclEnv())
         s = "declarative";
+    else if (env->isWith())
+        s = "with";
     else
         s = "object";
 
     JSAtom *str = js_Atomize(cx, s, strlen(s), InternAtom, NormalEncoding);
     if (!str)
         return false;
     args.rval().setString(str);
     return true;