Issue #2089 - Use JS engine stack if necessary when reporting errors

Based-on: m-c 996060
This commit is contained in:
Martok 2023-01-21 02:13:01 +01:00 committed by roytam1
commit 6b50dd5d06
21 changed files with 209 additions and 69 deletions

View file

@ -577,8 +577,9 @@ AutoJSAPI::ReportException()
}
JSAutoCompartment ac(cx(), errorGlobal);
JS::Rooted<JS::Value> exn(cx());
JS::Rooted<JSObject*> exnStack(cx());
js::ErrorReport jsReport(cx());
if (StealException(&exn) &&
if (StealExceptionAndStack(&exn, &exnStack) &&
jsReport.init(cx(), exn, js::ErrorReport::WithSideEffects)) {
if (mIsMainThread) {
RefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
@ -595,10 +596,10 @@ AutoJSAPI::ReportException()
inner ? inner->WindowID() : 0);
if (inner && jsReport.report()->errorNumber != JSMSG_OUT_OF_MEMORY) {
JS::RootingContext* rcx = JS::RootingContext::get(cx());
DispatchScriptErrorEvent(inner, rcx, xpcReport, exn);
DispatchScriptErrorEvent(inner, rcx, xpcReport, exn, exnStack);
} else {
JS::Rooted<JSObject*> stack(cx(),
xpc::FindExceptionStackForConsoleReport(inner, exn));
xpc::FindExceptionStackForConsoleReport(inner, exn, exnStack));
xpcReport->LogToConsoleWithStack(stack);
}
} else {
@ -638,9 +639,16 @@ AutoJSAPI::PeekException(JS::MutableHandle<JS::Value> aVal)
bool
AutoJSAPI::StealException(JS::MutableHandle<JS::Value> aVal)
{
JS::Rooted<JSObject*> stack(cx());
return StealExceptionAndStack(aVal, &stack);
}
bool AutoJSAPI::StealExceptionAndStack(JS::MutableHandle<JS::Value> aVal,
JS::MutableHandle<JSObject*> aStack) {
if (!PeekException(aVal)) {
return false;
}
aStack.set(JS::GetPendingExceptionStack(cx()));
JS_ClearPendingException(cx());
return true;
}