Bug 286450 - Make nsIScriptError.message display a formatted message with file/line information, for future logging purposes r=dbradley sr=bz

This commit is contained in:
bsmedberg%covad.net 2005-03-30 11:34:59 +00:00
Родитель f6cc2eed3b
Коммит 4e7256ad3f
6 изменённых файлов: 52 добавлений и 36 удалений

Просмотреть файл

@ -43,7 +43,7 @@
#include "nsISupports.idl"
#include "nsIConsoleMessage.idl"
[scriptable, uuid(fc9e5a94-1dd1-11b2-888b-d8907b2c6996)]
[scriptable, uuid(b0196fc7-1913-441a-882a-453c0d8b89b8)]
interface nsIScriptError : nsIConsoleMessage
{
/** pseudo-flag for default case */
@ -59,8 +59,16 @@ interface nsIScriptError : nsIConsoleMessage
/** error or warning is due to strict option */
const unsigned long strictFlag = 0x4;
readonly attribute wstring sourceName;
readonly attribute wstring sourceLine;
/**
* The error message without any context/line number information.
*
* @note nsIConsoleMessage.message will return the error formatted
* with file/line information.
*/
readonly attribute AString errorMessage;
readonly attribute AString sourceName;
readonly attribute AString sourceLine;
readonly attribute PRUint32 lineNumber;
readonly attribute PRUint32 columnNumber;
readonly attribute PRUint32 flags;
@ -81,7 +89,7 @@ interface nsIScriptError : nsIConsoleMessage
in PRUint32 flags,
in string category);
string toString();
AUTF8String toString();
};
%{ C++

Просмотреть файл

@ -62,20 +62,36 @@ nsScriptError::~nsScriptError() {}
// nsIConsoleMessage methods
NS_IMETHODIMP
nsScriptError::GetMessage(PRUnichar **result) {
*result = ToNewUnicode(mMessage);
nsresult rv;
nsCAutoString message;
rv = ToString(message);
if (NS_FAILED(rv))
return rv;
*result = UTF8ToNewUnicode(message);
if (!*result)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
// nsIScriptError methods
NS_IMETHODIMP
nsScriptError::GetSourceName(PRUnichar **result) {
*result = ToNewUnicode(mSourceName);
nsScriptError::GetErrorMessage(nsAString& aResult) {
aResult.Assign(mMessage);
return NS_OK;
}
NS_IMETHODIMP
nsScriptError::GetSourceLine(PRUnichar **result) {
*result = ToNewUnicode(mSourceLine);
nsScriptError::GetSourceName(nsAString& aResult) {
aResult.Assign(mSourceName);
return NS_OK;
}
NS_IMETHODIMP
nsScriptError::GetSourceLine(nsAString& aResult) {
aResult.Assign(mSourceLine);
return NS_OK;
}
@ -124,7 +140,7 @@ nsScriptError::Init(const PRUnichar *message,
}
NS_IMETHODIMP
nsScriptError::ToString(char **_retval)
nsScriptError::ToString(nsACString& /*UTF8*/ aResult)
{
static const char format0[] =
"[%s: \"%s\" {file: \"%s\" line: %d column: %d source: \"%s\"}]";
@ -144,11 +160,11 @@ nsScriptError::ToString(char **_retval)
char* tempSourceLine = nsnull;
if(!mMessage.IsEmpty())
tempMessage = ToNewCString(mMessage);
tempMessage = ToNewUTF8String(mMessage);
if(!mSourceName.IsEmpty())
tempSourceName = ToNewCString(mSourceName);
tempSourceName = ToNewUTF8String(mSourceName);
if(!mSourceLine.IsEmpty())
tempSourceLine = ToNewCString(mSourceLine);
tempSourceLine = ToNewUTF8String(mSourceLine);
if(nsnull != tempSourceName && nsnull != tempSourceLine)
temp = JS_smprintf(format0,
@ -176,14 +192,10 @@ nsScriptError::ToString(char **_retval)
if(nsnull != tempSourceLine)
nsMemory::Free(tempSourceLine);
char* final = nsnull;
if(temp)
{
final = (char*) nsMemory::Clone(temp,
sizeof(char)*(strlen(temp)+1));
JS_smprintf_free(temp);
}
if (!temp)
return NS_ERROR_OUT_OF_MEMORY;
*_retval = final;
return final ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
aResult.Assign(temp);
JS_smprintf_free(temp);
return NS_OK;
}

Просмотреть файл

@ -43,6 +43,7 @@
/* Data conversion between native and JavaScript types. */
#include "xpcprivate.h"
#include "nsString.h"
//#define STRICT_CHECK_OF_UNICODE
#ifdef STRICT_CHECK_OF_UNICODE
@ -1401,16 +1402,13 @@ XPCConvert::JSErrorToXPCException(XPCCallContext& ccx,
if(data)
{
char* formattedMsg;
if(NS_FAILED(data->ToString(&formattedMsg)))
formattedMsg = nsnull;
nsCAutoString formattedMsg;
data->ToString(formattedMsg);
rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS,
formattedMsg, ifaceName, methodName, data,
formattedMsg.get(), ifaceName, methodName, data,
exceptn);
if(formattedMsg)
nsMemory::Free(formattedMsg);
NS_RELEASE(data);
}
else

Просмотреть файл

@ -622,13 +622,11 @@ static void ShowXPCException()
nsCOMPtr<nsIScriptError> report = do_QueryInterface(data);
if(report)
{
char* str2;
rv = report->ToString(&str2);
if(NS_SUCCEEDED(rv) && str2)
nsCAutoString str2;
rv = report->ToString(str2);
if(NS_SUCCEEDED(rv))
{
printf(str2);
printf("\n");
nsMemory::Free(str2);
printf("%s\n", str2.get());
}
}
}

Просмотреть файл

@ -164,7 +164,7 @@
var typetext = warning ? "typeWarning" : "typeError";
row.setAttribute("typetext", this.mStrBundle.getString(typetext));
row.setAttribute("type", warning ? "warning" : "error");
row.setAttribute("msg", aObject.message);
row.setAttribute("msg", aObject.errorMessage);
if (aObject.lineNumber || aObject.sourceName) {
row.setAttribute("url", aObject.sourceName);
row.setAttribute("line", aObject.lineNumber);

Просмотреть файл

@ -148,7 +148,7 @@
var typetext = warning ? "typeWarning" : "typeError";
row.setAttribute("typetext", this.mStrBundle.getString(typetext));
row.setAttribute("type", warning ? "warning" : "error");
row.setAttribute("msg", aObject.message);
row.setAttribute("msg", aObject.errorMessage);
if (aObject.lineNumber || aObject.sourceName) {
row.setAttribute("url", aObject.sourceName);
row.setAttribute("line", aObject.lineNumber);