зеркало из https://github.com/mozilla/gecko-dev.git
Bug 966452 part 2. Report all unhandled Promise rejections. r=nsm
This commit is contained in:
Родитель
5ae9050749
Коммит
2a36000fa7
|
@ -22,6 +22,7 @@
|
||||||
#include "nsJSUtils.h"
|
#include "nsJSUtils.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
#include "nsJSEnvironment.h"
|
#include "nsJSEnvironment.h"
|
||||||
|
#include "nsIScriptObjectPrincipal.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
@ -1039,14 +1040,22 @@ Promise::MaybeReportRejected()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mResult.isObject()) {
|
ThreadsafeAutoJSContext cx;
|
||||||
|
Maybe<JSAutoCompartment> ac;
|
||||||
|
Maybe<JS::Rooted<JSObject*>> obj;
|
||||||
|
JS::Rooted<JS::Value> val(cx, mResult);
|
||||||
|
if (val.isObject()) {
|
||||||
|
obj.construct(cx, &val.toObject());
|
||||||
|
ac.construct(cx, obj.ref());
|
||||||
|
} else if (!JS_WrapValue(cx, &val)) {
|
||||||
|
JS_ClearPendingException(cx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ThreadsafeAutoJSContext cx;
|
|
||||||
JS::Rooted<JSObject*> obj(cx, &mResult.toObject());
|
JS::ExposeValueToActiveJS(val);
|
||||||
JSAutoCompartment ac(cx, obj);
|
js::ErrorReport report(cx);
|
||||||
JSErrorReport* report = JS_ErrorFromException(cx, obj);
|
if (!report.init(cx, val)) {
|
||||||
if (!report) {
|
JS_ClearPendingException(cx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1055,9 +1064,24 @@ Promise::MaybeReportRejected()
|
||||||
bool isChromeError = false;
|
bool isChromeError = false;
|
||||||
|
|
||||||
if (MOZ_LIKELY(NS_IsMainThread())) {
|
if (MOZ_LIKELY(NS_IsMainThread())) {
|
||||||
win =
|
nsIPrincipal* principal;
|
||||||
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(obj));
|
if (!obj.empty()) {
|
||||||
nsIPrincipal* principal = nsContentUtils::ObjectPrincipal(obj);
|
win =
|
||||||
|
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(obj.ref()));
|
||||||
|
principal = nsContentUtils::ObjectPrincipal(obj.ref());
|
||||||
|
} else {
|
||||||
|
// Just use our global if we can.
|
||||||
|
win = do_QueryInterface(GetParentObject());
|
||||||
|
if (!win) {
|
||||||
|
// Give up. We just have no sane way to report this.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nsCOMPtr<nsIScriptObjectPrincipal> scriptPrin = do_QueryInterface(win);
|
||||||
|
principal = scriptPrin->GetPrincipal();
|
||||||
|
if (!principal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
isChromeError = nsContentUtils::IsSystemPrincipal(principal);
|
isChromeError = nsContentUtils::IsSystemPrincipal(principal);
|
||||||
} else {
|
} else {
|
||||||
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
||||||
|
@ -1070,9 +1094,9 @@ Promise::MaybeReportRejected()
|
||||||
// AsyncErrorReporter, otherwise if the call to DispatchToMainThread fails, it
|
// AsyncErrorReporter, otherwise if the call to DispatchToMainThread fails, it
|
||||||
// will leak. See Bug 958684.
|
// will leak. See Bug 958684.
|
||||||
nsRefPtr<AsyncErrorReporter> r =
|
nsRefPtr<AsyncErrorReporter> r =
|
||||||
new AsyncErrorReporter(JS_GetObjectRuntime(obj),
|
new AsyncErrorReporter(CycleCollectedJSRuntime::Get()->Runtime(),
|
||||||
report,
|
report.report(),
|
||||||
nullptr,
|
report.message(),
|
||||||
isChromeError,
|
isChromeError,
|
||||||
win);
|
win);
|
||||||
NS_DispatchToMainThread(r);
|
NS_DispatchToMainThread(r);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче