diff --git a/js/src/xpconnect/src/xpcstack.cpp b/js/src/xpconnect/src/xpcstack.cpp index 2482e3ecef7..7eed9dbe7c7 100644 --- a/js/src/xpconnect/src/xpcstack.cpp +++ b/js/src/xpconnect/src/xpcstack.cpp @@ -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(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(nsMemory::Alloc(length + 1)); + if(self->mFunname) + { + JS_EncodeStringToBuffer(funid, self->mFunname, length); + self->mFunname[length] = '\0'; + } } } }