Bug 895774 - Fix ScriptFrameIter::computeThis with multiple compartments and contexts; r=jandem

This commit is contained in:
Nick Fitzgerald 2013-07-23 10:10:43 -07:00
parent a86cc4ab9a
commit 4d1fc444fa
5 changed files with 21 additions and 7 deletions

View File

@ -0,0 +1,14 @@
var g1 = newGlobal();
var g2 = newGlobal();
g1.eval("function f1() { debugger; evaluate('debugger', {newContext:true}) }");
g2.eval("function f2() { f1(); assertEq(Number(this), 42) }");
g2.f1 = g1.f1;
var dbg = new Debugger(g1,g2);
dbg.onDebuggerStatement = function(frame) {
var target = frame.older;
dbg.onDebuggerStatement = function(frame) {
assertEq(Number(target.this.unsafeDereference()), 42);
}
}
g2.f2.call(42);

View File

@ -1061,7 +1061,7 @@ FormatFrame(JSContext *cx, const NonBuiltinScriptFrameIter &iter, char *buf, int
RootedValue thisVal(cx);
AutoPropertyDescArray thisProps(cx);
if (iter.computeThis()) {
if (iter.computeThis(cx)) {
thisVal = iter.thisv();
if (showThisProps && !thisVal.isPrimitive())
thisProps.fetch(&thisVal.toObject());

View File

@ -3820,7 +3820,7 @@ DebuggerFrame_getThis(JSContext *cx, unsigned argc, Value *vp)
RootedValue thisv(cx);
{
AutoCompartment ac(cx, iter.scopeChain());
if (!iter.computeThis())
if (!iter.computeThis(cx))
return false;
thisv = iter.thisv();
}
@ -4220,7 +4220,7 @@ DebuggerGenericEval(JSContext *cx, const char *fullMethodName, const Value &code
Rooted<Env *> env(cx);
if (iter) {
/* ExecuteInEnv requires 'fp' to have a computed 'this" value. */
if (!iter->computeThis())
if (!iter->computeThis(cx))
return false;
thisv = iter->thisv();
env = GetDebugScopeForFrame(cx, iter->abstractFramePtr());

View File

@ -1099,12 +1099,12 @@ ScriptFrameIter::argsObj() const
}
bool
ScriptFrameIter::computeThis() const
ScriptFrameIter::computeThis(JSContext *cx) const
{
JS_ASSERT(!done());
if (!isIon()) {
JS_ASSERT(data_.cx_);
return ComputeThis(data_.cx_, abstractFramePtr());
assertSameCompartment(cx, scopeChain());
return ComputeThis(cx, abstractFramePtr());
}
return true;
}

View File

@ -1519,7 +1519,7 @@ class ScriptFrameIter
ArgumentsObject &argsObj() const;
// Ensure that thisv is correct, see ComputeThis.
bool computeThis() const;
bool computeThis(JSContext *cx) const;
Value thisv() const;
Value returnValue() const;