Bug 797695 (part 4) - Exactly root jsscript.cpp. r=terrence.

--HG--
extra : rebase_source : b6cc292b092b30e339a75921245d4605275c104d
This commit is contained in:
Nicholas Nethercote 2012-10-04 16:22:03 -07:00
Родитель 8fbf1bdfc3
Коммит 7df073ff5b
10 изменённых файлов: 59 добавлений и 68 удалений

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

@ -430,14 +430,14 @@ js::InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
template<XDRMode mode> template<XDRMode mode>
bool bool
js::XDRAtom(XDRState<mode> *xdr, JSAtom **atomp) js::XDRAtom(XDRState<mode> *xdr, MutableHandleAtom atomp)
{ {
if (mode == XDR_ENCODE) { if (mode == XDR_ENCODE) {
uint32_t nchars = (*atomp)->length(); uint32_t nchars = atomp->length();
if (!xdr->codeUint32(&nchars)) if (!xdr->codeUint32(&nchars))
return false; return false;
jschar *chars = const_cast<jschar *>((*atomp)->getChars(xdr->cx())); jschar *chars = const_cast<jschar *>(atomp->getChars(xdr->cx()));
if (!chars) if (!chars)
return false; return false;
@ -483,13 +483,13 @@ js::XDRAtom(XDRState<mode> *xdr, JSAtom **atomp)
if (!atom) if (!atom)
return false; return false;
*atomp = atom; atomp.set(atom);
return true; return true;
} }
template bool template bool
js::XDRAtom(XDRState<XDR_ENCODE> *xdr, JSAtom **atomp); js::XDRAtom(XDRState<XDR_ENCODE> *xdr, MutableHandleAtom atomp);
template bool template bool
js::XDRAtom(XDRState<XDR_DECODE> *xdr, JSAtom **atomp); js::XDRAtom(XDRState<XDR_DECODE> *xdr, MutableHandleAtom atomp);

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

@ -272,7 +272,7 @@ InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval, jsid *id
template<XDRMode mode> template<XDRMode mode>
bool bool
XDRAtom(XDRState<mode> *xdr, JSAtom **atomp); XDRAtom(XDRState<mode> *xdr, js::MutableHandleAtom atomp);
} /* namespace js */ } /* namespace js */

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

@ -120,9 +120,6 @@ struct GSNCache {
void purge(); void purge();
}; };
inline GSNCache *
GetGSNCache(JSContext *cx);
typedef Vector<ScriptAndCounts, 0, SystemAllocPolicy> ScriptAndCountsVector; typedef Vector<ScriptAndCounts, 0, SystemAllocPolicy> ScriptAndCountsVector;
struct ConservativeGCData struct ConservativeGCData

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

