Bug 1303118 - Fix 'this' computation for Debugger.Frame.evalWithBindings. (r=efaust)

This commit is contained in:
Shu-yu Guo 2016-09-22 12:42:37 -07:00
parent c4ae869e28
commit ce5eebf5d8
2 changed files with 23 additions and 2 deletions

View File

@ -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();
}
}

View 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();
`);