`this` gets global object instead of thisValue
- Open browser console
- Open browser toolbox's debugger
- Search
/server/actors/object.jsfile (resource://devtools/server/actors/object.js) - Add a breakpoint just inside
ObjectActor.prototype.grip(e.g. line 76) - In the browser console, enter
[] - The debugger pauses at the breakpoint.
- Add a new watch expression:
this - Switch the browser toolbox to the console panel
- Enter
this.
Result: the global Sandbox object.
Expected: the this value of that function.
/claim
Thanks for claiming the issue! :wave:
Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.
:fox_face: Debugger team!
A good STR
- Go to https://satin-fender.glitch.me/
- In the debugger open
client.js - Add a breakpoint to line 10
- refresh the browser
- After the breakpoint hits
- Add
thisto the watch expression list
AR:this is the global Window object
ER: this should be the instance object a
This looks like a bug in the Debugger API to me. We're definitely evaluating try { this } catch (e) { e } in the frame for Test::run, and getting the global window.
I changed the code around the call to evalWithBindings in devtools/server/actors/webconsole.js` to read:
if (frame) {
dump("JIMB: frame.evalwithBindings(" + uneval(string) + ")\n");
dump("JIMB: frame: " + describeDF(frame) + "\n");
result = frame.evalWithBindings(string, bindings, evalOptions);
if (result.return) {
dump("JIMB: result.return: " + describeDV(result.return));
} else if (result.throw) {
dump("JIMB: result.throw: " + describeDV(result.throw));
}
} else {
dump("JIMB: dbgWindow.executeInGlobalWithBindings(" + uneval(string) + ")\n");
result = dbgWindow.executeInGlobalWithBindings(string, bindings, evalOptions);
(imagine appropriate definitions for describeDV and describeDF) and got the following output:
DBG-SERVER: Received packet 105: {
"to": "server1.conn0.child1/consoleActor2",
"type": "evaluateJS",
"text": "try {\n this\n} catch (e) {\n e\n}",
"frameActor": "server1.conn0.child1/frame38"
}
JIMB: frame.evalwithBindings("try {\n this\n} catch (e) {\n e\n}")
JIMB: frame: [Debugger.Frame callee=[Debugger.Object class=Function displayName=run]
this=[Debugger.Object class=Object]]
JIMB: result.return: [Debugger.Object class=Window]
DBG-SERVER: Received packet 107: {
"from": "server1.conn0.child1/consoleActor2",
"input": "try {\n this\n} catch (e) {\n e\n}",
"result": {
"type": "object",
"actor": "server1.conn0.child1/obj1049",
"class": "Window",
"extensible": true,
"frozen": false,
"sealed": false,
"ownPropertyLength": 816,
"preview": {
"kind": "ObjectWithURL",
"url": "https://satin-fender.glitch.me/"
}
},
"timestamp": 1509743672917,
"exception": null,
"frame": null,
"helperResult": null,
"notes": null
}
Note that the this value fetched directly off the frame is correct, while the result of the eval is wrong.
it would be nice to reproduce this issue in the console as well. as in, when paused does the same behavior occur there too. I would bet 💸 that it does
Yeah I tested in the console, when paused. We get the same thing.
/unclaim
Done :+1:
I had a chat about #4324 (this gets global object instead of thisValue) with Ted Campbell, who works on the JavaScript engine.
Summary: it seems likely that js::IsExtensibleLexicalEnvironment might be mishandling debugger environments.
https://searchfox.org/mozilla-central/source/js/src/vm/EnvironmentObject.h#1073-1078
However, this is one instance of a larger class of bugs that result from SpiderMonkey using DebugEnvironmentProxy objects as environment objects, even though they're not subclasses of DebuggerEnvironment: https://searchfox.org/mozilla-central/rev/bab833ebeef6b2202e71f81d225b968283521fd6/js/src/vm/EnvironmentObject.h#893
In other words, most code in SpiderMonkey really wishes it were talking to some common superclass of debug environments and real environments, but there's no such type, so everyplace needs to have an if to handle both cases - and that if is often just missing.
So there's a short-term fix: change the behavior of IsExtensibleLexicalEnvironment, and maybe some related functions.
And then there's the longer-term fix: actually introduce a class which can serve as the common supertype of all the environments SpiderMonkey ought to deal with. In other words, make the types reflect reality, so you can trust them.
That's probably going to entail changing DebugEnvironmentProxy to no longer be a proxy object - which I think will be okay, and perhaps even good.
Reduced test case, usable in JS shell:
let g = newGlobal();
g.target = this;
g.evaluate(`
let d = new Debugger;
let gw = d.addDebuggee(target);
d.onDebuggerStatement = function(frame)
{
frame = frame.older;
let res = frame.eval("this");
print(res.return === frame.this);
}
`);
function brk() { debugger; }
function bar() {
let reversed = "stringstring";
brk();
}
bar.call({});
JS engine work is occurring in bug 1397049.
@jimblandy closed this issue as it's being tracked elsewhere