@ -134,12 +134,6 @@ struct PreserveRegsGuard
FrameRegs &regs_; FrameRegs &regs_;
}; };
inline GSNCache *
GetGSNCache(JSContext *cx)
{
return &cx->runtime->gsnCache;
}
#if JS_HAS_XML_SUPPORT #if JS_HAS_XML_SUPPORT
class AutoNamespaceArray : protected AutoGCRooter { class AutoNamespaceArray : protected AutoGCRooter {

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

@ -405,7 +405,7 @@ js::XDRInterpretedFunction(XDRState<mode> *xdr, HandleObject enclosingScope, Han
if (!xdr->codeUint32(&firstword)) if (!xdr->codeUint32(&firstword))
return false; return false;
if ((firstword & 1U) && !XDRAtom(xdr, atom.address())) if ((firstword & 1U) && !XDRAtom(xdr, &atom))
return false; return false;
if (!xdr->codeUint32(&flagsword)) if (!xdr->codeUint32(&flagsword))
return false; return false;

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

@ -298,7 +298,7 @@ typedef void
/* called just before script destruction */ /* called just before script destruction */
typedef void typedef void
(* JSDestroyScriptHook)(JSFreeOp *fop, (* JSDestroyScriptHook)(JSFreeOp *fop,
JSScript *script, JSRawScript script,
void *callerdata); void *callerdata);
typedef void typedef void

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

@ -187,7 +187,7 @@ XDRScriptBindings(XDRState<mode> *xdr, LifoAllocScope &las, unsigned numArgs, un
if (mode == XDR_ENCODE) { if (mode == XDR_ENCODE) {
for (BindingIter bi(script); bi; bi++) { for (BindingIter bi(script); bi; bi++) {
JSAtom *atom = bi->name(); RootedAtom atom(cx, bi->name());
if (!XDRAtom(xdr, &atom)) if (!XDRAtom(xdr, &atom))
return false; return false;
} }
@ -204,7 +204,7 @@ XDRScriptBindings(XDRState<mode> *xdr, LifoAllocScope &las, unsigned numArgs, un
if (!atoms.resize(nameCount)) if (!atoms.resize(nameCount))
return false; return false;
for (unsigned i = 0; i < nameCount; i++) { for (unsigned i = 0; i < nameCount; i++) {
JSAtom *atom; RootedAtom atom(cx);
if (!XDRAtom(xdr, &atom)) if (!XDRAtom(xdr, &atom))
return false; return false;
atoms[i] = StringValue(atom); atoms[i] = StringValue(atom);
@ -275,6 +275,8 @@ template<XDRMode mode>
static bool static bool
XDRScriptConst(XDRState<mode> *xdr, HeapValue *vp) XDRScriptConst(XDRState<mode> *xdr, HeapValue *vp)
{ {
JSContext *cx = xdr->cx();
/* /*
* A script constant can be an arbitrary primitive value as they are used * A script constant can be an arbitrary primitive value as they are used
* to implement JSOP_LOOKUPSWITCH. But they cannot be objects, see * to implement JSOP_LOOKUPSWITCH. But they cannot be objects, see
@ -335,7 +337,7 @@ XDRScriptConst(XDRState<mode> *xdr, HeapValue *vp)
break; break;
} }
case SCRIPT_ATOM: { case SCRIPT_ATOM: {
JSAtom *atom; RootedAtom atom(cx);
if (mode == XDR_ENCODE) if (mode == XDR_ENCODE)
atom = &vp->toString()->asAtom(); atom = &vp->toString()->asAtom();
if (!XDRAtom(xdr, &atom)) if (!XDRAtom(xdr, &atom))
@ -365,7 +367,7 @@ XDRScriptConst(XDRState<mode> *xdr, HeapValue *vp)
} }
static inline uint32_t static inline uint32_t
FindBlockIndex(JSScript *script, StaticBlockObject &block) FindBlockIndex(RawScript script, StaticBlockObject &block)
{ {
ObjectArray *objects = script->objects(); ObjectArray *objects = script->objects();
HeapPtrObject *vector = objects->vector; HeapPtrObject *vector = objects->vector;
@ -633,12 +635,12 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
for (i = 0; i != natoms; ++i) { for (i = 0; i != natoms; ++i) {
if (mode == XDR_DECODE) { if (mode == XDR_DECODE) {
JSAtom *tmp = NULL; RootedAtom tmp(cx);
if (!XDRAtom(xdr, &tmp)) if (!XDRAtom(xdr, &tmp))
return false; return false;
script->atoms[i].init(tmp); script->atoms[i].init(tmp);
} else { } else {
JSAtom *tmp = script->atoms[i]; RootedAtom tmp(cx, script->atoms[i]);
if (!XDRAtom(xdr, &tmp)) if (!XDRAtom(xdr, &tmp))
return false; return false;
} }
@ -653,7 +655,7 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
HeapPtr<JSObject> *objp = &script->objects()->vector[i]; HeapPtr<JSObject> *objp = &script->objects()->vector[i];
uint32_t isBlock; uint32_t isBlock;
if (mode == XDR_ENCODE) { if (mode == XDR_ENCODE) {
JSObject *obj = *objp; RawObject obj = *objp;
JS_ASSERT(obj->isFunction() || obj->isStaticBlock()); JS_ASSERT(obj->isFunction() || obj->isStaticBlock());
isBlock = obj->isBlock() ? 1 : 0; isBlock = obj->isBlock() ? 1 : 0;
} }
@ -1487,11 +1489,11 @@ JSScript::Create(JSContext *cx, HandleObject enclosingScope, bool savedCallerFun
const CompileOptions &options, unsigned staticLevel, const CompileOptions &options, unsigned staticLevel,
ScriptSource *ss, uint32_t bufStart, uint32_t bufEnd) ScriptSource *ss, uint32_t bufStart, uint32_t bufEnd)
{ {
JSScript *script = js_NewGCScript(cx); RootedScript script(cx, js_NewGCScript(cx));
if (!script) if (!script)
return NULL; return NULL;
PodZero(script); PodZero(script.get());
new (&script->bindings) Bindings; new (&script->bindings) Bindings;
script->enclosingScope_ = enclosingScope; script->enclosingScope_ = enclosingScope;
@ -1778,10 +1780,10 @@ JSScript::enclosingScriptsCompiledSuccessfully() const
* compiles. Thus, we can detect failed compilation by looking for * compiles. Thus, we can detect failed compilation by looking for
* JSFunctions in the enclosingScope chain without scripts. * JSFunctions in the enclosingScope chain without scripts.
*/ */
JSObject *enclosing = enclosingScope_; RawObject enclosing = enclosingScope_;
while (enclosing) { while (enclosing) {
if (enclosing->isFunction()) { if (enclosing->isFunction()) {
JSFunction *fun = enclosing->toFunction(); RawFunction fun = enclosing->toFunction();
if (!fun->script()) if (!fun->script())
return false; return false;
enclosing = fun->script()->enclosingScope_; enclosing = fun->script()->enclosingScope_;
@ -1804,7 +1806,7 @@ js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun)
} }
void void
js::CallDestroyScriptHook(FreeOp *fop, JSScript *script) js::CallDestroyScriptHook(FreeOp *fop, RawScript script)
{ {
if (JSDestroyScriptHook hook = fop->runtime()->debugHooks.destroyScriptHook) if (JSDestroyScriptHook hook = fop->runtime()->debugHooks.destroyScriptHook)
hook(fop, script, fop->runtime()->debugHooks.destroyScriptHookData); hook(fop, script, fop->runtime()->debugHooks.destroyScriptHookData);
@ -1865,13 +1867,15 @@ GSNCache::purge()
} /* namespace js */ } /* namespace js */
jssrcnote * 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; size_t target = pc - script->code;
if (target >= size_t(script->length)) if (target >= size_t(script->length))
return NULL; return NULL;
GSNCache *cache = GetGSNCache(cx);
if (cache->code == script->code) { if (cache->code == script->code) {
JS_ASSERT(cache->map.initialized()); JS_ASSERT(cache->map.initialized());
GSNCache::Map::Ptr p = cache->map.lookup(pc); GSNCache::Map::Ptr p = cache->map.lookup(pc);
@ -1966,21 +1970,20 @@ js::PCToLineNumber(unsigned startLine, jssrcnote *notes, jsbytecode *code, jsbyt
} }
unsigned 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. */ /* Cope with StackFrame.pc value prior to entering js_Interpret. */
if (!pc) if (!pc)
return 0; return 0;
return PCToLineNumber(script->lineno, script->notes(), script->code, pc, return PCToLineNumber(script->lineno, script->notes(), script->code, pc, columnp);
columnp);
} }
/* The line number limit is the same as the jssrcnote offset limit. */ /* The line number limit is the same as the jssrcnote offset limit. */
#define SN_LINE_LIMIT (SN_3BYTE_OFFSET_FLAG << 16) #define SN_LINE_LIMIT (SN_3BYTE_OFFSET_FLAG << 16)
jsbytecode * jsbytecode *
js_LineNumberToPC(JSScript *script, unsigned target) js_LineNumberToPC(RawScript script, unsigned target)
{ {
ptrdiff_t offset = 0; ptrdiff_t offset = 0;
ptrdiff_t best = -1; ptrdiff_t best = -1;
@ -2015,7 +2018,7 @@ out:
} }
JS_FRIEND_API(unsigned) JS_FRIEND_API(unsigned)
js_GetScriptLineExtent(JSScript *script) js_GetScriptLineExtent(RawScript script)
{ {
unsigned lineno = script->lineno; unsigned lineno = script->lineno;
unsigned maxLineNo = 0; unsigned maxLineNo = 0;
@ -2064,7 +2067,7 @@ CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *line
return; return;
} }
JSScript *script = iter.script(); RootedScript script(cx, iter.script());
*file = script->filename; *file = script->filename;
*linenop = PCToLineNumber(iter.script(), iter.pc()); *linenop = PCToLineNumber(iter.script(), iter.pc());
*origin = script->originPrincipals; *origin = script->originPrincipals;
@ -2074,7 +2077,7 @@ CurrentScriptFileLineOriginSlow(JSContext *cx, const char **file, unsigned *line
template <class T> template <class T>
static inline T * static inline T *
Rebase(JSScript *dst, JSScript *src, T *srcp) Rebase(RawScript dst, RawScript src, T *srcp)
{ {
size_t off = reinterpret_cast<uint8_t *>(srcp) - src->data; size_t off = reinterpret_cast<uint8_t *>(srcp) - src->data;
return reinterpret_cast<T *>(dst->data + off); return reinterpret_cast<T *>(dst->data + off);
@ -2113,12 +2116,12 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
if (nobjects != 0) { if (nobjects != 0) {
HeapPtrObject *vector = src->objects()->vector; HeapPtrObject *vector = src->objects()->vector;
for (unsigned i = 0; i < nobjects; i++) { for (unsigned i = 0; i < nobjects; i++) {
JSObject &obj = *vector[i]; RootedObject obj(cx, vector[i]);
JSObject *clone; RootedObject clone(cx);
if (obj.isStaticBlock()) { if (obj->isStaticBlock()) {
Rooted<StaticBlockObject*> innerBlock(cx, &obj.asStaticBlock()); Rooted<StaticBlockObject*> innerBlock(cx, &obj->asStaticBlock());
Rooted<JSObject*> enclosingScope(cx); RootedObject enclosingScope(cx);
if (StaticBlockObject *enclosingBlock = innerBlock->enclosingBlock()) if (StaticBlockObject *enclosingBlock = innerBlock->enclosingBlock())
enclosingScope = objects[FindBlockIndex(src, *enclosingBlock)]; enclosingScope = objects[FindBlockIndex(src, *enclosingBlock)];
else else
@ -2126,10 +2129,10 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock); clone = CloneStaticBlockObject(cx, enclosingScope, innerBlock);
} else { } else {
Rooted<JSFunction*> innerFun(cx, obj.toFunction()); RootedFunction innerFun(cx, obj->toFunction());
StaticScopeIter ssi(innerFun->script()->enclosingStaticScope()); StaticScopeIter ssi(innerFun->script()->enclosingStaticScope());
Rooted<JSObject*> 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())];
else else
@ -2148,7 +2151,7 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
for (unsigned i = 0; i < nregexps; i++) { for (unsigned i = 0; i < nregexps; i++) {
HeapPtrObject *vector = src->regexps()->vector; HeapPtrObject *vector = src->regexps()->vector;
for (unsigned i = 0; i < nregexps; i++) { 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)) if (!clone || !regexps.append(clone))
return NULL; return NULL;
} }
@ -2162,9 +2165,9 @@ js::CloneScript(JSContext *cx, HandleObject enclosingScope, HandleFunction fun,
.setCompileAndGo(src->compileAndGo) .setCompileAndGo(src->compileAndGo)
.setNoScriptRval(src->noScriptRval) .setNoScriptRval(src->noScriptRval)
.setVersion(src->getVersion()); .setVersion(src->getVersion());
JSScript *dst = JSScript::Create(cx, enclosingScope, src->savedCallerFun, RootedScript dst(cx, JSScript::Create(cx, enclosingScope, src->savedCallerFun,
options, src->staticLevel, options, src->staticLevel,
src->scriptSource(), src->sourceStart, src->sourceEnd); src->scriptSource(), src->sourceStart, src->sourceEnd));
if (!dst) { if (!dst) {
js_free(data); js_free(data);
return NULL; return NULL;
@ -2421,7 +2424,7 @@ JSScript::destroyBreakpointSite(FreeOp *fop, jsbytecode *pc)
} }
void void
JSScript::clearBreakpointsIn(FreeOp *fop, js::Debugger *dbg, JSObject *handler) JSScript::clearBreakpointsIn(FreeOp *fop, js::Debugger *dbg, RawObject handler)
{ {
if (!hasAnyBreakpointsOrStepMode()) if (!hasAnyBreakpointsOrStepMode())
return; return;
@ -2536,10 +2539,8 @@ JSScript::setNeedsArgsObj(bool needsArgsObj)
} }
/* static */ bool /* static */ bool
JSScript::argumentsOptimizationFailed(JSContext *cx, JSScript *script_) JSScript::argumentsOptimizationFailed(JSContext *cx, HandleScript script)
{ {
Rooted<JSScript*> script(cx, script_);
JS_ASSERT(script->analyzedArgsUsage()); JS_ASSERT(script->analyzedArgsUsage());
JS_ASSERT(script->argumentsHasVarBinding()); JS_ASSERT(script->argumentsHasVarBinding());
JS_ASSERT(!script->isGenerator); JS_ASSERT(!script->isGenerator);

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

@ -531,7 +531,7 @@ struct JSScript : public js::gc::Cell
bool analyzedArgsUsage() const { return !needsArgsAnalysis_; } bool analyzedArgsUsage() const { return !needsArgsAnalysis_; }
bool needsArgsObj() const { JS_ASSERT(analyzedArgsUsage()); return needsArgsObj_; } bool needsArgsObj() const { JS_ASSERT(analyzedArgsUsage()); return needsArgsObj_; }
void setNeedsArgsObj(bool 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 * 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 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 clearTraps(js::FreeOp *fop);
void markTrapClosures(JSTracer *trc); void markTrapClosures(JSTracer *trc);
@ -1159,7 +1159,7 @@ struct SourceCompressionToken
}; };
extern void extern void
CallDestroyScriptHook(FreeOp *fop, JSScript *script); CallDestroyScriptHook(FreeOp *fop, js::RawScript script);
extern const char * extern const char *
SaveScriptFilename(JSContext *cx, const char *filename); SaveScriptFilename(JSContext *cx, const char *filename);
@ -1210,18 +1210,18 @@ struct ScriptAndCounts
} /* namespace js */ } /* namespace js */
extern jssrcnote * extern jssrcnote *
js_GetSrcNote(JSContext *cx, JSScript *script, jsbytecode *pc); js_GetSrcNote(JSContext *cx, js::RawScript script, jsbytecode *pc);
extern jsbytecode * extern jsbytecode *
js_LineNumberToPC(JSScript *script, unsigned lineno); js_LineNumberToPC(js::RawScript script, unsigned lineno);
extern JS_FRIEND_API(unsigned) extern JS_FRIEND_API(unsigned)
js_GetScriptLineExtent(JSScript *script); js_GetScriptLineExtent(js::RawScript script);
namespace js { namespace js {
extern unsigned extern unsigned
PCToLineNumber(JSScript *script, jsbytecode *pc, unsigned *columnp = NULL); PCToLineNumber(js::RawScript script, jsbytecode *pc, unsigned *columnp = NULL);
extern unsigned extern unsigned
PCToLineNumber(unsigned startLine, jssrcnote *notes, jsbytecode *code, jsbytecode *pc, PCToLineNumber(unsigned startLine, jssrcnote *notes, jsbytecode *code, jsbytecode *pc,

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

@ -680,7 +680,7 @@ js::XDRScriptRegExpObject(XDRState<mode> *xdr, HeapPtrObject *objp)
source = reobj.getSource(); source = reobj.getSource();
flagsword = reobj.getFlags(); flagsword = reobj.getFlags();
} }
if (!XDRAtom(xdr, source.address()) || !xdr->codeUint32(&flagsword)) if (!XDRAtom(xdr, &source) || !xdr->codeUint32(&flagsword))
return false; return false;
if (mode == XDR_DECODE) { if (mode == XDR_DECODE) {
RegExpFlag flags = RegExpFlag(flagsword); RegExpFlag flags = RegExpFlag(flagsword);

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

@ -741,7 +741,7 @@ js::XDRStaticBlockObject(XDRState<mode> *xdr, HandleObject enclosingScope, Handl
* properties to XDR, stored as id/shortid pairs. * properties to XDR, stored as id/shortid pairs.
*/ */
for (unsigned i = 0; i < count; i++) { for (unsigned i = 0; i < count; i++) {
JSAtom *atom; RootedAtom atom(cx);
if (!XDRAtom(xdr, &atom)) if (!XDRAtom(xdr, &atom))
return false; return false;
@ -786,10 +786,9 @@ js::XDRStaticBlockObject(XDRState<mode> *xdr, HandleObject enclosingScope, Handl
JS_ASSERT(JSID_IS_ATOM(propid) || JSID_IS_INT(propid)); JS_ASSERT(JSID_IS_ATOM(propid) || JSID_IS_INT(propid));
/* The empty string indicates an int id. */ /* The empty string indicates an int id. */
JSAtom *atom = JSID_IS_ATOM(propid) RootedAtom atom(cx, JSID_IS_ATOM(propid)
? JSID_TO_ATOM(propid) ? JSID_TO_ATOM(propid)
: cx->runtime->emptyString; : cx->runtime->emptyString);
if (!XDRAtom(xdr, &atom)) if (!XDRAtom(xdr, &atom))
return false; return false;