Bug 382917 - "Display script filename and line number in Stop Script dialog" [p=manish@flock.com (Manish Singh) r+sr=mrbkap a1.9=jst]
authorreed@reedloden.com
Mon, 03 Dec 2007 01:17:40 -0800
changeset 8577 3c8b980d028ff2dfd32d27ce5bc93eaaacc5e67d
parent 8576 2f8eed488f904c199719cdb88f27d87a1759d942
child 8578 caff1dd167565da51ef3af80b938bd8517b4d1dc
push idunknown
push userunknown
push dateunknown
bugs382917
milestone1.9b2pre
Bug 382917 - "Display script filename and line number in Stop Script dialog" [p=manish@flock.com (Manish Singh) r+sr=mrbkap a1.9=jst]
dom/locales/en-US/chrome/dom/dom.properties
dom/src/base/nsJSEnvironment.cpp
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -33,16 +33,17 @@
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 KillScriptTitle=Warning: Unresponsive script
 KillScriptMessage=A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
 KillScriptWithDebugMessage=A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.
+KillScriptLocation=Script: %S
 StopScriptButton=Stop script
 DebugScriptButton=Debug script
 WaitForScriptButton=Continue
 DontAskAgain=Don't ask me again
 JSURLLoadBlockedWarning=Attempt to load a javascript: URL from one host\nin a window displaying content from another host\nwas blocked by the security manager.
 WindowCloseBlockedWarning=Scripts may not close windows that were not opened by script.
 OnBeforeUnloadPreMessage=Are you sure you want to navigate away from this page?
 OnBeforeUnloadPostMessage=Press OK to continue, or Cancel to stay on the current page.
--- a/dom/src/base/nsJSEnvironment.cpp
+++ b/dom/src/base/nsJSEnvironment.cpp
@@ -933,16 +933,45 @@ nsJSContext::DOMBranchCallback(JSContext
 
   //GetStringFromName can return NS_OK and still give NULL string
   if (NS_FAILED(rv) || !title || !msg || !stopButton || !waitButton ||
       (!debugButton && debugPossible) || !neverShowDlg) {
     NS_ERROR("Failed to get localized strings.");
     return JS_TRUE;
   }
 
+  // Append file and line number information, if available
+  if (script) {
+    const char *filename = ::JS_GetScriptFilename(cx, script);
+    if (filename) {
+      nsXPIDLString scriptLocation;
+      NS_ConvertUTF8toUTF16 filenameUTF16(filename);
+      const PRUnichar *formatParams[] = { filenameUTF16.get() };
+      rv = bundle->FormatStringFromName(NS_LITERAL_STRING("KillScriptLocation").get(),
+                                        formatParams, 1,
+                                        getter_Copies(scriptLocation));
+
+      if (NS_SUCCEEDED(rv) && scriptLocation) {
+        msg.AppendLiteral("\n\n");
+        msg.Append(scriptLocation);
+
+        JSStackFrame *fp, *iterator = nsnull;
+        fp = ::JS_FrameIterator(cx, &iterator);
+        if (fp) {
+          jsbytecode *pc = ::JS_GetFramePC(cx, fp);
+          if (pc) {
+            PRUint32 lineno = ::JS_PCToLineNumber(cx, script, pc);
+            msg.Append(':');
+            msg.AppendInt(lineno);
+          }
+        }
+      }
+    }
+  }
+
   PRInt32 buttonPressed = 1; //In case user exits dialog by clicking X
   PRBool neverShowDlgChk = PR_FALSE;
   PRUint32 buttonFlags = (nsIPrompt::BUTTON_TITLE_IS_STRING *
                           (nsIPrompt::BUTTON_POS_0 + nsIPrompt::BUTTON_POS_1));
 
   // Add a third button if necessary:
   if (debugPossible)
     buttonFlags += nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_2;