Bug 1286956 Serialize ErrorResult when transferring between threads. r=bz

This commit is contained in:
Ben Kelly 2016-07-15 16:27:28 -07:00
Родитель 8e2ea1af00
Коммит 71255bc78d
1 изменённых файлов: 18 добавлений и 14 удалений

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

@ -6,12 +6,14 @@
#include "ServiceWorkerRegistration.h" #include "ServiceWorkerRegistration.h"
#include "ipc/ErrorIPCUtils.h"
#include "mozilla/dom/Notification.h" #include "mozilla/dom/Notification.h"
#include "mozilla/dom/Promise.h" #include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseWorkerProxy.h" #include "mozilla/dom/PromiseWorkerProxy.h"
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h" #include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/unused.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
@ -387,7 +389,7 @@ public:
class UpdateResultRunnable final : public WorkerRunnable class UpdateResultRunnable final : public WorkerRunnable
{ {
RefPtr<PromiseWorkerProxy> mPromiseProxy; RefPtr<PromiseWorkerProxy> mPromiseProxy;
ErrorResult mStatus; IPC::Message mSerializedErrorResult;
~UpdateResultRunnable() ~UpdateResultRunnable()
{} {}
@ -396,30 +398,32 @@ public:
UpdateResultRunnable(PromiseWorkerProxy* aPromiseProxy, ErrorResult& aStatus) UpdateResultRunnable(PromiseWorkerProxy* aPromiseProxy, ErrorResult& aStatus)
: WorkerRunnable(aPromiseProxy->GetWorkerPrivate()) : WorkerRunnable(aPromiseProxy->GetWorkerPrivate())
, mPromiseProxy(aPromiseProxy) , mPromiseProxy(aPromiseProxy)
, mStatus(Move(aStatus)) {
{ } // ErrorResult is not thread safe. Serialize it for transfer across
// threads.
IPC::WriteParam(&mSerializedErrorResult, aStatus);
aStatus.SuppressException();
}
bool bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
{ {
// Deserialize the ErrorResult now that we are back in the worker
// thread.
ErrorResult status;
PickleIterator iter = PickleIterator(mSerializedErrorResult);
Unused << IPC::ReadParam(&mSerializedErrorResult, &iter, &status);
Promise* promise = mPromiseProxy->WorkerPromise(); Promise* promise = mPromiseProxy->WorkerPromise();
if (mStatus.Failed()) { if (status.Failed()) {
promise->MaybeReject(mStatus); promise->MaybeReject(status);
} else { } else {
promise->MaybeResolve(JS::UndefinedHandleValue); promise->MaybeResolve(JS::UndefinedHandleValue);
} }
mStatus.SuppressException(); status.SuppressException();
mPromiseProxy->CleanUp(); mPromiseProxy->CleanUp();
return true; return true;
} }
void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aSuccess) override
{
if (!aSuccess) {
mStatus.SuppressException();
}
}
}; };
class WorkerThreadUpdateCallback final : public ServiceWorkerUpdateFinishCallback class WorkerThreadUpdateCallback final : public ServiceWorkerUpdateFinishCallback