Bug 480765 - Scripts compiled before the debugger got activated cannot be debugged; r=timeless
authorWladimir Palant <trev.moz@adblockplus.org>
Sat, 14 Mar 2009 15:57:31 +0100
changeset 26156 49de852e98375226891719076db042862d6a1d14
parent 26155 1c7bfa72ed991bceb2a430debdb8fbaa1b0eab8c
child 26157 c825590cf53fc4da706c66abb2001f307f5c5732
push idunknown
push userunknown
push dateunknown
reviewerstimeless
bugs480765
milestone1.9.2a1pre
Bug 480765 - Scripts compiled before the debugger got activated cannot be debugged; r=timeless
js/jsd/jsd.h
js/jsd/jsd_hook.c
js/jsd/jsd_obj.c
js/jsd/jsd_scpt.c
js/jsd/jsd_step.c
--- a/js/jsd/jsd.h
+++ b/js/jsd/jsd.h
@@ -384,16 +384,22 @@ jsd_InitScriptManager(JSDContext *jsdc);
 
 extern void
 jsd_DestroyScriptManager(JSDContext* jsdc);
 
 extern JSDScript*
 jsd_FindJSDScript(JSDContext*  jsdc,
                   JSScript     *script);
 
+extern JSDScript*
+jsd_FindOrCreateJSDScript(JSDContext    *jsdc,
+                          JSContext     *cx,
+                          JSScript      *script,
+                          JSStackFrame  *fp);
+
 extern JSDProfileData*
 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script);
 
 extern uint32
 jsd_GetScriptFlags(JSDContext *jsdc, JSDScript *script);
 
 extern void
 jsd_SetScriptFlags(JSDContext *jsdc, JSDScript *script, uint32 flags);
