Bug 1147215 - Add a helper to get the current window with a null check. r=smaug

This commit is contained in:
Bobby Holley 2015-03-25 11:36:58 -07:00
Родитель 7c855a15e6
Коммит 125cbceb13
3 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -483,7 +483,7 @@ WarningOnlyErrorReporter(JSContext* aCx, const char* aMessage, JSErrorReport* aR
{
MOZ_ASSERT(JSREPORT_IS_WARNING(aRep->flags));
nsRefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
nsPIDOMWindow* win = xpc::WindowGlobalOrNull(JS::CurrentGlobalOrNull(aCx));
nsPIDOMWindow* win = xpc::CurrentWindowOrNull(aCx);
xpcReport->Init(aRep, aMessage, nsContentUtils::IsCallerChrome(),
win ? win->WindowID() : 0);
xpcReport->LogToConsole();

Просмотреть файл

@ -597,6 +597,13 @@ AddonWindowOrNull(JSObject *aObj)
return WindowOrNull(mainGlobal);
}
nsGlobalWindow*
CurrentWindowOrNull(JSContext *cx)
{
JSObject *glob = JS::CurrentGlobalOrNull(cx);
return glob ? WindowOrNull(glob) : nullptr;
}
}
static void

Просмотреть файл

@ -469,6 +469,13 @@ WindowGlobalOrNull(JSObject *aObj);
nsGlobalWindow*
AddonWindowOrNull(JSObject *aObj);
/**
* If |cx| is in a compartment whose global is a window, returns the associated
* nsGlobalWindow. Otherwise, returns null.
*/
nsGlobalWindow*
CurrentWindowOrNull(JSContext *cx);
// Error reporter used when there is no associated DOM window on to which to
// report errors and warnings.
//