Skip to content
Snippets Groups Projects
Commit 71255bc7 authored by Ben Kelly's avatar Ben Kelly
Browse files

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

parent 8e2ea1af
No related branches found
No related tags found
No related merge requests found
......@@ -6,12 +6,14 @@
#include "ServiceWorkerRegistration.h"
#include "ipc/ErrorIPCUtils.h"
#include "mozilla/dom/Notification.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseWorkerProxy.h"
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/unused.h"
#include "nsCycleCollectionParticipant.h"
#include "nsNetUtil.h"
#include "nsServiceManagerUtils.h"
......@@ -387,7 +389,7 @@ public:
class UpdateResultRunnable final : public WorkerRunnable
{
RefPtr<PromiseWorkerProxy> mPromiseProxy;
ErrorResult mStatus;
IPC::Message mSerializedErrorResult;
~UpdateResultRunnable()
{}
......@@ -396,30 +398,32 @@ public:
UpdateResultRunnable(PromiseWorkerProxy* aPromiseProxy, ErrorResult& aStatus)
: WorkerRunnable(aPromiseProxy->GetWorkerPrivate())
, mPromiseProxy(aPromiseProxy)
, mStatus(Move(aStatus))
{ }
{
// ErrorResult is not thread safe. Serialize it for transfer across
// threads.
IPC::WriteParam(&mSerializedErrorResult, aStatus);
aStatus.SuppressException();
}
bool
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();
if (mStatus.Failed()) {
promise->MaybeReject(mStatus);
if (status.Failed()) {
promise->MaybeReject(status);
} else {
promise->MaybeResolve(JS::UndefinedHandleValue);
}
mStatus.SuppressException();
status.SuppressException();
mPromiseProxy->CleanUp();
return true;
}
void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aSuccess) override
{
if (!aSuccess) {
mStatus.SuppressException();
}
}
};
class WorkerThreadUpdateCallback final : public ServiceWorkerUpdateFinishCallback
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment