Bug 440982 To avoid calling JS at unsafe times from JS_GC, jsds_ScriptHookProc should not get the script hook unless it needs to and it is safe to call
authortimeless@mozdev.org
Thu, 04 Jun 2009 21:00:56 -0400
changeset 28945 040cb204cd926d17b8be1062f48ac8665144cd96
parent 28944 fdecaf027ede916b818d6f11bcf38845f14f841b
child 28946 c2542ef0c8ef04eae1c8af06f0d01bc8320b3ed2
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs440982
milestone1.9.2a1pre
Bug 440982 To avoid calling JS at unsafe times from JS_GC, jsds_ScriptHookProc should not get the script hook unless it needs to and it is safe to call r=brendan sr=brendan
js/jsd/jsd_xpc.cpp
--- a/js/jsd/jsd_xpc.cpp
+++ b/js/jsd/jsd_xpc.cpp
@@ -702,20 +702,20 @@ static void
 jsds_ScriptHookProc (JSDContext* jsdc, JSDScript* jsdscript, JSBool creating,
                      void* callerdata)
 {
 #ifdef CAUTIOUS_SCRIPTHOOK
     JSContext *cx = JSD_GetDefaultJSContext(jsdc);
     JSRuntime *rt = JS_GetRuntime(cx);
 #endif
 
-    nsCOMPtr<jsdIScriptHook> hook;
-    gJsds->GetScriptHook (getter_AddRefs(hook));
-    
     if (creating) {
+        nsCOMPtr<jsdIScriptHook> hook;
+        gJsds->GetScriptHook(getter_AddRefs(hook));
+
         /* a script is being created */
         if (!hook) {
             /* nobody cares, just exit */
             return;
         }
             
         nsCOMPtr<jsdIScript> script = 
             getter_AddRefs(jsdScript::FromPtr(jsdc, jsdscript));
@@ -731,22 +731,25 @@ jsds_ScriptHookProc (JSDContext* jsdc, J
     } else {
         /* a script is being destroyed.  even if there is no registered hook
          * we'll still need to invalidate the jsdIScript record, in order
          * to remove the reference held in the JSDScript private data. */
         nsCOMPtr<jsdIScript> jsdis = 
             static_cast<jsdIScript *>(JSD_GetScriptPrivate(jsdscript));
         if (!jsdis)
             return;
-        
+
         jsdis->Invalidate();
-        if (!hook)
-            return;
-        
+
         if (gGCStatus == JSGC_END) {
+            nsCOMPtr<jsdIScriptHook> hook;
+            gJsds->GetScriptHook(getter_AddRefs(hook));
+            if (!hook)
+                return;
+
             /* if GC *isn't* running, we can tell the user about the script
              * delete now. */
 #ifdef CAUTIOUS_SCRIPTHOOK
             JS_UNKEEP_ATOMS(rt);
 #endif
                 
             gJsds->Pause(nsnull);
             hook->OnScriptDestroyed (jsdis);