зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1283710 - Part 9: Make JSErrorToXPCException a file static function. r=bholley
This commit is contained in:
Родитель
025ed2f4bf
Коммит
2496019988
|
@ -1047,6 +1047,56 @@ private:
|
|||
RootedValue tvr;
|
||||
};
|
||||
|
||||
static nsresult
|
||||
JSErrorToXPCException(const char* toStringResult,
|
||||
const char* ifaceName,
|
||||
const char* methodName,
|
||||
const JSErrorReport* report,
|
||||
nsIException** exceptn)
|
||||
{
|
||||
AutoJSContext cx;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
RefPtr<nsScriptError> data;
|
||||
if (report) {
|
||||
nsAutoString bestMessage;
|
||||
if (report && report->message()) {
|
||||
CopyUTF8toUTF16(report->message().c_str(), bestMessage);
|
||||
} else if (toStringResult) {
|
||||
CopyUTF8toUTF16(toStringResult, bestMessage);
|
||||
} else {
|
||||
bestMessage.AssignLiteral("JavaScript Error");
|
||||
}
|
||||
|
||||
const char16_t* linebuf = report->linebuf();
|
||||
|
||||
data = new nsScriptError();
|
||||
data->InitWithWindowID(
|
||||
bestMessage,
|
||||
NS_ConvertASCIItoUTF16(report->filename),
|
||||
linebuf ? nsDependentString(linebuf, report->linebufLength()) : EmptyString(),
|
||||
report->lineno,
|
||||
report->tokenOffset(), report->flags,
|
||||
NS_LITERAL_CSTRING("XPConnect JavaScript"),
|
||||
nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx));
|
||||
}
|
||||
|
||||
if (data) {
|
||||
nsAutoCString formattedMsg;
|
||||
data->ToString(formattedMsg);
|
||||
|
||||
rv = XPCConvert::ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS,
|
||||
formattedMsg.get(), ifaceName,
|
||||
methodName,
|
||||
static_cast<nsIScriptError*>(data.get()),
|
||||
exceptn, nullptr, nullptr);
|
||||
} else {
|
||||
rv = XPCConvert::ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR,
|
||||
nullptr, ifaceName, methodName,
|
||||
nullptr, exceptn, nullptr, nullptr);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
XPCConvert::JSValToXPCException(MutableHandleValue s,
|
||||
|
@ -1187,58 +1237,6 @@ XPCConvert::JSValToXPCException(MutableHandleValue s,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/********************************/
|
||||
|
||||
// static
|
||||
nsresult
|
||||
XPCConvert::JSErrorToXPCException(const char* toStringResult,
|
||||
const char* ifaceName,
|
||||
const char* methodName,
|
||||
const JSErrorReport* report,
|
||||
nsIException** exceptn)
|
||||
{
|
||||
AutoJSContext cx;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
RefPtr<nsScriptError> data;
|
||||
if (report) {
|
||||
nsAutoString bestMessage;
|
||||
if (report && report->message()) {
|
||||
CopyUTF8toUTF16(report->message().c_str(), bestMessage);
|
||||
} else if (toStringResult) {
|
||||
CopyUTF8toUTF16(toStringResult, bestMessage);
|
||||
} else {
|
||||
bestMessage.AssignLiteral("JavaScript Error");
|
||||
}
|
||||
|
||||
const char16_t* linebuf = report->linebuf();
|
||||
|
||||
data = new nsScriptError();
|
||||
data->InitWithWindowID(
|
||||
bestMessage,
|
||||
NS_ConvertASCIItoUTF16(report->filename),
|
||||
linebuf ? nsDependentString(linebuf, report->linebufLength()) : EmptyString(),
|
||||
report->lineno,
|
||||
report->tokenOffset(), report->flags,
|
||||
NS_LITERAL_CSTRING("XPConnect JavaScript"),
|
||||
nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx));
|
||||
}
|
||||
|
||||
if (data) {
|
||||
nsAutoCString formattedMsg;
|
||||
data->ToString(formattedMsg);
|
||||
|
||||
rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS,
|
||||
formattedMsg.get(), ifaceName, methodName,
|
||||
static_cast<nsIScriptError*>(data.get()),
|
||||
exceptn, nullptr, nullptr);
|
||||
} else {
|
||||
rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR,
|
||||
nullptr, ifaceName, methodName, nullptr,
|
||||
exceptn, nullptr, nullptr);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// array fun...
|
||||
|
|
|
@ -2376,12 +2376,6 @@ public:
|
|||
const char* methodName,
|
||||
nsIException** exception);
|
||||
|
||||
static nsresult JSErrorToXPCException(const char* toStringResult,
|
||||
const char* ifaceName,
|
||||
const char* methodName,
|
||||
const JSErrorReport* report,
|
||||
nsIException** exception);
|
||||
|
||||
static nsresult ConstructException(nsresult rv, const char* message,
|
||||
const char* ifaceName,
|
||||
const char* methodName,
|
||||
|
|
Загрузка…
Ссылка в новой задаче