/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
virtualbool PreDispatch(WorkerPrivate* aWorkerPrivate) override { // Silence bad assertions, this can be dispatched from any thread. returntrue;
}
virtualvoid PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override { // Silence bad assertions, this can be dispatched from any thread.
}
// If the inner runnable is not cancellable, then just do the normal // WorkerControlRunnable thing. This will end up calling Run(). if (!cr) { return Run();
}
// Otherwise call the inner runnable's Cancel() and treat this like // a WorkerRunnable cancel. We can't call WorkerControlRunnable::Cancel() // in this case since that would result in both Run() and the inner // Cancel() being called. return cr->Cancel();
}
if (mBehavior == Behavior::Hybrid) {
LOGV(("WorkerEventTarget::Dispatch [%p] Dispatch as normal runnable(%p)", this, runnable.get()));
RefPtr<WorkerRunnable> r =
mWorkerPrivate->MaybeWrapAsWorkerRunnable(runnable.forget()); if (r->Dispatch(mWorkerPrivate)) { return NS_OK;
}
runnable = std::move(r);
LOGV(( "WorkerEventTarget::Dispatch [%p] Dispatch as normal runnable(%p) fail", this, runnable.get()));
}
RefPtr<WorkerControlRunnable> r = new WrappedControlRunnable(mWorkerPrivate, std::move(runnable));
LOGV(
("WorkerEventTarget::Dispatch [%p] Wrapped runnable as control " "runnable(%p)", this, r.get())); if (!r->Dispatch(mWorkerPrivate)) {
LOGV(
("WorkerEventTarget::Dispatch [%p] Dispatch as control runnable(%p) " "fail", this, r.get())); return NS_ERROR_FAILURE;
}
// If mWorkerPrivate is gone, the event target is already late during // shutdown, return NS_ERROR_UNEXPECTED as documented in `nsIEventTarget.idl`. if (!mWorkerPrivate) { return NS_ERROR_UNEXPECTED;
}