2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2003-11-15 00:11:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-04-18 02:34:54 +00:00
|
|
|
*
|
2003-11-15 00:11:16 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-04-18 02:34:54 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-04-18 02:34:54 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2003-11-15 00:11:16 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-04-18 02:34:54 +00:00
|
|
|
*
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Mike McCabe <mccabe@netscape.com>
|
|
|
|
* John Bandhauer <jband@netscape.com>
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2003-11-15 00:11:16 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2003-11-15 00:11:16 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2003-11-15 00:11:16 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-04-18 02:34:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsIScriptError implementation. Defined here, lacking a JS-specific
|
|
|
|
* place to put XPCOM things.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xpcprivate.h"
|
2011-08-24 20:44:35 +00:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2000-04-18 02:34:54 +00:00
|
|
|
|
2011-12-21 21:51:29 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsScriptError, nsIConsoleMessage, nsIScriptError)
|
2000-04-18 02:34:54 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsScriptError::nsScriptError()
|
2004-02-19 02:44:03 +00:00
|
|
|
: mMessage(),
|
|
|
|
mSourceName(),
|
2000-08-09 22:48:52 +00:00
|
|
|
mLineNumber(0),
|
2004-02-19 02:44:03 +00:00
|
|
|
mSourceLine(),
|
2000-08-09 22:48:52 +00:00
|
|
|
mColumnNumber(0),
|
|
|
|
mFlags(0),
|
2010-10-21 00:24:15 +00:00
|
|
|
mCategory(),
|
2011-08-24 20:44:35 +00:00
|
|
|
mOuterWindowID(0),
|
|
|
|
mInnerWindowID(0),
|
|
|
|
mTimeStamp(0)
|
2000-04-18 02:34:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-09-07 22:37:27 +00:00
|
|
|
nsScriptError::~nsScriptError() {}
|
2000-04-18 02:34:54 +00:00
|
|
|
|
|
|
|
// nsIConsoleMessage methods
|
|
|
|
NS_IMETHODIMP
|
2008-02-12 04:11:07 +00:00
|
|
|
nsScriptError::GetMessageMoz(PRUnichar **result) {
|
2005-03-30 11:34:59 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCAutoString message;
|
|
|
|
rv = ToString(message);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*result = UTF8ToNewUnicode(message);
|
|
|
|
if (!*result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2000-04-18 02:34:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIScriptError methods
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 11:34:59 +00:00
|
|
|
nsScriptError::GetErrorMessage(nsAString& aResult) {
|
|
|
|
aResult.Assign(mMessage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::GetSourceName(nsAString& aResult) {
|
|
|
|
aResult.Assign(mSourceName);
|
2000-04-18 02:34:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 11:34:59 +00:00
|
|
|
nsScriptError::GetSourceLine(nsAString& aResult) {
|
|
|
|
aResult.Assign(mSourceLine);
|
2000-04-18 02:34:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::GetLineNumber(PRUint32 *result) {
|
|
|
|
*result = mLineNumber;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::GetColumnNumber(PRUint32 *result) {
|
|
|
|
*result = mColumnNumber;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::GetFlags(PRUint32 *result) {
|
|
|
|
*result = mFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::GetCategory(char **result) {
|
2001-09-29 08:28:41 +00:00
|
|
|
*result = ToNewCString(mCategory);
|
2000-04-18 02:34:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::Init(const PRUnichar *message,
|
|
|
|
const PRUnichar *sourceName,
|
|
|
|
const PRUnichar *sourceLine,
|
|
|
|
PRUint32 lineNumber,
|
|
|
|
PRUint32 columnNumber,
|
|
|
|
PRUint32 flags,
|
|
|
|
const char *category)
|
2010-10-21 00:24:15 +00:00
|
|
|
{
|
|
|
|
return InitWithWindowID(message, sourceName, sourceLine, lineNumber,
|
|
|
|
columnNumber, flags, category, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::InitWithWindowID(const PRUnichar *message,
|
|
|
|
const PRUnichar *sourceName,
|
|
|
|
const PRUnichar *sourceLine,
|
|
|
|
PRUint32 lineNumber,
|
|
|
|
PRUint32 columnNumber,
|
|
|
|
PRUint32 flags,
|
|
|
|
const char *category,
|
2011-08-24 20:44:35 +00:00
|
|
|
PRUint64 aInnerWindowID)
|
2000-04-18 02:34:54 +00:00
|
|
|
{
|
2000-04-18 23:53:10 +00:00
|
|
|
mMessage.Assign(message);
|
|
|
|
mSourceName.Assign(sourceName);
|
2000-04-18 02:34:54 +00:00
|
|
|
mLineNumber = lineNumber;
|
2000-04-18 23:53:10 +00:00
|
|
|
mSourceLine.Assign(sourceLine);
|
2000-04-18 02:34:54 +00:00
|
|
|
mColumnNumber = columnNumber;
|
|
|
|
mFlags = flags;
|
2000-04-18 23:53:10 +00:00
|
|
|
mCategory.Assign(category);
|
2011-12-17 04:22:26 +00:00
|
|
|
mTimeStamp = JS_Now() / 1000;
|
2011-08-24 20:44:35 +00:00
|
|
|
mInnerWindowID = aInnerWindowID;
|
|
|
|
|
2011-10-14 17:52:48 +00:00
|
|
|
if (aInnerWindowID) {
|
2011-08-24 20:44:35 +00:00
|
|
|
nsGlobalWindow* window =
|
|
|
|
nsGlobalWindow::GetInnerWindowWithId(aInnerWindowID);
|
2011-10-14 17:52:48 +00:00
|
|
|
if (window) {
|
2011-08-24 20:44:35 +00:00
|
|
|
nsPIDOMWindow* outer = window->GetOuterWindow();
|
2011-10-14 17:52:48 +00:00
|
|
|
if (outer)
|
2011-08-24 20:44:35 +00:00
|
|
|
mOuterWindowID = outer->WindowID();
|
|
|
|
}
|
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2000-04-18 02:34:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-09 22:48:52 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 11:34:59 +00:00
|
|
|
nsScriptError::ToString(nsACString& /*UTF8*/ aResult)
|
2000-08-09 22:48:52 +00:00
|
|
|
{
|
|
|
|
static const char format0[] =
|
|
|
|
"[%s: \"%s\" {file: \"%s\" line: %d column: %d source: \"%s\"}]";
|
|
|
|
static const char format1[] =
|
|
|
|
"[%s: \"%s\" {file: \"%s\" line: %d}]";
|
|
|
|
static const char format2[] =
|
|
|
|
"[%s: \"%s\"]";
|
|
|
|
|
|
|
|
static const char error[] = "JavaScript Error";
|
|
|
|
static const char warning[] = "JavaScript Warning";
|
|
|
|
|
|
|
|
const char* severity = !(mFlags & JSREPORT_WARNING) ? error : warning;
|
|
|
|
|
|
|
|
char* temp;
|
|
|
|
char* tempMessage = nsnull;
|
|
|
|
char* tempSourceName = nsnull;
|
|
|
|
char* tempSourceLine = nsnull;
|
|
|
|
|
2011-10-14 17:52:48 +00:00
|
|
|
if (!mMessage.IsEmpty())
|
2005-03-30 11:34:59 +00:00
|
|
|
tempMessage = ToNewUTF8String(mMessage);
|
2011-10-14 17:52:48 +00:00
|
|
|
if (!mSourceName.IsEmpty())
|
2005-03-30 11:34:59 +00:00
|
|
|
tempSourceName = ToNewUTF8String(mSourceName);
|
2011-10-14 17:52:48 +00:00
|
|
|
if (!mSourceLine.IsEmpty())
|
2005-03-30 11:34:59 +00:00
|
|
|
tempSourceLine = ToNewUTF8String(mSourceLine);
|
2000-08-09 22:48:52 +00:00
|
|
|
|
2011-10-14 17:52:48 +00:00
|
|
|
if (nsnull != tempSourceName && nsnull != tempSourceLine)
|
2000-08-09 22:48:52 +00:00
|
|
|
temp = JS_smprintf(format0,
|
|
|
|
severity,
|
|
|
|
tempMessage,
|
|
|
|
tempSourceName,
|
|
|
|
mLineNumber,
|
|
|
|
mColumnNumber,
|
|
|
|
tempSourceLine);
|
2011-10-14 17:52:48 +00:00
|
|
|
else if (!mSourceName.IsEmpty())
|
2000-08-09 22:48:52 +00:00
|
|
|
temp = JS_smprintf(format1,
|
|
|
|
severity,
|
|
|
|
tempMessage,
|
|
|
|
tempSourceName,
|
|
|
|
mLineNumber);
|
|
|
|
else
|
|
|
|
temp = JS_smprintf(format2,
|
|
|
|
severity,
|
|
|
|
tempMessage);
|
|
|
|
|
2011-10-14 17:52:48 +00:00
|
|
|
if (nsnull != tempMessage)
|
2000-08-09 22:48:52 +00:00
|
|
|
nsMemory::Free(tempMessage);
|
2011-10-14 17:52:48 +00:00
|
|
|
if (nsnull != tempSourceName)
|
2000-08-09 22:48:52 +00:00
|
|
|
nsMemory::Free(tempSourceName);
|
2011-10-14 17:52:48 +00:00
|
|
|
if (nsnull != tempSourceLine)
|
2000-08-09 22:48:52 +00:00
|
|
|
nsMemory::Free(tempSourceLine);
|
|
|
|
|
2005-03-30 11:34:59 +00:00
|
|
|
if (!temp)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-08-09 22:48:52 +00:00
|
|
|
|
2005-03-30 11:34:59 +00:00
|
|
|
aResult.Assign(temp);
|
|
|
|
JS_smprintf_free(temp);
|
|
|
|
return NS_OK;
|
2000-08-09 22:48:52 +00:00
|
|
|
}
|
2010-10-21 00:24:15 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 20:44:35 +00:00
|
|
|
nsScriptError::GetOuterWindowID(PRUint64 *aOuterWindowID)
|
2010-10-21 00:24:15 +00:00
|
|
|
{
|
2011-08-24 20:44:35 +00:00
|
|
|
*aOuterWindowID = mOuterWindowID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::GetInnerWindowID(PRUint64 *aInnerWindowID)
|
|
|
|
{
|
|
|
|
*aInnerWindowID = mInnerWindowID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptError::GetTimeStamp(PRInt64 *aTimeStamp)
|
|
|
|
{
|
|
|
|
*aTimeStamp = mTimeStamp;
|
2010-10-21 00:24:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|