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

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

@ -389,9 +389,9 @@ js::GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx)
if (!fp->isFunctionFrame())
return NULL;
JSFunction *scriptedCaller = fp->fun();
RootedFunction scriptedCaller(cx, fp->fun());
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)
outermost = i.funScript();
}

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

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

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

@ -669,7 +669,8 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
/* Code the nested function's enclosing scope. */
uint32_t funEnclosingScopeIndex = 0;
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) {
JS_ASSERT(ssi.done() == !fun);
funEnclosingScopeIndex = UINT32_MAX;
@ -2221,8 +2222,8 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock);
} else if (obj->isFunction()) {
RootedFunction innerFun(cx, obj->toFunction());
StaticScopeIter ssi(innerFun->nonLazyScript()->enclosingStaticScope());
RootedObject staticScope(cx, innerFun->nonLazyScript()->enclosingStaticScope());
StaticScopeIter ssi(cx, staticScope);
RootedObject enclosingScope(cx);
if (!ssi.done() && ssi.type() == StaticScopeIter::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++)
masm.loadPayload(Address(reg, ScopeObject::offsetOfEnclosingScope()), reg);
UnrootedShape shape = ScopeCoordinateToStaticScope(script_, PC).scopeShape();
UnrootedShape shape = ScopeCoordinateToStaticScopeShape(cx, script_, PC);
Address addr;
if (shape->numFixedSlots() <= sc.slot) {
masm.loadPtr(Address(reg, JSObject::offsetOfSlots()), reg);

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

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

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

@ -56,11 +56,11 @@ namespace js {
*/
class StaticScopeIter
{
JSObject *obj;
RootedObject obj;
bool onNamedLambda;
public:
explicit StaticScopeIter(JSObject *obj);
explicit StaticScopeIter(JSContext *cx, HandleObject obj);
bool done() const;
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'.
*/
extern StaticScopeIter
ScopeCoordinateToStaticScope(JSScript *script, jsbytecode *pc);
extern UnrootedShape
ScopeCoordinateToStaticScopeShape(JSContext *cx, JSScript *script, jsbytecode *pc);
/* Return the name being accessed by the given ALIASEDVAR op. */
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
AssertDynamicScopeMatchesStaticScope(JSScript *script, JSObject *scope)
AssertDynamicScopeMatchesStaticScope(JSContext *cx, JSScript *script, JSObject *scope)
{
#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()) {
/*
* 'with' does not participate in the static scope of the script,
@ -305,7 +306,7 @@ StackFrame::prologue(JSContext *cx, bool newType)
}
JS_ASSERT(isNonEvalFunctionFrame());
AssertDynamicScopeMatchesStaticScope(script, scopeChain());
AssertDynamicScopeMatchesStaticScope(cx, script, scopeChain());
if (fun()->isHeavyweight() && !initFunctionScopeObjects(cx))
return false;
@ -367,7 +368,7 @@ StackFrame::epilogue(JSContext *cx)
if (fun()->isHeavyweight())
JS_ASSERT_IF(hasCallObj(), scopeChain()->asCall().callee().nonLazyScript() == script);
else
AssertDynamicScopeMatchesStaticScope(script, scopeChain());
AssertDynamicScopeMatchesStaticScope(cx, script, scopeChain());
if (cx->compartment->debugMode())
DebugScopes::onPopCall(this, cx);