Bug 630471 - Enter compartment when creating XPC stack frame, before JS_PCToLineNumber (r=gal)
authorSteve Fink <sfink@mozilla.com>
Thu, 03 Feb 2011 11:29:16 -0800
changeset 62072 d461afeeae3def4eed95d55184296e3682540ff6
parent 62071 e8c7fea4eff36f732c1e4d9155d935c6c0fdce2d
child 62073 13ddee17c69141e356ec0baca64629dfde31d352
push idunknown
push userunknown
push dateunknown
reviewersgal
bugs630471
milestone2.0b11pre
Bug 630471 - Enter compartment when creating XPC stack frame, before JS_PCToLineNumber (r=gal)
js/src/xpconnect/src/xpcstack.cpp
--- a/js/src/xpconnect/src/xpcstack.cpp
+++ b/js/src/xpconnect/src/xpcstack.cpp
@@ -155,41 +155,45 @@ XPCJSStackFrame::CreateStack(JSContext* 
             else
                 self->mLanguage = nsIProgrammingLanguage::JAVASCRIPT;
             if(self->IsJSFrame())
             {
                 JSScript* script = JS_GetFrameScript(cx, 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));
-                    }
+                    JSAutoEnterCompartment ac;
+                    if(ac.enter(cx, script))
+                     {
+                         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);
+                        self->mLineno = (PRInt32) JS_PCToLineNumber(cx, script, pc);
 
 
-                    JSFunction* fun = JS_GetFrameFunction(cx, fp);
-                    if(fun)
-                    {
-                        JSString *funid = JS_GetFunctionId(fun);
-                        if(funid)
+                        JSFunction* fun = JS_GetFrameFunction(cx, fp);
+                        if(fun)
                         {
-                            size_t length = JS_GetStringEncodingLength(cx, funid);
-                            if(length != size_t(-1))
+                            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';
+                                    }
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     self->mLanguage = nsIProgrammingLanguage::CPLUSPLUS;