Bug 828020 - exactly root StaticScopeIter. r=terrence

This commit is contained in:
Tom Schuster 2013-01-10 13:31:40 +01:00
Родитель 73919a9923
Коммит 62b90a0ab5
8 изменённых файлов: 38 добавлений и 36 удалений

Просмотреть файл

@ -6710,7 +6710,7 @@ IonBuilder::jsop_getaliasedvar(ScopeCoordinate sc)
MDefinition *obj = walkScopeChain(sc.hops); MDefinition *obj = walkScopeChain(sc.hops);
RootedShape shape(cx, ScopeCoordinateToStaticScope(script(), pc).scopeShape()); RootedShape shape(cx, ScopeCoordinateToStaticScopeShape(cx, script(), pc));
MInstruction *load; MInstruction *load;
if (shape->numFixedSlots() <= sc.slot) { if (shape->numFixedSlots() <= sc.slot) {
@ -6744,7 +6744,7 @@ IonBuilder::jsop_setaliasedvar(ScopeCoordinate sc)
MDefinition *rval = current->peek(-1); MDefinition *rval = current->peek(-1);
MDefinition *obj = walkScopeChain(sc.hops); MDefinition *obj = walkScopeChain(sc.hops);
RootedShape shape(cx, ScopeCoordinateToStaticScope(script(), pc).scopeShape()); RootedShape shape(cx, ScopeCoordinateToStaticScopeShape(cx, script(), pc));
MInstruction *store; MInstruction *store;
if (shape->numFixedSlots() <= sc.slot) { if (shape->numFixedSlots() <= sc.slot) {

Просмотреть файл

@ -389,9 +389,9 @@ js::GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx)
if (!fp->isFunctionFrame()) if (!fp->isFunctionFrame())
return NULL; return NULL;
JSFunction *scriptedCaller = fp->fun(); RootedFunction scriptedCaller(cx, fp->fun());
RootedScript outermost(cx, scriptedCaller->nonLazyScript()); RootedScript outermost(cx, scriptedCaller->nonLazyScript());
for (StaticScopeIter i(scriptedCaller); !i.done(); i++) { for (StaticScopeIter i(cx, scriptedCaller); !i.done(); i++) {
if (i.type() == StaticScopeIter::FUNCTION) if (i.type() == StaticScopeIter::FUNCTION)
outermost = i.funScript(); outermost = i.funScript();
} }

Просмотреть файл

@ -583,7 +583,7 @@ js_Disassemble1(JSContext *cx, HandleScript script, jsbytecode *pc,
} }
case JOF_SCOPECOORD: { case JOF_SCOPECOORD: {
Value v = StringValue(ScopeCoordinateName(cx->runtime, script, pc)); Value v = StringValue(ScopeCoordinateName(cx, script, pc));
JSAutoByteString bytes; JSAutoByteString bytes;
if (!ToDisassemblySource(cx, v, &bytes)) if (!ToDisassemblySource(cx, v, &bytes))
return 0; return 0;
@ -1926,7 +1926,7 @@ IsVarSlot(JSPrinter *jp, jsbytecode *pc, JSAtom **varAtom, int *localSlot)
*localSlot = -1; *localSlot = -1;
if (JOF_OPTYPE(*pc) == JOF_SCOPECOORD) { if (JOF_OPTYPE(*pc) == JOF_SCOPECOORD) {
*varAtom = ScopeCoordinateName(jp->sprinter.context->runtime, jp->script, pc); *varAtom = ScopeCoordinateName(jp->sprinter.context, jp->script, pc);
LOCAL_ASSERT_RV(*varAtom, false); LOCAL_ASSERT_RV(*varAtom, false);
return true; return true;
} }
@ -5973,7 +5973,7 @@ ExpressionDecompiler::decompilePC(jsbytecode *pc)
} }
case JSOP_CALLALIASEDVAR: case JSOP_CALLALIASEDVAR:
case JSOP_GETALIASEDVAR: { case JSOP_GETALIASEDVAR: {
JSAtom *atom = ScopeCoordinateName(cx->runtime, script, pc); JSAtom *atom = ScopeCoordinateName(cx, script, pc);
JS_ASSERT(atom); JS_ASSERT(atom);
return write(atom); return write(atom);
} }

Просмотреть файл

@ -669,7 +669,8 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
/* Code the nested function's enclosing scope. */ /* Code the nested function's enclosing scope. */
uint32_t funEnclosingScopeIndex = 0; uint32_t funEnclosingScopeIndex = 0;
if (mode == XDR_ENCODE) { if (mode == XDR_ENCODE) {
StaticScopeIter ssi((*objp)->toFunction()->nonLazyScript()->enclosingStaticScope()); RootedObject staticScope(cx, (*objp)->toFunction()->nonLazyScript()->enclosingStaticScope());
StaticScopeIter ssi(cx, staticScope);
if (ssi.done() || ssi.type() == StaticScopeIter::FUNCTION) { if (ssi.done() || ssi.type() == StaticScopeIter::FUNCTION) {
JS_ASSERT(ssi.done() == !fun); JS_ASSERT(ssi.done() == !fun);
funEnclosingScopeIndex = UINT32_MAX; funEnclosingScopeIndex = UINT32_MAX;
@ -2221,8 +2222,8 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock); clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock);
} else if (obj->isFunction()) { } else if (obj->isFunction()) {
RootedFunction innerFun(cx, obj->toFunction()); RootedFunction innerFun(cx, obj->toFunction());
RootedObject staticScope(cx, innerFun->nonLazyScript()->enclosingStaticScope());
StaticScopeIter ssi(innerFun->nonLazyScript()->enclosingStaticScope()); StaticScopeIter ssi(cx, staticScope);
RootedObject enclosingScope(cx); RootedObject enclosingScope(cx);
if (!ssi.done() && ssi.type() == StaticScopeIter::BLOCK) if (!ssi.done() && ssi.type() == StaticScopeIter::BLOCK)
enclosingScope = objects[FindBlockIndex(src, ssi.block())]; enclosingScope = objects[FindBlockIndex(src, ssi.block())];

Просмотреть файл

@ -6060,7 +6060,7 @@ mjit::Compiler::jsop_aliasedVar(ScopeCoordinate sc, bool get, bool poppedAfter)
for (unsigned i = 0; i < sc.hops; i++) for (unsigned i = 0; i < sc.hops; i++)
masm.loadPayload(Address(reg, ScopeObject::offsetOfEnclosingScope()), reg); masm.loadPayload(Address(reg, ScopeObject::offsetOfEnclosingScope()), reg);
UnrootedShape shape = ScopeCoordinateToStaticScope(script_, PC).scopeShape(); UnrootedShape shape = ScopeCoordinateToStaticScopeShape(cx, script_, PC);
Address addr; Address addr;
if (shape->numFixedSlots() <= sc.slot) { if (shape->numFixedSlots() <= sc.slot) {
masm.loadPtr(Address(reg, JSObject::offsetOfSlots()), reg); masm.loadPtr(Address(reg, JSObject::offsetOfSlots()), reg);

Просмотреть файл

@ -23,8 +23,8 @@ using namespace js::types;
/*****************************************************************************/ /*****************************************************************************/
StaticScopeIter::StaticScopeIter(JSObject *obj) StaticScopeIter::StaticScopeIter(JSContext *cx, HandleObject objArg)
: obj(obj), onNamedLambda(false) : obj(cx, objArg), onNamedLambda(false)
{ {
JS_ASSERT_IF(obj, obj->isStaticBlock() || obj->isFunction()); JS_ASSERT_IF(obj, obj->isStaticBlock() || obj->isFunction());
} }
@ -32,7 +32,7 @@ StaticScopeIter::StaticScopeIter(JSObject *obj)
bool bool
StaticScopeIter::done() const StaticScopeIter::done() const
{ {
return obj == NULL; return !obj;
} }
void void
@ -92,20 +92,20 @@ StaticScopeIter::funScript() const
/*****************************************************************************/ /*****************************************************************************/
StaticScopeIter UnrootedShape
js::ScopeCoordinateToStaticScope(JSScript *script, jsbytecode *pc) js::ScopeCoordinateToStaticScopeShape(JSContext *cx, JSScript *script, jsbytecode *pc)
{ {
JS_ASSERT(pc >= script->code && pc < script->code + script->length); JS_ASSERT(pc >= script->code && pc < script->code + script->length);
JS_ASSERT(JOF_OPTYPE(*pc) == JOF_SCOPECOORD); JS_ASSERT(JOF_OPTYPE(*pc) == JOF_SCOPECOORD);
uint32_t blockIndex = GET_UINT32_INDEX(pc + 2 * sizeof(uint16_t)); uint32_t blockIndex = GET_UINT32_INDEX(pc + 2 * sizeof(uint16_t));
JSObject *innermostStaticScope; RootedObject innermostStaticScope(cx, NULL);
if (blockIndex == UINT32_MAX) if (blockIndex == UINT32_MAX)
innermostStaticScope = script->function(); innermostStaticScope = script->function();
else else
innermostStaticScope = &script->getObject(blockIndex)->asStaticBlock(); innermostStaticScope = &script->getObject(blockIndex)->asStaticBlock();
StaticScopeIter ssi(innermostStaticScope); StaticScopeIter ssi(cx, innermostStaticScope);
ScopeCoordinate sc(pc); ScopeCoordinate sc(pc);
while (true) { while (true) {
if (ssi.hasDynamicScopeObject()) { if (ssi.hasDynamicScopeObject()) {
@ -115,13 +115,13 @@ js::ScopeCoordinateToStaticScope(JSScript *script, jsbytecode *pc)
} }
ssi++; ssi++;
} }
return ssi; return ssi.scopeShape();
} }
PropertyName * PropertyName *
js::ScopeCoordinateName(JSRuntime *rt, JSScript *script, jsbytecode *pc) js::ScopeCoordinateName(JSContext *cx, JSScript *script, jsbytecode *pc)
{ {
Shape::Range r = ScopeCoordinateToStaticScope(script, pc).scopeShape()->all(); Shape::Range r = ScopeCoordinateToStaticScopeShape(cx, script, pc)->all();
ScopeCoordinate sc(pc); ScopeCoordinate sc(pc);
while (r.front().slot() != sc.slot) while (r.front().slot() != sc.slot)
r.popFront(); r.popFront();
@ -129,7 +129,7 @@ js::ScopeCoordinateName(JSRuntime *rt, JSScript *script, jsbytecode *pc)
/* Beware nameless destructuring formal. */ /* Beware nameless destructuring formal. */
if (!JSID_IS_ATOM(id)) if (!JSID_IS_ATOM(id))
return rt->atomState.empty; return cx->runtime->atomState.empty;
return JSID_TO_ATOM(id)->asPropertyName(); return JSID_TO_ATOM(id)->asPropertyName();
} }
@ -427,7 +427,7 @@ static JSBool
with_SetGeneric(JSContext *cx, HandleObject obj, HandleId id, with_SetGeneric(JSContext *cx, HandleObject obj, HandleId id,
MutableHandleValue vp, JSBool strict) MutableHandleValue vp, JSBool strict)
{ {
Rooted<JSObject*> actual(cx, &obj->asWith().object()); RootedObject actual(cx, &obj->asWith().object());
return JSObject::setGeneric(cx, actual, actual, id, vp, strict); return JSObject::setGeneric(cx, actual, actual, id, vp, strict);
} }
@ -435,7 +435,7 @@ static JSBool
with_SetProperty(JSContext *cx, HandleObject obj, HandlePropertyName name, with_SetProperty(JSContext *cx, HandleObject obj, HandlePropertyName name,
MutableHandleValue vp, JSBool strict) MutableHandleValue vp, JSBool strict)
{ {
Rooted<JSObject*> actual(cx, &obj->asWith().object()); RootedObject actual(cx, &obj->asWith().object());
return JSObject::setProperty(cx, actual, actual, name, vp, strict); return JSObject::setProperty(cx, actual, actual, name, vp, strict);
} }
@ -443,7 +443,7 @@ static JSBool
with_SetElement(JSContext *cx, HandleObject obj, uint32_t index, with_SetElement(JSContext *cx, HandleObject obj, uint32_t index,
MutableHandleValue vp, JSBool strict) MutableHandleValue vp, JSBool strict)
{ {
Rooted<JSObject*> actual(cx, &obj->asWith().object()); RootedObject actual(cx, &obj->asWith().object());
return JSObject::setElement(cx, actual, actual, index, vp, strict); return JSObject::setElement(cx, actual, actual, index, vp, strict);
} }
@ -451,7 +451,7 @@ static JSBool
with_SetSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid, with_SetSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid,
MutableHandleValue vp, JSBool strict) MutableHandleValue vp, JSBool strict)
{ {
Rooted<JSObject*> actual(cx, &obj->asWith().object()); RootedObject actual(cx, &obj->asWith().object());
return JSObject::setSpecial(cx, actual, actual, sid, vp, strict); return JSObject::setSpecial(cx, actual, actual, sid, vp, strict);
} }

Просмотреть файл

@ -56,11 +56,11 @@ namespace js {
*/ */
class StaticScopeIter class StaticScopeIter
{ {
JSObject *obj; RootedObject obj;
bool onNamedLambda; bool onNamedLambda;
public: public:
explicit StaticScopeIter(JSObject *obj); explicit StaticScopeIter(JSContext *cx, HandleObject obj);
bool done() const; bool done() const;
void operator++(int); void operator++(int);
@ -97,15 +97,15 @@ struct ScopeCoordinate
}; };
/* /*
* Return a scope iterator pointing at the static scope containing the variable * Return a shape representing the static scope containing the variable
* accessed by the ALIASEDVAR op at 'pc'. * accessed by the ALIASEDVAR op at 'pc'.
*/ */
extern StaticScopeIter extern UnrootedShape
ScopeCoordinateToStaticScope(JSScript *script, jsbytecode *pc); ScopeCoordinateToStaticScopeShape(JSContext *cx, JSScript *script, jsbytecode *pc);
/* Return the name being accessed by the given ALIASEDVAR op. */ /* Return the name being accessed by the given ALIASEDVAR op. */
extern PropertyName * extern PropertyName *
ScopeCoordinateName(JSRuntime *rt, JSScript *script, jsbytecode *pc); ScopeCoordinateName(JSContext *cx, JSScript *script, jsbytecode *pc);
/*****************************************************************************/ /*****************************************************************************/

Просмотреть файл

@ -233,10 +233,11 @@ StackFrame::copyRawFrameSlots(AutoValueVector *vec)
} }
static inline void static inline void
AssertDynamicScopeMatchesStaticScope(JSScript *script, JSObject *scope) AssertDynamicScopeMatchesStaticScope(JSContext *cx, JSScript *script, JSObject *scope)
{ {
#ifdef DEBUG #ifdef DEBUG
for (StaticScopeIter i(script->enclosingStaticScope()); !i.done(); i++) { RootedObject enclosingScope(cx, script->enclosingStaticScope());
for (StaticScopeIter i(cx, enclosingScope); !i.done(); i++) {
if (i.hasDynamicScopeObject()) { if (i.hasDynamicScopeObject()) {
/* /*
* 'with' does not participate in the static scope of the script, * 'with' does not participate in the static scope of the script,
@ -305,7 +306,7 @@ StackFrame::prologue(JSContext *cx, bool newType)
} }
JS_ASSERT(isNonEvalFunctionFrame()); JS_ASSERT(isNonEvalFunctionFrame());
AssertDynamicScopeMatchesStaticScope(script, scopeChain()); AssertDynamicScopeMatchesStaticScope(cx, script, scopeChain());
if (fun()->isHeavyweight() && !initFunctionScopeObjects(cx)) if (fun()->isHeavyweight() && !initFunctionScopeObjects(cx))
return false; return false;
@ -367,7 +368,7 @@ StackFrame::epilogue(JSContext *cx)
if (fun()->isHeavyweight()) if (fun()->isHeavyweight())
JS_ASSERT_IF(hasCallObj(), scopeChain()->asCall().callee().nonLazyScript() == script); JS_ASSERT_IF(hasCallObj(), scopeChain()->asCall().callee().nonLazyScript() == script);
else else
AssertDynamicScopeMatchesStaticScope(script, scopeChain()); AssertDynamicScopeMatchesStaticScope(cx, script, scopeChain());
if (cx->compartment->debugMode()) if (cx->compartment->debugMode())
DebugScopes::onPopCall(this, cx); DebugScopes::onPopCall(this, cx);