mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1303118 - Fix 'this' computation for Debugger.Frame.evalWithBindings. (r=efaust)
This commit is contained in:
parent
c4ae869e28
commit
ce5eebf5d8
@ -287,13 +287,19 @@ EvalSharedContext::EvalSharedContext(ExclusiveContext* cx, JSObject* enclosingEn
|
||||
// this binding with respect to enclosingScope is incorrect if the
|
||||
// Debugger.Frame is a function frame. Recompute the this binding if we
|
||||
// are such an eval.
|
||||
if (enclosingEnv && enclosingEnv->is<DebugEnvironmentProxy>()) {
|
||||
JSObject* env = &enclosingEnv->as<DebugEnvironmentProxy>().environment();
|
||||
if (enclosingEnv && enclosingScope->hasOnChain(ScopeKind::NonSyntactic)) {
|
||||
// For Debugger.Frame.eval with bindings, the environment chain may
|
||||
// have more than the DebugEnvironmentProxy.
|
||||
JSObject* env = enclosingEnv;
|
||||
while (env) {
|
||||
if (env->is<DebugEnvironmentProxy>())
|
||||
env = &env->as<DebugEnvironmentProxy>().environment();
|
||||
|
||||
if (env->is<CallObject>()) {
|
||||
computeThisBinding(env->as<CallObject>().callee().nonLazyScript()->bodyScope());
|
||||
break;
|
||||
}
|
||||
|
||||
env = env->enclosingEnvironment();
|
||||
}
|
||||
}
|
||||
|
15
js/src/jit-test/tests/debug/Frame-evalWithBindings-15.js
Normal file
15
js/src/jit-test/tests/debug/Frame-evalWithBindings-15.js
Normal file
@ -0,0 +1,15 @@
|
||||
var g = newGlobal();
|
||||
var dbg = new Debugger(g);
|
||||
|
||||
dbg.onDebuggerStatement = function (frame) {
|
||||
// The bindings object is unused but adds another environment on the
|
||||
// environment chain. Make sure 'this' computes the right value in light of
|
||||
// this.
|
||||
assertEq(frame.evalWithBindings(`this === foo;`, { bar: 42 }).return, true);
|
||||
assertEq(frame.evalWithBindings(`eval('this') === foo;`, { bar: 42 }).return, true);
|
||||
};
|
||||
|
||||
g.eval(`
|
||||
var foo = { bar: function() { debugger; } };
|
||||
foo.bar();
|
||||
`);
|
Loading…
Reference in New Issue
Block a user