diff --git a/js/src/ion/IonBuilder.cpp b/js/src/ion/IonBuilder.cpp index 164267aeb574..1e5b5ce5eacc 100644 --- a/js/src/ion/IonBuilder.cpp +++ b/js/src/ion/IonBuilder.cpp @@ -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) { diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index f813e2c8288b..ecc0e8713994 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -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(); } diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp index c58955ac1031..12a1cbeeab7d 100644 --- a/js/src/jsopcode.cpp +++ b/js/src/jsopcode.cpp @@ -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); } diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 654117651c97..1a8f6e748b95 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -669,7 +669,8 @@ js::XDRScript(XDRState *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())]; diff --git a/js/src/methodjit/Compiler.cpp b/js/src/methodjit/Compiler.cpp index ebdc247a8db4..d1ba7a47e360 100644 --- a/js/src/methodjit/Compiler.cpp +++ b/js/src/methodjit/Compiler.cpp @@ -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); diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index 1a4b08bdb4eb..2263bb9bf808 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -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 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 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 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 actual(cx, &obj->asWith().object()); + RootedObject actual(cx, &obj->asWith().object()); return JSObject::setSpecial(cx, actual, actual, sid, vp, strict); } diff --git a/js/src/vm/ScopeObject.h b/js/src/vm/ScopeObject.h index 0a02f69db905..7417ead1bc90 100644 --- a/js/src/vm/ScopeObject.h +++ b/js/src/vm/ScopeObject.h @@ -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); /*****************************************************************************/ diff --git a/js/src/vm/Stack.cpp b/js/src/vm/Stack.cpp index a6ebbe6c1b7a..d5810308cc1d 100644 --- a/js/src/vm/Stack.cpp +++ b/js/src/vm/Stack.cpp @@ -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);