Bug 1122335 - Fix static scope chain for Debugger.Frame.prototype.eval. (r=jimb)

This commit is contained in:
Shu-yu Guo 2015-01-24 12:30:56 -08:00
parent a50f9e2df5
commit 7ce3b01635
3 changed files with 24 additions and 5 deletions

View File

@ -311,6 +311,8 @@ EvalKernel(JSContext *cx, const CallArgs &args, EvalType evalType, AbstractFrame
if (evalType == DIRECT_EVAL)
enclosing = callerScript->innermostStaticScope(pc);
Rooted<StaticEvalObject *> staticScope(cx, StaticEvalObject::create(cx, enclosing));
if (!staticScope)
return false;
CompileOptions options(cx);
options.setFileAndLine(filename, 1)

View File

@ -0,0 +1,12 @@
// Test that strict Debugger.Frame.eval has a correct static scope.
options('strict_mode');
var g = newGlobal();
var dbg = new Debugger(g);
var hits = 0;
dbg.onEnterFrame = function(f) {
hits++;
if (hits > 2)
return;
f.eval("42");
};
g.eval("42");

View File

@ -5941,10 +5941,15 @@ EvaluateInEnv(JSContext *cx, Handle<Env*> env, HandleValue thisv, AbstractFrameP
* calls and properly compute a static level. In practice, any non-zero
* static level will suffice.
*
* Pass in NullPtr for evalStaticScope, as ScopeIter should stop at any
* non-ScopeObject boundaries, and we are putting a DebugScopeProxy on the
* scope chain.
* Pass in a StaticEvalObject *not* linked to env for evalStaticScope, as
* ScopeIter should stop at any non-ScopeObject boundaries, and we are
* putting a DebugScopeProxy on the scope chain.
*/
Rooted<StaticEvalObject *> staticScope(cx, StaticEvalObject::create(cx, js::NullPtr()));
if (!staticScope)
return false;
if (frame && frame.script()->strict())
staticScope->setStrict();
CompileOptions options(cx);
options.setCompileAndGo(true)
.setForEval(true)
@ -5956,8 +5961,8 @@ EvaluateInEnv(JSContext *cx, Handle<Env*> env, HandleValue thisv, AbstractFrameP
RootedScript callerScript(cx, frame ? frame.script() : nullptr);
SourceBufferHolder srcBuf(chars.start().get(), chars.length(), SourceBufferHolder::NoOwnership);
RootedScript script(cx, frontend::CompileScript(cx, &cx->tempLifoAlloc(), env, callerScript,
/* evalStaticScope = */ js::NullPtr(),
options, srcBuf, /* source = */ nullptr,
staticScope, options, srcBuf,
/* source = */ nullptr,
/* staticLevel = */ frame ? 1 : 0));
if (!script)
return false;