Bug 743575 - Try to get line number if at all possible when reporting warnings to the error console. r=mrbkap
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 13 Apr 2012 13:57:05 -0400
changeset 94941 11cf97fceacdd1ed92de5a7bf3fe0e617f6d1a01
parent 94940 cdf819eedd4bc527380119a5e7ec64adfa8f9cd0
child 94942 acefe9a94a63a014a26e95a5784c7aeddb787b95
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs743575
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 743575 - Try to get line number if at all possible when reporting warnings to the error console. r=mrbkap
content/base/src/nsContentUtils.cpp
content/base/test/test_bug708620.html
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3100,17 +3100,29 @@ nsContentUtils::ReportToConsole(PRUint32
                                errorText);
   }
   else {
     rv = GetLocalizedString(aFile, aMessageName, errorText);
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCAutoString spec;
-  if (aURI)
+  if (!aLineNumber) {
+    JSContext *cx = nsnull;
+    sThreadJSContextStack->Peek(&cx);
+    if (cx) {
+      const char* filename;
+      PRUint32 lineno;
+      if (nsJSUtils::GetCallingLocation(cx, &filename, &lineno)) {
+        spec = filename;
+        aLineNumber = lineno;
+      }
+    }
+  }
+  if (spec.IsEmpty() && aURI)
     aURI->GetSpec(spec);
 
   nsCOMPtr<nsIScriptError> errorObject =
       do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = errorObject->InitWithWindowID(errorText.get(),
                                      NS_ConvertUTF8toUTF16(spec).get(), // file name
--- a/content/base/test/test_bug708620.html
+++ b/content/base/test/test_bug708620.html
@@ -21,18 +21,24 @@ https://bugzilla.mozilla.org/show_bug.cg
 /** Test for Bug 708620 **/
 
 SimpleTest.waitForExplicitFinish();
 
 var tests = [
   "file_bug708620.html"
 ];
 
+function resolveURL(relative) {
+  var a = document.createElement('a');
+  a.href = relative;
+  return a.href;
+}
+
 var expectedErrors = [
-  '[JavaScript Warning: "A form was submitted in the windows-1252 encoding which cannot encode all Unicode characters, so user input may get corrupted. To avoid this problem, the page should be changed so that the form is submitted in the UTF-8 encoding either by changing the encoding of the page itself to UTF-8 or by specifying accept-charset=utf-8 on the form element."]'
+  '[JavaScript Warning: "A form was submitted in the windows-1252 encoding which cannot encode all Unicode characters, so user input may get corrupted. To avoid this problem, the page should be changed so that the form is submitted in the UTF-8 encoding either by changing the encoding of the page itself to UTF-8 or by specifying accept-charset=utf-8 on the form element." {file: "' + resolveURL(tests[0]) + '" line: 1}]'
 ];
 
 function consoleError(msg) {
   var expected = expectedErrors.shift();
   is(msg, expected, "Not the right error message");
 }
 
 SpecialPowers.addErrorConsoleListener(consoleError);