From 3e4da21b72f9a7626ba3c8b791fc359260d00b1d Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Fri, 13 Apr 2012 13:57:05 -0400 Subject: [PATCH] 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 | 14 +++++++++++++- content/base/test/test_bug708620.html | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 25dc580b852..ab779086d6d 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -3105,7 +3105,19 @@ nsContentUtils::ReportToConsole(PRUint32 aErrorFlags, 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 errorObject = diff --git a/content/base/test/test_bug708620.html b/content/base/test/test_bug708620.html index 5ace778b58c..7e15e9cf102 100644 --- a/content/base/test/test_bug708620.html +++ b/content/base/test/test_bug708620.html @@ -26,8 +26,14 @@ 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) {