Bug 1255298. Just pass through the JSContext when passing through the NotificationOptions in notification code. r=wchen

This commit is contained in:
Boris Zbarsky 2016-03-10 18:07:28 -05:00
Родитель 2ce6bc7ebf
Коммит 5a9c81f6df
3 изменённых файлов: 24 добавлений и 21 удалений

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

@ -1049,7 +1049,8 @@ Notification::Constructor(const GlobalObject& aGlobal,
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
RefPtr<Notification> notification =
CreateAndShow(global, aTitle, aOptions, EmptyString(), aRv);
CreateAndShow(aGlobal.Context(), global, aTitle, aOptions,
EmptyString(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
@ -2592,7 +2593,8 @@ public:
/* static */
already_AddRefed<Promise>
Notification::ShowPersistentNotification(nsIGlobalObject *aGlobal,
Notification::ShowPersistentNotification(JSContext* aCx,
nsIGlobalObject *aGlobal,
const nsAString& aScope,
const nsAString& aTitle,
const NotificationOptions& aOptions,
@ -2669,7 +2671,7 @@ Notification::ShowPersistentNotification(nsIGlobalObject *aGlobal,
p->MaybeResolve(JS::UndefinedHandleValue);
RefPtr<Notification> notification =
CreateAndShow(aGlobal, aTitle, aOptions, aScope, aRv);
CreateAndShow(aCx, aGlobal, aTitle, aOptions, aScope, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
@ -2678,7 +2680,8 @@ Notification::ShowPersistentNotification(nsIGlobalObject *aGlobal,
}
/* static */ already_AddRefed<Notification>
Notification::CreateAndShow(nsIGlobalObject* aGlobal,
Notification::CreateAndShow(JSContext* aCx,
nsIGlobalObject* aGlobal,
const nsAString& aTitle,
const NotificationOptions& aOptions,
const nsAString& aScope,
@ -2686,21 +2689,12 @@ Notification::CreateAndShow(nsIGlobalObject* aGlobal,
{
MOZ_ASSERT(aGlobal);
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(aGlobal)))
{
aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
return nullptr;
}
JSContext* cx = jsapi.cx();
RefPtr<Notification> notification = CreateInternal(aGlobal, EmptyString(),
aTitle, aOptions);
aTitle, aOptions);
// Make a structured clone of the aOptions.mData object
JS::Rooted<JS::Value> data(cx, aOptions.mData);
notification->InitFromJSVal(cx, data, aRv);
JS::Rooted<JS::Value> data(aCx, aOptions.mData);
notification->InitFromJSVal(aCx, data, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}

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

@ -259,8 +259,13 @@ public:
// Notification implementation of
// ServiceWorkerRegistration.showNotification.
//
//
// Note that aCx may not be in the compartment of aGlobal, but aOptions will
// have its JS things in the compartment of aCx.
static already_AddRefed<Promise>
ShowPersistentNotification(nsIGlobalObject* aGlobal,
ShowPersistentNotification(JSContext* aCx,
nsIGlobalObject* aGlobal,
const nsAString& aScope,
const nsAString& aTitle,
const NotificationOptions& aOptions,
@ -417,8 +422,12 @@ private:
// Notification if result is NS_OK. The lifetime of this Notification is tied
// to an underlying NotificationRef. Do not hold a non-stack raw pointer to
// it. Be careful about thread safety if acquiring a strong reference.
//
// Note that aCx may not be in the compartment of aGlobal, but aOptions will
// have its JS things in the compartment of aCx.
static already_AddRefed<Notification>
CreateAndShow(nsIGlobalObject* aGlobal,
CreateAndShow(JSContext* aCx,
nsIGlobalObject* aGlobal,
const nsAString& aTitle,
const NotificationOptions& aOptions,
const nsAString& aScope,

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

@ -729,8 +729,8 @@ ServiceWorkerRegistrationMainThread::ShowNotification(JSContext* aCx,
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(window);
RefPtr<Promise> p =
Notification::ShowPersistentNotification(global,
mScope, aTitle, aOptions, aRv);
Notification::ShowPersistentNotification(aCx, global, mScope, aTitle,
aOptions, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
@ -1212,7 +1212,7 @@ ServiceWorkerRegistrationWorkerThread::ShowNotification(JSContext* aCx,
// also verifying scope so that we block the worker on the main thread only
// once.
RefPtr<Promise> p =
Notification::ShowPersistentNotification(mWorkerPrivate->GlobalScope(),
Notification::ShowPersistentNotification(aCx, mWorkerPrivate->GlobalScope(),
mScope, aTitle, aOptions, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;