--- a/js/jsd/jsd_hook.c
+++ b/js/jsd/jsd_hook.c
@@ -61,17 +61,17 @@ jsd_InterruptHandler(JSContext *cx, JSSc
     hook     = jsdc->interruptHook;
     hookData = jsdc->interruptHookData;
     JSD_UNLOCK();
 
     if (!hook)
         return JSTRAP_CONTINUE;
     
     JSD_LOCK_SCRIPTS(jsdc);
-    jsdscript = jsd_FindJSDScript(jsdc, script);
+    jsdscript = jsd_FindOrCreateJSDScript(jsdc, cx, script, NULL);
     JSD_UNLOCK_SCRIPTS(jsdc);
     if( ! jsdscript )
         return JSTRAP_CONTINUE;
 
 #ifdef LIVEWIRE
     if( ! jsdlw_UserCodeAtPC(jsdc, jsdscript, (jsuword)pc) )
         return JSTRAP_CONTINUE;
 #endif
@@ -99,17 +99,17 @@ jsd_DebuggerHandler(JSContext *cx, JSScr
     JSD_LOCK();
     hook     = jsdc->debuggerHook;
     hookData = jsdc->debuggerHookData;
     JSD_UNLOCK();
     if(!hook)
         return JSTRAP_CONTINUE;
 
     JSD_LOCK_SCRIPTS(jsdc);
-    jsdscript = jsd_FindJSDScript(jsdc, script);
+    jsdscript = jsd_FindOrCreateJSDScript(jsdc, cx, script, NULL);
     JSD_UNLOCK_SCRIPTS(jsdc);
     if( ! jsdscript )
         return JSTRAP_CONTINUE;
 
     return jsd_CallExecutionHook(jsdc, cx, JSD_HOOK_DEBUGGER_KEYWORD,
                                  hook, hookData, rval);
 }
 
@@ -133,17 +133,17 @@ jsd_ThrowHandler(JSContext *cx, JSScript
     JSD_LOCK();
     hook     = jsdc->throwHook;
     hookData = jsdc->throwHookData;
     JSD_UNLOCK();
     if (!hook)
         return JSD_HOOK_RETURN_CONTINUE_THROW;
 
     JSD_LOCK_SCRIPTS(jsdc);
-    jsdscript = jsd_FindJSDScript(jsdc, script);
+    jsdscript = jsd_FindOrCreateJSDScript(jsdc, cx, script, NULL);
     JSD_UNLOCK_SCRIPTS(jsdc);
     if( ! jsdscript )
         return JSD_HOOK_RETURN_CONTINUE_THROW;
 
     JS_GetPendingException(cx, rval);
 
     return jsd_CallExecutionHook(jsdc, cx, JSD_HOOK_THROW,
                                  hook, hookData, rval);
--- a/js/jsd/jsd_obj.c
+++ b/js/jsd/jsd_obj.c
@@ -200,17 +200,17 @@ jsd_Constructing(JSDContext* jsdc, JSCon
         script = JS_GetFrameScript(cx, fp);
         if( script )
         {
             ctorURL = JS_GetScriptFilename(cx, script);
             if( ctorURL )
                 jsdobj->ctorURL = jsd_AddAtom(jsdc, ctorURL);
 
             JSD_LOCK_SCRIPTS(jsdc);
-            jsdscript = jsd_FindJSDScript(jsdc, script);
+            jsdscript = jsd_FindOrCreateJSDScript(jsdc, cx, script, fp);
             JSD_UNLOCK_SCRIPTS(jsdc);
             if( jsdscript )
             {
                 ctorName = jsd_GetScriptFunctionName(jsdc, jsdscript);
                 if( ctorName )
                     jsdobj->ctorName = jsd_AddAtom(jsdc, ctorName);
             }
             jsdobj->ctorLineno = JS_GetScriptBaseLineNumber(cx, script);
--- a/js/jsd/jsd_scpt.c
+++ b/js/jsd/jsd_scpt.c
@@ -279,17 +279,39 @@ jsd_DestroyScriptManager(JSDContext* jsd
 }
 
 JSDScript*
 jsd_FindJSDScript( JSDContext*  jsdc,
                    JSScript     *script )
 {
     JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
     return (JSDScript*) JS_HashTableLookup(jsdc->scriptsTable, (void *)script);
-}               
+}
+
+JSDScript *
+jsd_FindOrCreateJSDScript(JSDContext    *jsdc,
+                          JSContext     *cx,
+                          JSScript      *script,
+                          JSStackFrame  *fp)
+{
+    JSDScript *jsdscript;
+    JS_ASSERT(JSD_SCRIPTS_LOCKED(jsdc));
+
+    jsdscript = jsd_FindJSDScript(jsdc, script);
+    if (jsdscript)
+        return jsdscript;
+
+    // Fallback for unknown scripts: create a new script
+    if (!fp)
+        JS_FrameIterator(cx, &fp);
+    if (fp)
+        jsdscript = _newJSDScript(jsdc, cx, script, JS_GetFrameFunction(cx, fp));
+
+    return jsdscript;
+}
 
 JSDProfileData*
 jsd_GetScriptProfileData(JSDContext* jsdc, JSDScript *script)
 {
     if (!script->profileData)
         script->profileData = (JSDProfileData*)calloc(1, sizeof(JSDProfileData));
 
     return script->profileData;
--- a/js/jsd/jsd_step.c
+++ b/js/jsd/jsd_step.c
@@ -71,17 +71,17 @@ static void
     static indent = 0;
     char* buf;
     const char* funName = NULL;
 
     script = JS_GetFrameScript(cx, fp);
     if(script)
     {
         JSD_LOCK_SCRIPTS(jsdc);
-        jsdscript = jsd_FindJSDScript(jsdc, script);
+        jsdscript = jsd_FindOrCreateJSDScript(jsdc, cx, script, fp);
         JSD_UNLOCK_SCRIPTS(jsdc);
         if(jsdscript)
             funName = JSD_GetScriptFunctionName(jsdc, jsdscript);
     }
     if(!funName)
         funName = "TOP_LEVEL";
 
     if(before)
@@ -131,17 +131,17 @@ JSBool
     
     if (before && JS_IsConstructorFrame(cx, fp))
         jsd_Constructing(jsdc, cx, JS_GetFrameThis(cx, fp), fp);
 
     jsscript = JS_GetFrameScript(cx, fp);
     if (jsscript)
     {
         JSD_LOCK_SCRIPTS(jsdc);
-        jsdscript = jsd_FindJSDScript(jsdc, jsscript);
+        jsdscript = jsd_FindOrCreateJSDScript(jsdc, cx, jsscript, fp);
         JSD_UNLOCK_SCRIPTS(jsdc);
     
         if (jsdscript)
         {
             if (JSD_IS_PROFILE_ENABLED(jsdc, jsdscript))
             {
                 JSDProfileData *pdata;
                 pdata = jsd_GetScriptProfileData (jsdc, jsdscript);