Backed out changeset 965cf4cbedc8 (bug 958816) for mochitest crashes.

CLOSED TREE
This commit is contained in:
Ryan VanderMeulen 2014-01-17 10:20:05 -05:00
parent d9a8f0324a
commit 4e06172283
14 changed files with 300 additions and 210 deletions

View File

@ -94,14 +94,16 @@ class BlobURLsReporter MOZ_FINAL : public nsIMemoryReporter
}
for (uint32_t i = 0; i < maxFrames && frame; ++i) {
nsCString fileName;
nsAutoCString fileNameEscaped;
char* fileName = nullptr;
int32_t lineNumber = 0;
frame->GetFilename(fileName);
frame->GetFilename(&fileName);
frame->GetLineNumber(&lineNumber);
if (!fileName.IsEmpty()) {
if (fileName != nullptr && fileName[0] != '\0') {
stack += "js(";
fileNameEscaped = fileName;
if (!origin.IsEmpty()) {
// Make the file name root-relative for conciseness if possible.
const char* originData;
@ -109,14 +111,14 @@ class BlobURLsReporter MOZ_FINAL : public nsIMemoryReporter
originLen = origin.GetData(&originData);
// If fileName starts with origin + "/", cut up to that "/".
if (fileName.Length() >= originLen + 1 &&
memcmp(fileName.get(), originData, originLen) == 0 &&
if (strlen(fileName) >= originLen + 1 &&
memcmp(fileName, originData, originLen) == 0 &&
fileName[originLen] == '/') {
fileName.Cut(0, originLen);
fileNameEscaped.Cut(0, originLen);
}
}
fileName.ReplaceChar('/', '\\');
stack += fileName;
fileNameEscaped.ReplaceChar('/', '\\');
stack += fileNameEscaped;
if (lineNumber > 0) {
stack += ", line=";
stack.AppendInt(lineNumber);

View File

@ -29,11 +29,11 @@ DOMError::DOMError(nsPIDOMWindow* aWindow)
DOMError::DOMError(nsPIDOMWindow* aWindow, nsresult aValue)
: mWindow(aWindow)
{
nsCString name, message;
NS_GetNameAndMessageForDOMNSResult(aValue, name, message);
const char *name, *message;
NS_GetNameAndMessageForDOMNSResult(aValue, &name, &message);
CopyUTF8toUTF16(name, mName);
CopyUTF8toUTF16(message, mMessage);
mName = NS_ConvertASCIItoUTF16(name);
mMessage = NS_ConvertASCIItoUTF16(message);
SetIsDOMBinding();
}

View File

@ -89,19 +89,17 @@ static const struct ResultStruct
static void
NSResultToNameAndMessage(nsresult aNSResult,
nsCString& aName,
nsCString& aMessage,
const char** aName,
const char** aMessage,
uint16_t* aCode)
{
aName.Truncate();
aMessage.Truncate();
*aName = nullptr;
*aMessage = nullptr;
*aCode = 0;
for (uint32_t idx = 0; idx < ArrayLength(sDOMErrorMsgMap); idx++) {
if (aNSResult == sDOMErrorMsgMap[idx].mNSResult) {
aName.Rebind(sDOMErrorMsgMap[idx].mName,
strlen(sDOMErrorMsgMap[idx].mName));
aMessage.Rebind(sDOMErrorMsgMap[idx].mMessage,
strlen(sDOMErrorMsgMap[idx].mMessage));
*aName = sDOMErrorMsgMap[idx].mName;
*aMessage = sDOMErrorMsgMap[idx].mMessage;
*aCode = sDOMErrorMsgMap[idx].mCode;
return;
}
@ -113,17 +111,17 @@ NSResultToNameAndMessage(nsresult aNSResult,
}
nsresult
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName,
nsACString& aMessage, uint16_t* aCode)
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, const char** aName,
const char** aMessage, uint16_t* aCode)
{
nsCString name;
nsCString message;
const char* name = nullptr;
const char* message = nullptr;
uint16_t code = 0;
NSResultToNameAndMessage(aNSResult, name, message, &code);
NSResultToNameAndMessage(aNSResult, &name, &message, &code);
if (!name.IsEmpty() && !message.IsEmpty()) {
aName = name;
aMessage = message;
if (name && message) {
*aName = name;
*aMessage = message;
if (aCode) {
*aCode = code;
}
@ -172,13 +170,19 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CI_INTERFACE_GETTER1(Exception, nsIXPCException)
Exception::Exception(const nsACString& aMessage,
Exception::Exception(const char *aMessage,
nsresult aResult,
const nsACString& aName,
const char *aName,
nsIStackFrame *aLocation,
nsISupports *aData)
: mResult(NS_OK),
: mMessage(nullptr),
mResult(NS_OK),
mName(nullptr),
mLocation(nullptr),
mData(nullptr),
mFilename(nullptr),
mLineNumber(0),
mInner(nullptr),
mInitialized(false),
mHoldingJSVal(false)
{
@ -231,7 +235,10 @@ Exception::Exception(const nsACString& aMessage,
}
Exception::Exception()
: mResult(NS_OK),
: mMessage(nullptr),
mResult(NS_OK),
mName(nullptr),
mFilename(nullptr),
mLineNumber(-1),
mInitialized(false),
mHoldingJSVal(false)
@ -240,6 +247,19 @@ Exception::Exception()
Exception::~Exception()
{
if (mMessage) {
nsMemory::Free(mMessage);
mMessage = nullptr;
}
if (mName) {
nsMemory::Free(mName);
mName = nullptr;
}
if (mFilename) {
nsMemory::Free(mFilename);
mFilename = nullptr;
}
if (mHoldingJSVal) {
MOZ_ASSERT(NS_IsMainThread());
@ -276,13 +296,20 @@ Exception::StowJSVal(JS::Value& aVp)
}
}
/* readonly attribute AUTF8String message; */
/* readonly attribute string message; */
NS_IMETHODIMP
Exception::GetMessageMoz(nsACString& aMessage)
Exception::GetMessageMoz(char** aMessage)
{
NS_ENSURE_ARG_POINTER(aMessage);
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
aMessage.Assign(mMessage);
if (mMessage) {
*aMessage =
(char*) nsMemory::Clone(mMessage, sizeof(char)*(strlen(mMessage)+1));
} else {
*aMessage = nullptr;
}
return NS_OK;
}
@ -297,31 +324,30 @@ Exception::GetResult(nsresult* aResult)
return NS_OK;
}
/* readonly attribute AUTF8String name; */
/* readonly attribute string name; */
NS_IMETHODIMP
Exception::GetName(nsACString& aName)
Exception::GetName(char** aName)
{
NS_ENSURE_ARG_POINTER(aName);
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
if (!mName.IsEmpty()) {
aName.Assign(mName);
} else {
aName.Truncate();
const char* name = nullptr;
const char* name = mName;
if (!name) {
nsXPCException::NameAndFormatForNSResult(mResult, &name, nullptr);
}
if (name) {
aName.Assign(name);
}
if (name) {
*aName = (char*) nsMemory::Clone(name, sizeof(char)*(strlen(name)+1));
} else {
*aName = nullptr;
}
return NS_OK;
}
/* readonly attribute AUTF8String filename; */
/* readonly attribute string filename; */
NS_IMETHODIMP
Exception::GetFilename(nsACString& aFilename)
Exception::GetFilename(char** aFilename)
{
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
@ -329,8 +355,7 @@ Exception::GetFilename(nsACString& aFilename)
return mLocation->GetFilename(aFilename);
}
aFilename.Assign(mFilename);
return NS_OK;
XPC_STRING_GETTER_BODY(aFilename, mFilename);
}
/* readonly attribute uint32_t lineNumber; */
@ -398,10 +423,11 @@ Exception::GetInner(nsIException** aException)
return NS_OK;
}
/* AUTF8String toString (); */
/* string toString (); */
NS_IMETHODIMP
Exception::ToString(nsACString& _retval)
Exception::ToString(char **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
static const char defaultMsg[] = "<no message>";
@ -409,21 +435,18 @@ Exception::ToString(nsACString& _retval)
static const char format[] =
"[Exception... \"%s\" nsresult: \"0x%x (%s)\" location: \"%s\" data: %s]";
nsCString location;
char* indicatedLocation = nullptr;
if (mLocation) {
// we need to free this if it does not fail
nsresult rv = mLocation->ToString(location);
nsresult rv = mLocation->ToString(&indicatedLocation);
NS_ENSURE_SUCCESS(rv, rv);
}
if (location.IsEmpty()) {
location.Assign(defaultLocation);
}
const char* msg = mMessage.IsEmpty() ? nullptr : mMessage.get();
const char* resultName = mName.IsEmpty() ? nullptr: mName.get();
const char* msg = mMessage ? mMessage : nullptr;
const char* location = indicatedLocation ?
indicatedLocation : defaultLocation;
const char* resultName = mName;
if (!resultName &&
!nsXPCException::NameAndFormatForNSResult(mResult, &resultName,
(!msg) ? &msg : nullptr)) {
@ -434,24 +457,36 @@ Exception::ToString(nsACString& _retval)
}
const char* data = mData ? "yes" : "no";
_retval.Truncate();
_retval.AppendPrintf(format, msg, mResult, resultName,
location.get(), data);
return NS_OK;
char* temp = JS_smprintf(format, msg, mResult, resultName, location, data);
if (indicatedLocation) {
nsMemory::Free(indicatedLocation);
}
char* final = nullptr;
if (temp) {
final = (char*) nsMemory::Clone(temp, sizeof(char)*(strlen(temp)+1));
JS_smprintf_free(temp);
}
*_retval = final;
return final ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
/* void initialize (in AUTF8String aMessage, in nsresult aResult,
* in AUTF8String aName, in nsIStackFrame aLocation,
* in nsISupports aData, in nsIException aInner); */
/* void initialize (in string aMessage, in nsresult aResult, in string aName, in nsIStackFrame aLocation, in nsISupports aData, in nsIException aInner); */
NS_IMETHODIMP
Exception::Initialize(const nsACString& aMessage, nsresult aResult,
const nsACString& aName, nsIStackFrame *aLocation,
nsISupports *aData, nsIException *aInner)
Exception::Initialize(const char *aMessage, nsresult aResult, const char *aName, nsIStackFrame *aLocation, nsISupports *aData, nsIException *aInner)
{
NS_ENSURE_FALSE(mInitialized, NS_ERROR_ALREADY_INITIALIZED);
mMessage = aMessage;
mName = aName;
if (aMessage) {
mMessage =
(char*) nsMemory::Clone(aMessage, sizeof(char)*(strlen(aMessage)+1));
}
if (aName) {
mName = (char*) nsMemory::Clone(aName, sizeof(char)*(strlen(aName)+1));
}
mResult = aResult;
if (aLocation) {
@ -481,13 +516,14 @@ Exception::WrapObject(JSContext* cx, JS::Handle<JSObject*> scope)
void
Exception::GetMessageMoz(nsString& retval)
{
nsCString str;
char* str = nullptr;
#ifdef DEBUG
DebugOnly<nsresult> rv =
#endif
GetMessageMoz(str);
GetMessageMoz(&str);
MOZ_ASSERT(NS_SUCCEEDED(rv));
CopyUTF8toUTF16(str, retval);
nsMemory::Free(str);
}
uint32_t
@ -499,25 +535,27 @@ Exception::Result() const
void
Exception::GetName(nsString& retval)
{
nsCString str;
char* str = nullptr;
#ifdef DEBUG
DebugOnly<nsresult> rv =
#endif
GetName(str);
GetName(&str);
MOZ_ASSERT(NS_SUCCEEDED(rv));
CopyUTF8toUTF16(str, retval);
nsMemory::Free(str);
}
void
Exception::GetFilename(nsString& retval)
{
nsCString str;
char* str = nullptr;
#ifdef DEBUG
DebugOnly<nsresult> rv =
#endif
GetFilename(str);
GetFilename(&str);
MOZ_ASSERT(NS_SUCCEEDED(rv));
CopyUTF8toUTF16(str, retval);
nsMemory::Free(str);
}
uint32_t
@ -564,13 +602,14 @@ Exception::GetData() const
void
Exception::Stringify(nsString& retval)
{
nsCString str;
char* str = nullptr;
#ifdef DEBUG
DebugOnly<nsresult> rv =
#endif
ToString(str);
ToString(&str);
MOZ_ASSERT(NS_SUCCEEDED(rv));
CopyUTF8toUTF16(str, retval);
nsMemory::Free(str);
}
NS_IMPL_ADDREF_INHERITED(DOMException, Exception)
@ -579,9 +618,9 @@ NS_INTERFACE_MAP_BEGIN(DOMException)
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMException)
NS_INTERFACE_MAP_END_INHERITING(Exception)
DOMException::DOMException(nsresult aRv, const nsACString& aMessage,
const nsACString& aName, uint16_t aCode)
: Exception(EmptyCString(), aRv, EmptyCString(), nullptr, nullptr),
DOMException::DOMException(nsresult aRv, const char* aMessage,
const char* aName, uint16_t aCode)
: Exception(nullptr, aRv, nullptr, nullptr, nullptr),
mName(aName),
mMessage(aMessage),
mCode(aCode)
@ -608,9 +647,9 @@ DOMException::GetCode(uint16_t* aCode)
}
NS_IMETHODIMP
DOMException::ToString(nsACString& aReturn)
DOMException::ToString(char **aReturn)
{
aReturn.Truncate();
*aReturn = nullptr;
static const char defaultMsg[] = "<no message>";
static const char defaultLocation[] = "<unknown>";
@ -621,8 +660,9 @@ DOMException::ToString(nsACString& aReturn)
nsAutoCString location;
if (mInner) {
nsCString filename;
mInner->GetFilename(filename);
nsXPIDLCString filename;
mInner->GetFilename(getter_Copies(filename));
if (!filename.IsEmpty()) {
uint32_t line_nr = 0;
@ -641,13 +681,13 @@ DOMException::ToString(nsACString& aReturn)
location = defaultLocation;
}
const char* msg = !mMessage.IsEmpty() ? mMessage.get() : defaultMsg;
const char* resultName = !mName.IsEmpty() ? mName.get() : defaultName;
const char* msg = mMessage ? mMessage : defaultMsg;
const char* resultName = mName ? mName : defaultName;
aReturn.AppendPrintf(format, msg, mCode, mResult, resultName,
location.get());
*aReturn = PR_smprintf(format, msg, mCode, mResult, resultName,
location.get());
return NS_OK;
return *aReturn ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
void
@ -671,10 +711,10 @@ DOMException::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
/* static */already_AddRefed<DOMException>
DOMException::Create(nsresult aRv)
{
nsCString name;
nsCString message;
const char* name;
const char* message;
uint16_t code;
NSResultToNameAndMessage(aRv, name, message, &code);
NSResultToNameAndMessage(aRv, &name, &message, &code);
nsRefPtr<DOMException> inst =
new DOMException(aRv, message, name, code);
return inst.forget();

View File

@ -21,14 +21,13 @@
#include "nsIDOMDOMException.h"
#include "nsWrapperCache.h"
#include "xpcexception.h"
#include "nsString.h"
class nsIStackFrame;
class nsString;
nsresult
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName,
nsACString& aMessage,
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, const char** aName,
const char** aMessage,
uint16_t* aCode = nullptr);
namespace mozilla {
@ -86,21 +85,21 @@ public:
// XPCOM factory ctor.
Exception();
Exception(const nsACString& aMessage,
Exception(const char *aMessage,
nsresult aResult,
const nsACString& aName,
const char *aName,
nsIStackFrame *aLocation,
nsISupports *aData);
protected:
virtual ~Exception();
nsCString mMessage;
char* mMessage;
nsresult mResult;
nsCString mName;
char* mName;
nsCOMPtr<nsIStackFrame> mLocation;
nsCOMPtr<nsISupports> mData;
nsCString mFilename;
char* mFilename;
int mLineNumber;
nsCOMPtr<nsIException> mInner;
bool mInitialized;
@ -118,14 +117,14 @@ class DOMException : public Exception,
public nsIDOMDOMException
{
public:
DOMException(nsresult aRv, const nsACString& aMessage,
const nsACString& aName, uint16_t aCode);
DOMException(nsresult aRv, const char* aMessage,
const char* aName, uint16_t aCode);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMDOMEXCEPTION
// nsIException overrides
NS_IMETHOD ToString(nsACString& aReturn) MOZ_OVERRIDE;
NS_IMETHOD ToString(char **aReturn) MOZ_OVERRIDE;
// nsWrapperCache overrides
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
@ -146,8 +145,9 @@ protected:
virtual ~DOMException() {}
nsCString mName;
nsCString mMessage;
// Intentionally shadow the nsXPCException version.
const char* mName;
const char* mMessage;
uint16_t mCode;
};

View File

@ -147,8 +147,7 @@ Throw(JSContext* aCx, nsresult aRv, const char* aMessage)
// If not, use the default.
if (!finalException) {
finalException = new Exception(nsCString(aMessage), aRv,
EmptyCString(), nullptr, nullptr);
finalException = new Exception(aMessage, aRv, nullptr, nullptr, nullptr);
}
MOZ_ASSERT(finalException);
@ -293,14 +292,16 @@ private:
return mLanguage == nsIProgrammingLanguage::JAVASCRIPT;
}
const char* GetFilename();
const char* GetFunname();
int32_t GetLineno();
nsRefPtr<StackDescriptionOwner> mStackDescription;
nsCOMPtr<nsIStackFrame> mCaller;
// Cached values
nsCString mFilename;
nsCString mFunname;
char* mFilename;
char* mFunname;
int32_t mLineno;
uint32_t mLanguage;
@ -314,7 +315,9 @@ private:
JSStackFrame::JSStackFrame(StackDescriptionOwner* aStackDescription,
size_t aIndex)
: mLineno(0)
: mFilename(nullptr),
mFunname(nullptr),
mLineno(0)
{
if (aStackDescription && aIndex < aStackDescription->NumFrames()) {
mStackDescription = aStackDescription;
@ -337,6 +340,12 @@ JSStackFrame::JSStackFrame(StackDescriptionOwner* aStackDescription,
JSStackFrame::~JSStackFrame()
{
if (mFilename) {
nsMemory::Free(mFilename);
}
if (mFunname) {
nsMemory::Free(mFunname);
}
}
NS_IMPL_CYCLE_COLLECTION_2(JSStackFrame, mStackDescription, mCaller)
@ -357,22 +366,22 @@ NS_IMETHODIMP JSStackFrame::GetLanguage(uint32_t* aLanguage)
}
/* readonly attribute string languageName; */
NS_IMETHODIMP JSStackFrame::GetLanguageName(nsACString& aLanguageName)
NS_IMETHODIMP JSStackFrame::GetLanguageName(char** aLanguageName)
{
static const char js[] = "JavaScript";
static const char cpp[] = "C++";
if (IsJSFrame()) {
aLanguageName.AssignASCII(js);
*aLanguageName = (char*) nsMemory::Clone(js, sizeof(js));
} else {
aLanguageName.AssignASCII(cpp);
*aLanguageName = (char*) nsMemory::Clone(cpp, sizeof(cpp));
}
return NS_OK;
}
/* readonly attribute string filename; */
NS_IMETHODIMP JSStackFrame::GetFilename(nsACString& aFilename)
const char*
JSStackFrame::GetFilename()
{
if (!mFilenameInitialized) {
JS::FrameDescription& desc = mStackDescription->FrameAt(mIndex);
@ -384,22 +393,34 @@ NS_IMETHODIMP JSStackFrame::GetFilename(nsACString& aFilename)
JSAutoCompartment ac(cx, desc.script());
const char* filename = JS_GetScriptFilename(cx, desc.script());
if (filename) {
mFilename.Assign(filename);
mFilename =
(char*)nsMemory::Clone(filename, sizeof(char)*(strlen(filename)+1));
}
}
mFilenameInitialized = true;
}
if (mFilename.IsEmpty()) {
aFilename.SetIsVoid(true);
return mFilename;
}
/* readonly attribute string filename; */
NS_IMETHODIMP JSStackFrame::GetFilename(char** aFilename)
{
NS_ENSURE_ARG_POINTER(aFilename);
const char* filename = GetFilename();
if (filename) {
*aFilename = (char*) nsMemory::Clone(filename,
sizeof(char)*(strlen(filename)+1));
} else {
aFilename.Assign(mFilename);
*aFilename = nullptr;
}
return NS_OK;
}
/* readonly attribute string name; */
NS_IMETHODIMP JSStackFrame::GetName(nsACString& aFunction)
const char*
JSStackFrame::GetFunname()
{
if (!mFunnameInitialized) {
JS::FrameDescription& desc = mStackDescription->FrameAt(mIndex);
@ -412,19 +433,33 @@ NS_IMETHODIMP JSStackFrame::GetName(nsACString& aFunction)
if (funid) {
size_t length = JS_GetStringEncodingLength(cx, funid);
if (length != size_t(-1)) {
mFunname.SetLength(uint32_t(length));
JS_EncodeStringToBuffer(cx, funid, mFunname.BeginWriting(), length);
mFunname = static_cast<char *>(nsMemory::Alloc(length + 1));
if (mFunname) {
JS_EncodeStringToBuffer(cx, funid, mFunname, length);
mFunname[length] = '\0';
}
}
}
}
mFunnameInitialized = true;
}
if (mFunname.IsEmpty()) {
aFunction.SetIsVoid(true);
return mFunname;
}
/* readonly attribute string name; */
NS_IMETHODIMP JSStackFrame::GetName(char** aFunction)
{
NS_ENSURE_ARG_POINTER(aFunction);
const char* funname = GetFunname();
if (funname) {
*aFunction = (char*) nsMemory::Clone(funname,
sizeof(char)*(strlen(funname)+1));
} else {
aFunction.Assign(mFunname);
*aFunction = nullptr;
}
return NS_OK;
}
@ -447,10 +482,10 @@ NS_IMETHODIMP JSStackFrame::GetLineNumber(int32_t* aLineNumber)
return NS_OK;
}
/* readonly attribute AUTF8String sourceLine; */
NS_IMETHODIMP JSStackFrame::GetSourceLine(nsACString& aSourceLine)
/* readonly attribute string sourceLine; */
NS_IMETHODIMP JSStackFrame::GetSourceLine(char** aSourceLine)
{
aSourceLine.Truncate();
*aSourceLine = nullptr;
return NS_OK;
}
@ -465,31 +500,26 @@ NS_IMETHODIMP JSStackFrame::GetCaller(nsIStackFrame** aCaller)
return NS_OK;
}
/* AUTF8String toString (); */
NS_IMETHODIMP JSStackFrame::ToString(nsACString& _retval)
/* string toString (); */
NS_IMETHODIMP JSStackFrame::ToString(char** _retval)
{
_retval.Truncate();
const char* frametype = IsJSFrame() ? "JS" : "native";
nsCString filename;
nsresult rv = GetFilename(filename);
NS_ENSURE_SUCCESS(rv, rv);
if (filename.IsEmpty()) {
filename.AssignASCII("<unknown filename>");
const char* filename = GetFilename();
if (!filename) {
filename = "<unknown filename>";
}
nsCString funname;
rv = GetName(funname);
NS_ENSURE_SUCCESS(rv, rv);
if (funname.IsEmpty()) {
funname.AssignASCII("<TOP_LEVEL>");
const char* funname = GetFunname();
if (!funname) {
funname = "<TOP_LEVEL>";
}
static const char format[] = "%s frame :: %s :: %s :: line %d";
_retval.AppendPrintf(format, frametype, filename.get(),
funname.get(), GetLineno());
int len = sizeof(char)*
(strlen(frametype) + strlen(filename) + strlen(funname)) +
sizeof(format) + 3 * sizeof(mLineno);
char* buf = (char*) nsMemory::Alloc(len);
JS_snprintf(buf, len, format, frametype, filename, funname, GetLineno());
*_retval = buf;
return NS_OK;
}
@ -520,8 +550,17 @@ JSStackFrame::CreateStackFrameLocation(uint32_t aLanguage,
self->mLanguage = aLanguage;
self->mLineno = aLineNumber;
self->mFilename = aFilename;
self->mFunname = aFunctionName;
if (aFilename) {
self->mFilename =
(char*)nsMemory::Clone(aFilename, sizeof(char)*(strlen(aFilename)+1));
}
if (aFunctionName) {
self->mFunname =
(char*)nsMemory::Clone(aFunctionName,
sizeof(char)*(strlen(aFunctionName)+1));
}
self->mCaller = aCaller;

View File

@ -153,7 +153,7 @@ interface nsIXPCComponents_Utils : nsISupports
[implicit_jscontext,optional_argc]
jsval evalInSandbox(in AString source, in jsval sandbox,
[optional] in jsval version,
[optional] in AUTF8String filename,
[optional] in jsval filename,
[optional] in long lineNo);
/*

View File

@ -12,9 +12,9 @@ interface nsIXPCException : nsIException
{
// inherits methods from nsIException
void initialize(in AUTF8String aMessage,
void initialize(in string aMessage,
in nsresult aResult,
in AUTF8String aName,
in string aName,
in nsIStackFrame aLocation,
in nsISupports aData,
in nsIException aInner);

View File

@ -1515,7 +1515,7 @@ AssembleSandboxMemoryReporterName(JSContext *cx, nsCString &sandboxName)
if (frame) {
nsCString location;
int32_t lineNumber = 0;
frame->GetFilename(location);
frame->GetFilename(getter_Copies(location));
frame->GetLineNumber(&lineNumber);
sandboxName.AppendLiteral(" (from: ");
@ -1634,7 +1634,7 @@ ContextHolder::~ContextHolder()
nsresult
xpc::EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& source,
const nsACString& filename, int32_t lineNo,
const char *filename, int32_t lineNo,
JSVersion jsVersion, bool returnStringOnly, MutableHandleValue rval)
{
JS_AbortIfWrongThread(JS_GetRuntime(cx));
@ -1653,11 +1653,10 @@ xpc::EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& sour
NS_ENSURE_TRUE(prin, NS_ERROR_FAILURE);
nsAutoCString filenameBuf;
if (!filename.IsVoid()) {
filenameBuf.Assign(filename);
} else {
if (!filename) {
// Default to the spec of the principal.
nsJSPrincipals::get(prin)->GetScriptLocation(filenameBuf);
filename = filenameBuf.get();
lineNo = 1;
}
@ -1681,7 +1680,7 @@ xpc::EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& sour
JS::CompileOptions options(sandcx);
options.setPrincipals(nsJSPrincipals::get(prin))
.setFileAndLine(filenameBuf.get(), lineNo);
.setFileAndLine(filename, lineNo);
if (jsVersion != JSVERSION_DEFAULT)
options.setVersion(jsVersion);
JS::RootedObject rootedSandbox(sandcx, sandbox);

View File

@ -1861,10 +1861,8 @@ nsXPCComponents_Exception::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
if (!parser.parse(args))
return ThrowAndFail(NS_ERROR_XPC_BAD_CONVERT_JS, cx, _retval);
nsCOMPtr<nsIException> e = new Exception(nsCString(parser.eMsg),
parser.eResult,
EmptyCString(),
parser.eStack,
nsCOMPtr<nsIException> e = new Exception(parser.eMsg, parser.eResult,
nullptr, parser.eStack,
parser.eData);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
@ -2584,10 +2582,10 @@ nsXPCComponents_Utils::ReportError(HandleValue error, JSContext *cx)
nsXPConnect *xpc = nsXPConnect::XPConnect();
xpc->GetCurrentJSStack(getter_AddRefs(frame));
nsCString fileName;
nsXPIDLCString fileName;
int32_t lineNo = 0;
if (frame) {
frame->GetFilename(fileName);
frame->GetFilename(getter_Copies(fileName));
frame->GetLineNumber(&lineNo);
}
@ -2597,8 +2595,8 @@ nsXPCComponents_Utils::ReportError(HandleValue error, JSContext *cx)
nsresult rv = scripterr->InitWithWindowID(
nsDependentString(static_cast<const char16_t *>(msgchars)),
NS_ConvertUTF8toUTF16(fileName), EmptyString(), lineNo, 0, 0,
"XPConnect JavaScript", innerWindowID);
NS_ConvertUTF8toUTF16(fileName),
EmptyString(), lineNo, 0, 0, "XPConnect JavaScript", innerWindowID);
NS_ENSURE_SUCCESS(rv, NS_OK);
console->LogMessage(scripterr);
@ -2610,7 +2608,7 @@ NS_IMETHODIMP
nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
HandleValue sandboxVal,
HandleValue version,
const nsACString& filenameArg,
HandleValue filenameVal,
int32_t lineNumber,
JSContext *cx,
uint8_t optionalArgc,
@ -2644,10 +2642,17 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
}
// Optional fourth and fifth arguments: filename and line number.
nsXPIDLCString filename;
int32_t lineNo = (optionalArgc >= 3) ? lineNumber : 1;
nsCString filename;
if (!filenameArg.IsVoid()) {
filename.Assign(filenameArg);
if (optionalArgc >= 2) {
JSString *filenameStr = ToString(cx, filenameVal);
if (!filenameStr)
return NS_ERROR_INVALID_ARG;
JSAutoByteString filenameBytes;
if (!filenameBytes.encodeLatin1(cx, filenameStr))
return NS_ERROR_INVALID_ARG;
filename = filenameBytes.ptr();
} else {
// Get the current source info from xpc.
nsresult rv;
@ -2657,12 +2662,12 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
nsCOMPtr<nsIStackFrame> frame;
xpc->GetCurrentJSStack(getter_AddRefs(frame));
if (frame) {
frame->GetFilename(filename);
frame->GetFilename(getter_Copies(filename));
frame->GetLineNumber(&lineNo);
}
}
return xpc::EvalInSandbox(cx, sandbox, source, filename, lineNo,
return xpc::EvalInSandbox(cx, sandbox, source, filename.get(), lineNo,
jsVersion, false, retval);
}

View File

@ -1070,6 +1070,7 @@ XPCConvert::ConstructException(nsresult rv, const char* message,
static const char format[] = "\'%s\' when calling method: [%s::%s]";
const char * msg = message;
char* sz = nullptr;
nsXPIDLString xmsg;
nsAutoCString sxmsg;
@ -1083,18 +1084,19 @@ XPCConvert::ConstructException(nsresult rv, const char* message,
if (!msg)
if (!nsXPCException::NameAndFormatForNSResult(rv, nullptr, &msg) || ! msg)
msg = "<error>";
nsCString msgStr(msg);
if (ifaceName && methodName)
msgStr.AppendPrintf(format, msg, ifaceName, methodName);
msg = sz = JS_smprintf(format, msg, ifaceName, methodName);
nsRefPtr<Exception> e = new Exception(msgStr, rv, EmptyCString(), nullptr, data);
nsRefPtr<Exception> e = new Exception(msg, rv, nullptr, nullptr, data);
if (cx && jsExceptionPtr) {
e->StowJSVal(*jsExceptionPtr);
}
e.forget(exceptn);
if (sz)
JS_smprintf_free(sz);
return NS_OK;
}

View File

@ -899,11 +899,11 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
fputs(line, stdout);
fputs(preamble, stdout);
nsCString text;
if (NS_SUCCEEDED(xpc_exception->ToString(text)) &&
!text.IsEmpty()) {
fputs(text.get(), stdout);
char* text;
if (NS_SUCCEEDED(xpc_exception->ToString(&text)) && text) {
fputs(text, stdout);
fputs("\n", stdout);
nsMemory::Free(text);
} else
fputs(cant_get_text, stdout);
fputs(line, stdout);
@ -926,13 +926,17 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
// try to cook one up.
scriptError = do_CreateInstance(XPC_SCRIPT_ERROR_CONTRACTID);
if (nullptr != scriptError) {
nsCString newMessage;
rv = xpc_exception->ToString(newMessage);
char* exn_string;
rv = xpc_exception->ToString(&exn_string);
if (NS_SUCCEEDED(rv)) {
// use toString on the exception as the message
NS_ConvertASCIItoUTF16 newMessage(exn_string);
nsMemory::Free((void *) exn_string);
// try to get filename, lineno from the first
// stack frame location.
int32_t lineNumber = 0;
nsCString sourceName;
nsXPIDLCString sourceName;
nsCOMPtr<nsIStackFrame> location;
xpc_exception->
@ -942,11 +946,11 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
location->GetLineNumber(&lineNumber);
// get a filename.
rv = location->GetFilename(sourceName);
rv = location->GetFilename(getter_Copies(sourceName));
}
rv = scriptError->InitWithWindowID(NS_ConvertUTF8toUTF16(newMessage),
NS_ConvertUTF8toUTF16(sourceName),
rv = scriptError->InitWithWindowID(newMessage,
NS_ConvertASCIItoUTF16(sourceName),
EmptyString(),
lineNumber, 0, 0,
"XPConnect JavaScript",

View File

@ -898,14 +898,9 @@ nsXPConnect::EvalInSandboxObject(const nsAString& source, const char *filename,
return NS_ERROR_INVALID_ARG;
RootedObject sandbox(cx, sandboxArg);
nsCString filenameStr;
if (filename) {
filenameStr.Assign(filename);
} else {
filenameStr = NS_LITERAL_CSTRING("x-bogus://XPConnect/Sandbox");
}
return EvalInSandbox(cx, sandbox, source, filenameStr, 1,
JSVERSION_DEFAULT, returnStringOnly, rval);
return EvalInSandbox(cx, sandbox, source, filename ? filename :
"x-bogus://XPConnect/Sandbox", 1, JSVERSION_DEFAULT,
returnStringOnly, rval);
}
/* nsIXPConnectJSObjectHolder getWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo); */

View File

@ -3527,7 +3527,7 @@ CreateSandboxObject(JSContext *cx, JS::MutableHandleValue vp, nsISupports *prinO
// result, and cx->exception will be empty.
nsresult
EvalInSandbox(JSContext *cx, JS::HandleObject sandbox, const nsAString& source,
const nsACString& filename, int32_t lineNo,
const char *filename, int32_t lineNo,
JSVersion jsVersion, bool returnStringOnly,
JS::MutableHandleValue rval);

View File

@ -10,31 +10,35 @@
#include "nsISupports.idl"
// XXX - most "string"s in this file should probably move to Unicode
// so may as well use AStrings...
[scriptable, uuid(91d82105-7c62-4f8b-9779-154277c0ee90)]
interface nsIStackFrame : nsISupports
{
// see nsIProgrammingLanguage for list of language consts
readonly attribute uint32_t language;
readonly attribute AUTF8String languageName;
readonly attribute AUTF8String filename;
readonly attribute AUTF8String name;
readonly attribute string languageName;
readonly attribute string filename;
readonly attribute string name;
// Valid line numbers begin at '1'. '0' indicates unknown.
readonly attribute int32_t lineNumber;
readonly attribute AUTF8String sourceLine;
readonly attribute string sourceLine;
readonly attribute nsIStackFrame caller;
AUTF8String toString();
string toString();
};
[scriptable, uuid(F3A8D3B4-C424-4edc-8BF6-8974C983BA78)]
interface nsIException : nsISupports
{
// A custom message set by the thrower.
[binaryname(MessageMoz)] readonly attribute AUTF8String message;
[binaryname(MessageMoz)] readonly attribute string message;
// The nsresult associated with this exception.
readonly attribute nsresult result;
// The name of the error code (ie, a string repr of |result|)
readonly attribute AUTF8String name;
readonly attribute string name;
// Filename location. This is the location that caused the
// error, which may or may not be a source file location.
@ -44,7 +48,7 @@ interface nsIException : nsISupports
// etc.
// null indicates "no data"
readonly attribute AUTF8String filename;
readonly attribute string filename;
// Valid line numbers begin at '1'. '0' indicates unknown.
readonly attribute uint32_t lineNumber;
// Valid column numbers begin at 0.
@ -60,5 +64,5 @@ interface nsIException : nsISupports
readonly attribute nsISupports data;
// A generic formatter - make it suitable to print, etc.
AUTF8String toString();
string toString();
};