зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 2cba58b2e1b4 (bug 1100498) for m-oth js crashes
--HG-- extra : rebase_source : 1f90cff0e3a790d034cd73a1641fbc9c89998a58
This commit is contained in:
Родитель
616a34a8b6
Коммит
415a18b516
|
@ -681,83 +681,42 @@ ErrorReport::~ErrorReport()
|
|||
js_free(const_cast<char16_t*>(ownedReport.ucmessage));
|
||||
}
|
||||
|
||||
void
|
||||
ErrorReport::ReportAddonExceptionToTelementry(JSContext* cx)
|
||||
{
|
||||
MOZ_ASSERT(exnObject);
|
||||
RootedObject unwrapped(cx, UncheckedUnwrap(exnObject));
|
||||
MOZ_ASSERT(unwrapped, "UncheckedUnwrap failed?");
|
||||
|
||||
// There is not much we can report if the exception is not an ErrorObject, let's ignore those.
|
||||
if (!unwrapped->is<ErrorObject>())
|
||||
return;
|
||||
|
||||
Rooted<ErrorObject*> errObj(cx, &unwrapped->as<ErrorObject>());
|
||||
RootedObject stack(cx, errObj->stack());
|
||||
|
||||
// Let's ignore TOP level exceptions. For regular add-ons those will not be reported anyway,
|
||||
// for SDK based once it should not be a valid case either.
|
||||
// At this point the frame stack is unwound but the exception object stored the stack so let's
|
||||
// use that for getting the function name.
|
||||
if (!stack)
|
||||
return;
|
||||
|
||||
JSCompartment* comp = stack->compartment();
|
||||
JSAddonId* addonId = comp->addonId;
|
||||
|
||||
// We only want to send the report if the scope that just have thrown belongs to an add-on.
|
||||
// Let's check the compartment of the youngest function on the stack, to determine that.
|
||||
if (!addonId)
|
||||
return;
|
||||
|
||||
RootedString funnameString(cx);
|
||||
JS::SavedFrameResult result = GetSavedFrameFunctionDisplayName(cx, stack, &funnameString);
|
||||
// AccessDenied should never be the case here for add-ons but let's not risk it.
|
||||
JSAutoByteString bytes;
|
||||
const char* funname = nullptr;
|
||||
funname = result == JS::SavedFrameResult::AccessDenied ? "unknown"
|
||||
: AtomToPrintableString(cx,
|
||||
&funnameString->asAtom(),
|
||||
&bytes);
|
||||
|
||||
UniqueChars addonIdChars(JS_EncodeString(cx, addonId));
|
||||
|
||||
const char* filename = nullptr;
|
||||
if (reportp && reportp->filename) {
|
||||
filename = strrchr(reportp->filename, '/');
|
||||
if (filename)
|
||||
filename++;
|
||||
}
|
||||
if (!filename) {
|
||||
filename = "FILE_NOT_FOUND";
|
||||
}
|
||||
char histogramKey[64];
|
||||
JS_snprintf(histogramKey, sizeof(histogramKey),
|
||||
"%s %s %s %u",
|
||||
addonIdChars.get(),
|
||||
funname,
|
||||
filename,
|
||||
(reportp ? reportp->lineno : 0) );
|
||||
cx->runtime()->addTelemetry(JS_TELEMETRY_ADDON_EXCEPTIONS, 1, histogramKey);
|
||||
}
|
||||
|
||||
bool
|
||||
ErrorReport::init(JSContext* cx, HandleValue exn)
|
||||
{
|
||||
MOZ_ASSERT(!cx->isExceptionPending());
|
||||
|
||||
/*
|
||||
* Because ToString below could error and an exception object could become
|
||||
* unrooted, we must root our exception object, if any.
|
||||
*/
|
||||
if (exn.isObject()) {
|
||||
// Because ToString below could error and an exception object could become
|
||||
// unrooted, we must root our exception object, if any.
|
||||
exnObject = &exn.toObject();
|
||||
reportp = ErrorFromException(cx, exnObject);
|
||||
|
||||
// Let's see if the exception is from add-on code, if so, it should be reported
|
||||
// to telementry.
|
||||
ReportAddonExceptionToTelementry(cx);
|
||||
JSCompartment* comp = exnObject->compartment();
|
||||
JSAddonId* addonId = comp->addonId;
|
||||
if (addonId) {
|
||||
UniqueChars addonIdChars(JS_EncodeString(cx, addonId));
|
||||
|
||||
const char* filename = nullptr;
|
||||
if (reportp && reportp->filename) {
|
||||
filename = strrchr(reportp->filename, '/');
|
||||
if (filename)
|
||||
filename++;
|
||||
}
|
||||
if (!filename) {
|
||||
filename = "FILE_NOT_FOUND";
|
||||
}
|
||||
char histogramKey[64];
|
||||
JS_snprintf(histogramKey, sizeof(histogramKey),
|
||||
"%s %s %u",
|
||||
addonIdChars.get(),
|
||||
filename,
|
||||
(reportp ? reportp->lineno : 0) );
|
||||
cx->runtime()->addTelemetry(JS_TELEMETRY_ADDON_EXCEPTIONS, 1, histogramKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Be careful not to invoke ToString if we've already successfully extracted
|
||||
// an error report, since the exception might be wrapped in a security
|
||||
// wrapper, and ToString-ing it might throw.
|
||||
|
|
|
@ -1396,9 +1396,6 @@ struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport)
|
|||
bool populateUncaughtExceptionReport(JSContext* cx, ...);
|
||||
bool populateUncaughtExceptionReportVA(JSContext* cx, va_list ap);
|
||||
|
||||
// Reports exceptions from add-on scopes to telementry.
|
||||
void ReportAddonExceptionToTelementry(JSContext* cx);
|
||||
|
||||
// We may have a provided JSErrorReport, so need a way to represent that.
|
||||
JSErrorReport* reportp;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче