mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 995047. Change out stack/exception APIs to hand out AString instead of AUTF8String for filename/functionname, so we end up with fewer string conversions in practice. r=smaug
This commit is contained in:
parent
97faab00c5
commit
34e0756678
@ -94,13 +94,14 @@ class BlobURLsReporter MOZ_FINAL : public nsIMemoryReporter
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < maxFrames && frame; ++i) {
|
||||
nsCString fileName;
|
||||
nsString fileNameUTF16;
|
||||
int32_t lineNumber = 0;
|
||||
|
||||
frame->GetFilename(fileName);
|
||||
frame->GetFilename(fileNameUTF16);
|
||||
frame->GetLineNumber(&lineNumber);
|
||||
|
||||
if (!fileName.IsEmpty()) {
|
||||
if (!fileNameUTF16.IsEmpty()) {
|
||||
NS_ConvertUTF16toUTF8 fileName(fileNameUTF16);
|
||||
stack += "js(";
|
||||
if (!origin.IsEmpty()) {
|
||||
// Make the file name root-relative for conciseness if possible.
|
||||
|
@ -814,15 +814,12 @@ Console::Method(JSContext* aCx, MethodName aMethodName,
|
||||
language == nsIProgrammingLanguage::JAVASCRIPT2) {
|
||||
ConsoleStackEntry& data = *callData->mStack.AppendElement();
|
||||
|
||||
nsCString string;
|
||||
rv = stack->GetFilename(string);
|
||||
rv = stack->GetFilename(data.mFilename);
|
||||
if (NS_FAILED(rv)) {
|
||||
Throw(aCx, rv);
|
||||
return;
|
||||
}
|
||||
|
||||
CopyUTF8toUTF16(string, data.mFilename);
|
||||
|
||||
int32_t lineNumber;
|
||||
rv = stack->GetLineNumber(&lineNumber);
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -832,14 +829,12 @@ Console::Method(JSContext* aCx, MethodName aMethodName,
|
||||
|
||||
data.mLineNumber = lineNumber;
|
||||
|
||||
rv = stack->GetName(string);
|
||||
rv = stack->GetName(data.mFunctionName);
|
||||
if (NS_FAILED(rv)) {
|
||||
Throw(aCx, rv);
|
||||
return;
|
||||
}
|
||||
|
||||
CopyUTF8toUTF16(string, data.mFunctionName);
|
||||
|
||||
data.mLanguage = language;
|
||||
}
|
||||
|
||||
|
@ -320,9 +320,9 @@ Exception::GetName(nsACString& aName)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute AUTF8String filename; */
|
||||
/* readonly attribute AString filename; */
|
||||
NS_IMETHODIMP
|
||||
Exception::GetFilename(nsACString& aFilename)
|
||||
Exception::GetFilename(nsAString& aFilename)
|
||||
{
|
||||
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
@ -509,18 +509,6 @@ Exception::GetName(nsString& retval)
|
||||
CopyUTF8toUTF16(str, retval);
|
||||
}
|
||||
|
||||
void
|
||||
Exception::GetFilename(nsString& retval)
|
||||
{
|
||||
nsCString str;
|
||||
#ifdef DEBUG
|
||||
DebugOnly<nsresult> rv =
|
||||
#endif
|
||||
GetFilename(str);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
CopyUTF8toUTF16(str, retval);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Exception::LineNumber() const
|
||||
{
|
||||
@ -622,7 +610,7 @@ DOMException::ToString(nsACString& aReturn)
|
||||
nsAutoCString location;
|
||||
|
||||
if (mInner) {
|
||||
nsCString filename;
|
||||
nsString filename;
|
||||
mInner->GetFilename(filename);
|
||||
|
||||
if (!filename.IsEmpty()) {
|
||||
@ -630,7 +618,9 @@ DOMException::ToString(nsACString& aReturn)
|
||||
|
||||
mInner->GetLineNumber(&line_nr);
|
||||
|
||||
char *temp = PR_smprintf("%s Line: %d", filename.get(), line_nr);
|
||||
char *temp = PR_smprintf("%s Line: %d",
|
||||
NS_ConvertUTF16toUTF8(filename).get(),
|
||||
line_nr);
|
||||
if (temp) {
|
||||
location.Assign(temp);
|
||||
PR_smprintf_free(temp);
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
|
||||
void GetName(nsString& retval);
|
||||
|
||||
void GetFilename(nsString& retval);
|
||||
// The XPCOM GetFilename does the right thing.
|
||||
|
||||
uint32_t LineNumber() const;
|
||||
|
||||
@ -100,7 +100,7 @@ protected:
|
||||
nsCString mName;
|
||||
nsCOMPtr<nsIStackFrame> mLocation;
|
||||
nsCOMPtr<nsISupports> mData;
|
||||
nsCString mFilename;
|
||||
nsString mFilename;
|
||||
int mLineNumber;
|
||||
nsCOMPtr<nsIException> mInner;
|
||||
bool mInitialized;
|
||||
|
@ -302,8 +302,8 @@ private:
|
||||
nsCOMPtr<nsIStackFrame> mCaller;
|
||||
|
||||
// Cached values
|
||||
nsCString mFilename;
|
||||
nsCString mFunname;
|
||||
nsString mFilename;
|
||||
nsString mFunname;
|
||||
int32_t mLineno;
|
||||
uint32_t mLanguage;
|
||||
|
||||
@ -374,13 +374,13 @@ NS_IMETHODIMP JSStackFrame::GetLanguageName(nsACString& aLanguageName)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute string filename; */
|
||||
NS_IMETHODIMP JSStackFrame::GetFilename(nsACString& aFilename)
|
||||
/* readonly attribute AString filename; */
|
||||
NS_IMETHODIMP JSStackFrame::GetFilename(nsAString& aFilename)
|
||||
{
|
||||
if (!mFilenameInitialized) {
|
||||
JS::FrameDescription& desc = mStackDescription->FrameAt(mIndex);
|
||||
if (const char *filename = desc.filename()) {
|
||||
mFilename.Assign(filename);
|
||||
CopyUTF8toUTF16(filename, mFilename);
|
||||
}
|
||||
mFilenameInitialized = true;
|
||||
}
|
||||
@ -395,13 +395,15 @@ NS_IMETHODIMP JSStackFrame::GetFilename(nsACString& aFilename)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute string name; */
|
||||
NS_IMETHODIMP JSStackFrame::GetName(nsACString& aFunction)
|
||||
/* readonly attribute AString name; */
|
||||
NS_IMETHODIMP JSStackFrame::GetName(nsAString& aFunction)
|
||||
{
|
||||
if (!mFunnameInitialized) {
|
||||
JS::FrameDescription& desc = mStackDescription->FrameAt(mIndex);
|
||||
if (JSFlatString *name = desc.funDisplayName()) {
|
||||
CopyUTF16toUTF8(JS_GetFlatStringChars(name), mFunname);
|
||||
mFunname.Assign(JS_GetFlatStringChars(name),
|
||||
// XXXbz Can't JS_GetStringLength on JSFlatString!
|
||||
JS_GetStringLength(JS_FORGET_STRING_FLATNESS(name)));
|
||||
}
|
||||
mFunnameInitialized = true;
|
||||
}
|
||||
@ -460,24 +462,26 @@ NS_IMETHODIMP JSStackFrame::ToString(nsACString& _retval)
|
||||
|
||||
const char* frametype = IsJSFrame() ? "JS" : "native";
|
||||
|
||||
nsCString filename;
|
||||
nsString filename;
|
||||
nsresult rv = GetFilename(filename);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (filename.IsEmpty()) {
|
||||
filename.AssignASCII("<unknown filename>");
|
||||
filename.AssignLiteral("<unknown filename>");
|
||||
}
|
||||
|
||||
nsCString funname;
|
||||
nsString funname;
|
||||
rv = GetName(funname);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (funname.IsEmpty()) {
|
||||
funname.AssignASCII("<TOP_LEVEL>");
|
||||
funname.AssignLiteral("<TOP_LEVEL>");
|
||||
}
|
||||
static const char format[] = "%s frame :: %s :: %s :: line %d";
|
||||
_retval.AppendPrintf(format, frametype, filename.get(),
|
||||
funname.get(), GetLineno());
|
||||
_retval.AppendPrintf(format, frametype,
|
||||
NS_ConvertUTF16toUTF8(filename).get(),
|
||||
NS_ConvertUTF16toUTF8(funname).get(),
|
||||
GetLineno());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -511,8 +515,8 @@ JSStackFrame::CreateStackFrameLocation(uint32_t aLanguage,
|
||||
|
||||
self->mLanguage = aLanguage;
|
||||
self->mLineno = aLineNumber;
|
||||
self->mFilename = aFilename;
|
||||
self->mFunname = aFunctionName;
|
||||
CopyUTF8toUTF16(aFilename, self->mFilename);
|
||||
CopyUTF8toUTF16(aFunctionName, self->mFunname);
|
||||
|
||||
self->mCaller = aCaller;
|
||||
|
||||
|
@ -1541,13 +1541,13 @@ AssembleSandboxMemoryReporterName(JSContext *cx, nsCString &sandboxName)
|
||||
|
||||
// Append the caller's location information.
|
||||
if (frame) {
|
||||
nsCString location;
|
||||
nsString location;
|
||||
int32_t lineNumber = 0;
|
||||
frame->GetFilename(location);
|
||||
frame->GetLineNumber(&lineNumber);
|
||||
|
||||
sandboxName.AppendLiteral(" (from: ");
|
||||
sandboxName.Append(location);
|
||||
sandboxName.Append(NS_ConvertUTF16toUTF8(location));
|
||||
sandboxName.AppendLiteral(":");
|
||||
sandboxName.AppendInt(lineNumber);
|
||||
sandboxName.AppendLiteral(")");
|
||||
|
@ -2599,7 +2599,7 @@ nsXPCComponents_Utils::ReportError(HandleValue error, JSContext *cx)
|
||||
nsXPConnect *xpc = nsXPConnect::XPConnect();
|
||||
xpc->GetCurrentJSStack(getter_AddRefs(frame));
|
||||
|
||||
nsCString fileName;
|
||||
nsString fileName;
|
||||
int32_t lineNo = 0;
|
||||
if (frame) {
|
||||
frame->GetFilename(fileName);
|
||||
@ -2612,7 +2612,7 @@ 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,
|
||||
fileName, EmptyString(), lineNo, 0, 0,
|
||||
"XPConnect JavaScript", innerWindowID);
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
@ -2672,7 +2672,9 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
|
||||
nsCOMPtr<nsIStackFrame> frame;
|
||||
xpc->GetCurrentJSStack(getter_AddRefs(frame));
|
||||
if (frame) {
|
||||
frame->GetFilename(filename);
|
||||
nsString frameFile;
|
||||
frame->GetFilename(frameFile);
|
||||
CopyUTF16toUTF8(frameFile, filename);
|
||||
frame->GetLineNumber(&lineNo);
|
||||
}
|
||||
}
|
||||
|
@ -912,7 +912,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
|
||||
// try to get filename, lineno from the first
|
||||
// stack frame location.
|
||||
int32_t lineNumber = 0;
|
||||
nsCString sourceName;
|
||||
nsString sourceName;
|
||||
|
||||
nsCOMPtr<nsIStackFrame> location;
|
||||
xpc_exception->
|
||||
@ -926,7 +926,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
|
||||
}
|
||||
|
||||
rv = scriptError->InitWithWindowID(NS_ConvertUTF8toUTF16(newMessage),
|
||||
NS_ConvertUTF8toUTF16(sourceName),
|
||||
sourceName,
|
||||
EmptyString(),
|
||||
lineNumber, 0, 0,
|
||||
"XPConnect JavaScript",
|
||||
|
@ -10,14 +10,14 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(60abee59-717e-477d-8bbb-a1c3e7067126)]
|
||||
[scriptable, uuid(3bc4793f-e6be-44d6-b839-d6b9e85e5346)]
|
||||
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 AString filename;
|
||||
readonly attribute AString name;
|
||||
// Valid line numbers begin at '1'. '0' indicates unknown.
|
||||
readonly attribute int32_t lineNumber;
|
||||
readonly attribute AUTF8String sourceLine;
|
||||
@ -26,7 +26,7 @@ interface nsIStackFrame : nsISupports
|
||||
AUTF8String toString();
|
||||
};
|
||||
|
||||
[scriptable, uuid(6738090a-ba6f-4f3f-8aa0-b9f6311262a5)]
|
||||
[scriptable, uuid(1caf1461-be1d-4b79-a552-5292b6bf3c35)]
|
||||
interface nsIException : nsISupports
|
||||
{
|
||||
// A custom message set by the thrower.
|
||||
@ -44,7 +44,7 @@ interface nsIException : nsISupports
|
||||
// etc.
|
||||
|
||||
// null indicates "no data"
|
||||
readonly attribute AUTF8String filename;
|
||||
readonly attribute AString filename;
|
||||
// Valid line numbers begin at '1'. '0' indicates unknown.
|
||||
readonly attribute uint32_t lineNumber;
|
||||
// Valid column numbers begin at 0.
|
||||
|
Loading…
Reference in New Issue
Block a user