From 7df073ff5b22a201849cb2e3c6235ee29e382614 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 4 Oct 2012 16:22:03 -0700 Subject: [PATCH] Bug 797695 (part 4) - Exactly root jsscript.cpp. r=terrence. --HG-- extra : rebase_source : b6cc292b092b30e339a75921245d4605275c104d --- js/src/jsatom.cpp | 12 +++--- js/src/jsatom.h | 2 +- js/src/jscntxt.h | 3 -- js/src/jscntxtinlines.h | 6 --- js/src/jsfun.cpp | 2 +- js/src/jsprvtd.h | 2 +- js/src/jsscript.cpp | 75 +++++++++++++++++++------------------- js/src/jsscript.h | 14 +++---- js/src/vm/RegExpObject.cpp | 2 +- js/src/vm/ScopeObject.cpp | 9 ++--- 10 files changed, 59 insertions(+), 68 deletions(-) diff --git a/js/src/jsatom.cpp b/js/src/jsatom.cpp index d03b773e6419..71a9d6941a2e 100644 --- a/js/src/jsatom.cpp +++ b/js/src/jsatom.cpp @@ -430,14 +430,14 @@ js::InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval, template bool -js::XDRAtom(XDRState *xdr, JSAtom **atomp) +js::XDRAtom(XDRState *xdr, MutableHandleAtom atomp) { if (mode == XDR_ENCODE) { - uint32_t nchars = (*atomp)->length(); + uint32_t nchars = atomp->length(); if (!xdr->codeUint32(&nchars)) return false; - jschar *chars = const_cast((*atomp)->getChars(xdr->cx())); + jschar *chars = const_cast(atomp->getChars(xdr->cx())); if (!chars) return false; @@ -483,13 +483,13 @@ js::XDRAtom(XDRState *xdr, JSAtom **atomp) if (!atom) return false; - *atomp = atom; + atomp.set(atom); return true; } template bool -js::XDRAtom(XDRState *xdr, JSAtom **atomp); +js::XDRAtom(XDRState *xdr, MutableHandleAtom atomp); template bool -js::XDRAtom(XDRState *xdr, JSAtom **atomp); +js::XDRAtom(XDRState *xdr, MutableHandleAtom atomp); diff --git a/js/src/jsatom.h b/js/src/jsatom.h index 18ab1674b31f..a9777bf6cf18 100644 --- a/js/src/jsatom.h +++ b/js/src/jsatom.h @@ -272,7 +272,7 @@ InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval, jsid *id template bool -XDRAtom(XDRState *xdr, JSAtom **atomp); +XDRAtom(XDRState *xdr, js::MutableHandleAtom atomp); } /* namespace js */ diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 5b3f43da0541..a7246c3656b1 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -120,9 +120,6 @@ struct GSNCache { void purge(); }; -inline GSNCache * -GetGSNCache(JSContext *cx); - typedef Vector ScriptAndCountsVector; struct ConservativeGCData diff --git a/js/src/jscntxtinlines.h b/js/src/jscntxtinlines.h index 3244bb6523c5..211ff457f551 100644 --- a/js/src/jscntxtinlines.h +++ b/js/src/jscntxtinlines.h @@ -134,12 +134,6 @@ struct PreserveRegsGuard FrameRegs ®s_; }; -inline GSNCache * -GetGSNCache(JSContext *cx) -{ - return &cx->runtime->gsnCache; -} - #if JS_HAS_XML_SUPPORT class AutoNamespaceArray : protected AutoGCRooter { diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 17f83e567140..6dbac7ad40e3 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -405,7 +405,7 @@ js::XDRInterpretedFunction(XDRState *xdr, HandleObject enclosingScope, Han if (!xdr->codeUint32(&firstword)) return false; - if ((firstword & 1U) && !XDRAtom(xdr, atom.address())) + if ((firstword & 1U) && !XDRAtom(xdr, &atom)) return false; if (!xdr->codeUint32(&flagsword)) return false; diff --git a/js/src/jsprvtd.h b/js/src/jsprvtd.h index 9d6c9e16cd91..2fbfc54aa14c 100644 --- a/js/src/jsprvtd.h +++ b/js/src/jsprvtd.h @@ -298,7 +298,7 @@ typedef void /* called just before script destruction */ typedef void (* JSDestroyScriptHook)(JSFreeOp *fop, - JSScript *script, + JSRawScript script, void *callerdata); typedef void diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 724a0f5dfb63..30d07d6dcd2d 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -187,7 +187,7 @@ XDRScriptBindings(XDRState *xdr, LifoAllocScope &las, unsigned numArgs, un if (mode == XDR_ENCODE) { for (BindingIter bi(script); bi; bi++) { - JSAtom *atom = bi->name(); + RootedAtom atom(cx, bi->name()); if (!XDRAtom(xdr, &atom)) return false; } @@ -204,7 +204,7 @@ XDRScriptBindings(XDRState *xdr, LifoAllocScope &las, unsigned numArgs, un if (!atoms.resize(nameCount)) return false; for (unsigned i = 0; i < nameCount; i++) { - JSAtom *atom; + RootedAtom atom(cx); if (!XDRAtom(xdr, &atom)) return false; atoms[i] = StringValue(atom); @@ -275,6 +275,8 @@ template static bool XDRScriptConst(XDRState *xdr, HeapValue *vp) { + JSContext *cx = xdr->cx(); + /* * A script constant can be an arbitrary primitive value as they are used * to implement JSOP_LOOKUPSWITCH. But they cannot be objects, see @@ -335,7 +337,7 @@ XDRScriptConst(XDRState *xdr, HeapValue *vp) break; } case SCRIPT_ATOM: { - JSAtom *atom; + RootedAtom atom(cx); if (mode == XDR_ENCODE) atom = &vp->toString()->asAtom(); if (!XDRAtom(xdr, &atom)) @@ -365,7 +367,7 @@ XDRScriptConst(XDRState *xdr, HeapValue *vp) } static inline uint32_t -FindBlockIndex(JSScript *script, StaticBlockObject &block) +FindBlockIndex(RawScript script, StaticBlockObject &block) { ObjectArray *objects = script->objects(); HeapPtrObject *vector = objects->vector; @@ -633,12 +635,12 @@ js::XDRScript(XDRState *xdr, HandleObject enclosingScope, HandleScript enc for (i = 0; i != natoms; ++i) { if (mode == XDR_DECODE) { - JSAtom *tmp = NULL; + RootedAtom tmp(cx); if (!XDRAtom(xdr, &tmp)) return false; script->atoms[i].init(tmp); } else { - JSAtom *tmp = script->atoms[i]; + RootedAtom tmp(cx, script->atoms[i]); if (!XDRAtom(xdr, &tmp)) return false; } @@ -653,7 +655,7 @@ js::XDRScript(XDRState *xdr, HandleObject enclosingScope, HandleScript enc HeapPtr *objp = &script->objects()->vector[i]; uint32_t isBlock; if (mode == XDR_ENCODE) { - JSObject *obj = *objp; + RawObject obj = *objp; JS_ASSERT(obj->isFunction() || obj->isStaticBlock()); isBlock = obj->isBlock() ? 1 : 0; } @@ -1487,11 +1489,11 @@ JSScript::Create(JSContext *cx, HandleObject enclosingScope, bool savedCallerFun const CompileOptions &options, unsigned staticLevel, ScriptSource *ss, uint32_t bufStart, uint32_t bufEnd) { - JSScript *script = js_NewGCScript(cx); + RootedScript script(cx, js_NewGCScript(cx)); if (!script) return NULL; - PodZero(script); + PodZero(script.get()); new (&script->bindings) Bindings; script->enclosingScope_ = enclosingScope; @@ -1511,7 +1513,7 @@ JSScript::Create(JSContext *cx, HandleObject enclosingScope, bool savedCallerFun script->compileAndGo = options.compileAndGo; script->noScriptRval = options.noScriptRval; - + script->version = options.version; JS_ASSERT(script->getVersion() == options.version); // assert that no overflow occurred @@ -1778,10 +1780,10 @@ JSScript::enclosingScriptsCompiledSuccessfully() const * compiles. Thus, we can detect failed compilation by looking for * JSFunctions in the enclosingScope chain without scripts. */ - JSObject *enclosing = enclosingScope_; + RawObject enclosing = enclosingScope_; while (enclosing) { if (enclosing->isFunction()) { - JSFunction *fun = enclosing->toFunction(); + RawFunction fun = enclosing->toFunction(); if (!fun->script()) return false; enclosing = fun->script()->enclosingScope_; @@ -1804,7 +1806,7 @@ js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun) } void -js::CallDestroyScriptHook(FreeOp *fop, JSScript *script) +js::CallDestroyScriptHook(FreeOp *fop, RawScript script) { if (JSDestroyScriptHook hook = fop->runtime()->debugHooks.destroyScriptHook) hook(fop, script, fop->runtime()->debugHooks.destroyScriptHookData); @@ -1865,13 +1867,15 @@ GSNCache::purge() } /* namespace js */ jssrcnote * -js_GetSrcNote(JSContext *cx, JSScript *script, jsbytecode *pc) +js_GetSrcNote(JSContext *cx, RawScript script, jsbytecode *pc) { + GSNCache *cache = &cx->runtime->gsnCache; + cx = NULL; // nulling |cx| ensures GC can't be triggered, so |RawScript script| is safe + size_t target = pc - script->code; if (target >= size_t(script->length)) return NULL; - GSNCache *cache = GetGSNCache(cx); if (cache->code == script->code) { JS_ASSERT(cache->map.initialized()); GSNCache::Map::Ptr p = cache->map.lookup(pc); @@ -1966,21 +1970,20 @@ js::PCToLineNumber(unsigned startLine, jssrcnote *notes, jsbytecode *code, jsbyt } unsigned -js::PCToLineNumber(JSScript *script, jsbytecode *pc, unsigned *columnp) +js::PCToLineNumber(RawScript script, jsbytecode *pc, unsigned *columnp) { /* Cope with StackFrame.pc value prior to entering js_Interpret. */ if (!pc) return 0; - return PCToLineNumber(script->lineno, script->notes(), script->code, pc, - columnp); + return PCToLineNumber(script->lineno, script->notes(), script->code, pc, columnp); } /* The line number limit is the same as the jssrcnote offset limit. */ #define SN_LINE_LIMIT (SN_3BYTE_OFFSET_FLAG << 16) jsbytecode * -js_LineNumberToPC(JSScript *script, unsigned target) +js_LineNumberToPC(RawScript script, unsigned target) { ptrdiff_t offset = 0; ptrdiff_t best = -1; @@ -2015,7 +2018,7 @@ out: } JS_FRIEND_API(unsigned) -js_GetScriptLineExtent(JSScript *script) +js_GetScriptLineExtent(RawScript script) { unsigned lineno = script->lineno; unsigned maxLineNo = 0; @@ -2064,7 +2067,7 @@ CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *line return; } - JSScript *script = iter.script(); + RootedScript script(cx, iter.script()); *file = script->filename; *linenop = PCToLineNumber(iter.script(), iter.pc()); *origin = script->originPrincipals; @@ -2074,7 +2077,7 @@ CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *line template static inline T * -Rebase(JSScript *dst, JSScript *src, T *srcp) +Rebase(RawScript dst, RawScript src, T *srcp) { size_t off = reinterpret_cast(srcp) - src->data; return reinterpret_cast(dst->data + off); @@ -2113,12 +2116,12 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, if (nobjects != 0) { HeapPtrObject *vector = src->objects()->vector; for (unsigned i = 0; i < nobjects; i++) { - JSObject &obj = *vector[i]; - JSObject *clone; - if (obj.isStaticBlock()) { - Rooted innerBlock(cx, &obj.asStaticBlock()); + RootedObject obj(cx, vector[i]); + RootedObject clone(cx); + if (obj->isStaticBlock()) { + Rooted innerBlock(cx, &obj->asStaticBlock()); - Rooted enclosingScope(cx); + RootedObject enclosingScope(cx); if (StaticBlockObject *enclosingBlock = innerBlock->enclosingBlock()) enclosingScope = objects[FindBlockIndex(src, *enclosingBlock)]; else @@ -2126,10 +2129,10 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock); } else { - Rooted innerFun(cx, obj.toFunction()); + RootedFunction innerFun(cx, obj->toFunction()); StaticScopeIter ssi(innerFun->script()->enclosingStaticScope()); - Rooted enclosingScope(cx); + RootedObject enclosingScope(cx); if (!ssi.done() && ssi.type() == StaticScopeIter::BLOCK) enclosingScope = objects[FindBlockIndex(src, ssi.block())]; else @@ -2148,7 +2151,7 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, for (unsigned i = 0; i < nregexps; i++) { HeapPtrObject *vector = src->regexps()->vector; for (unsigned i = 0; i < nregexps; i++) { - JSObject *clone = CloneScriptRegExpObject(cx, vector[i]->asRegExp()); + RawObject clone = CloneScriptRegExpObject(cx, vector[i]->asRegExp()); if (!clone || !regexps.append(clone)) return NULL; } @@ -2162,9 +2165,9 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun, .setCompileAndGo(src->compileAndGo) .setNoScriptRval(src->noScriptRval) .setVersion(src->getVersion()); - JSScript *dst = JSScript::Create(cx, enclosingScope, src->savedCallerFun, - options, src->staticLevel, - src->scriptSource(), src->sourceStart, src->sourceEnd); + RootedScript dst(cx, JSScript::Create(cx, enclosingScope, src->savedCallerFun, + options, src->staticLevel, + src->scriptSource(), src->sourceStart, src->sourceEnd)); if (!dst) { js_free(data); return NULL; @@ -2421,7 +2424,7 @@ JSScript::destroyBreakpointSite(FreeOp *fop, jsbytecode *pc) } void -JSScript::clearBreakpointsIn(FreeOp *fop, js::Debugger *dbg, JSObject *handler) +JSScript::clearBreakpointsIn(FreeOp *fop, js::Debugger *dbg, RawObject handler) { if (!hasAnyBreakpointsOrStepMode()) return; @@ -2536,10 +2539,8 @@ JSScript::setNeedsArgsObj(bool needsArgsObj) } /* static */ bool -JSScript::argumentsOptimizationFailed(JSContext *cx, JSScript *script_) +JSScript::argumentsOptimizationFailed(JSContext *cx, HandleScript script) { - Rooted script(cx, script_); - JS_ASSERT(script->analyzedArgsUsage()); JS_ASSERT(script->argumentsHasVarBinding()); JS_ASSERT(!script->isGenerator); diff --git a/js/src/jsscript.h b/js/src/jsscript.h index 24e3f9735feb..eb25296d5b15 100644 --- a/js/src/jsscript.h +++ b/js/src/jsscript.h @@ -531,7 +531,7 @@ struct JSScript : public js::gc::Cell bool analyzedArgsUsage() const { return !needsArgsAnalysis_; } bool needsArgsObj() const { JS_ASSERT(analyzedArgsUsage()); return needsArgsObj_; } void setNeedsArgsObj(bool needsArgsObj); - static bool argumentsOptimizationFailed(JSContext *cx, JSScript *script); + static bool argumentsOptimizationFailed(JSContext *cx, js::HandleScript script); /* * Arguments access (via JSOP_*ARG* opcodes) must access the canonical @@ -848,7 +848,7 @@ struct JSScript : public js::gc::Cell void destroyBreakpointSite(js::FreeOp *fop, jsbytecode *pc); - void clearBreakpointsIn(js::FreeOp *fop, js::Debugger *dbg, JSObject *handler); + void clearBreakpointsIn(js::FreeOp *fop, js::Debugger *dbg, js::RawObject handler); void clearTraps(js::FreeOp *fop); void markTrapClosures(JSTracer *trc); @@ -1159,7 +1159,7 @@ struct SourceCompressionToken }; extern void -CallDestroyScriptHook(FreeOp *fop, JSScript *script); +CallDestroyScriptHook(FreeOp *fop, js::RawScript script); extern const char * SaveScriptFilename(JSContext *cx, const char *filename); @@ -1210,18 +1210,18 @@ struct ScriptAndCounts } /* namespace js */ extern jssrcnote * -js_GetSrcNote(JSContext *cx, JSScript *script, jsbytecode *pc); +js_GetSrcNote(JSContext *cx, js::RawScript script, jsbytecode *pc); extern jsbytecode * -js_LineNumberToPC(JSScript *script, unsigned lineno); +js_LineNumberToPC(js::RawScript script, unsigned lineno); extern JS_FRIEND_API(unsigned) -js_GetScriptLineExtent(JSScript *script); +js_GetScriptLineExtent(js::RawScript script); namespace js { extern unsigned -PCToLineNumber(JSScript *script, jsbytecode *pc, unsigned *columnp = NULL); +PCToLineNumber(js::RawScript script, jsbytecode *pc, unsigned *columnp = NULL); extern unsigned PCToLineNumber(unsigned startLine, jssrcnote *notes, jsbytecode *code, jsbytecode *pc, diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index cf749888368d..28e88678b07e 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -680,7 +680,7 @@ js::XDRScriptRegExpObject(XDRState *xdr, HeapPtrObject *objp) source = reobj.getSource(); flagsword = reobj.getFlags(); } - if (!XDRAtom(xdr, source.address()) || !xdr->codeUint32(&flagsword)) + if (!XDRAtom(xdr, &source) || !xdr->codeUint32(&flagsword)) return false; if (mode == XDR_DECODE) { RegExpFlag flags = RegExpFlag(flagsword); diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index 0621ae89ed3e..76622a61177a 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -741,7 +741,7 @@ js::XDRStaticBlockObject(XDRState *xdr, HandleObject enclosingScope, Handl * properties to XDR, stored as id/shortid pairs. */ for (unsigned i = 0; i < count; i++) { - JSAtom *atom; + RootedAtom atom(cx); if (!XDRAtom(xdr, &atom)) return false; @@ -786,10 +786,9 @@ js::XDRStaticBlockObject(XDRState *xdr, HandleObject enclosingScope, Handl JS_ASSERT(JSID_IS_ATOM(propid) || JSID_IS_INT(propid)); /* The empty string indicates an int id. */ - JSAtom *atom = JSID_IS_ATOM(propid) - ? JSID_TO_ATOM(propid) - : cx->runtime->emptyString; - + RootedAtom atom(cx, JSID_IS_ATOM(propid) + ? JSID_TO_ATOM(propid) + : cx->runtime->emptyString); if (!XDRAtom(xdr, &atom)) return false;