Bug 630471 - Enter compartment when creating XPC stack frame, before JS_PCToLineNumber (r=gal)

This commit is contained in:
Steve Fink 2011-02-03 11:29:16 -08:00
parent 7b5ff04357
commit 8d967375c9

View File

@ -160,31 +160,35 @@ XPCJSStackFrame::CreateStack(JSContext* cx, JSStackFrame* fp,
jsbytecode* pc = JS_GetFramePC(cx, fp);
if(script && pc)
{
const char* filename = JS_GetScriptFilename(cx, script);
if(filename)
{
self->mFilename = (char*)
nsMemory::Clone(filename,
sizeof(char)*(strlen(filename)+1));
}
self->mLineno = (PRInt32) JS_PCToLineNumber(cx, script, pc);
JSFunction* fun = JS_GetFrameFunction(cx, fp);
if(fun)
{
JSString *funid = JS_GetFunctionId(fun);
if(funid)
JSAutoEnterCompartment ac;
if(ac.enter(cx, script))
{
const char* filename = JS_GetScriptFilename(cx, script);
if(filename)
{
size_t length = JS_GetStringEncodingLength(cx, funid);
if(length != size_t(-1))
self->mFilename = (char*)
nsMemory::Clone(filename,
sizeof(char)*(strlen(filename)+1));
}
self->mLineno = (PRInt32) JS_PCToLineNumber(cx, script, pc);
JSFunction* fun = JS_GetFrameFunction(cx, fp);
if(fun)
{
JSString *funid = JS_GetFunctionId(fun);
if(funid)
{
self->mFunname = static_cast<char *>(nsMemory::Alloc(length + 1));
if(self->mFunname)
size_t length = JS_GetStringEncodingLength(cx, funid);
if(length != size_t(-1))
{
JS_EncodeStringToBuffer(funid, self->mFunname, length);
self->mFunname[length] = '\0';
self->mFunname = static_cast<char *>(nsMemory::Alloc(length + 1));
if(self->mFunname)
{
JS_EncodeStringToBuffer(funid, self->mFunname, length);
self->mFunname[length] = '\0';
}
}
}
}