Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / workers / WorkerEventTarget.h
blobdd9cb61748aa524aee76f8e737817a9b0b856baf
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_WorkerEventTarget_h
8 #define mozilla_dom_WorkerEventTarget_h
10 #include "nsISerialEventTarget.h"
11 #include "mozilla/Mutex.h"
12 #include "mozilla/dom/WorkerPrivate.h"
14 namespace mozilla::dom {
16 class WorkerEventTarget final : public nsISerialEventTarget {
17 public:
18 // The WorkerEventTarget supports different dispatch behaviors:
20 // * Hybrid targets will attempt to dispatch as a normal runnable,
21 // but fallback to a control runnable if that fails. This is
22 // often necessary for code that wants normal dispatch order, but
23 // also needs to execute while the worker is shutting down (possibly
24 // with a holder in place.)
26 // * ControlOnly targets will simply dispatch a control runnable.
27 enum class Behavior : uint8_t { Hybrid, ControlOnly };
29 private:
30 mozilla::Mutex mMutex;
31 CheckedUnsafePtr<WorkerPrivate> mWorkerPrivate MOZ_GUARDED_BY(mMutex);
32 const Behavior mBehavior MOZ_GUARDED_BY(mMutex);
34 ~WorkerEventTarget() = default;
36 public:
37 WorkerEventTarget(WorkerPrivate* aWorkerPrivate, Behavior aBehavior);
39 void ForgetWorkerPrivate(WorkerPrivate* aWorkerPrivate);
41 NS_DECL_THREADSAFE_ISUPPORTS
42 NS_DECL_NSIEVENTTARGET
43 NS_DECL_NSISERIALEVENTTARGET
46 } // namespace mozilla::dom
48 #endif // mozilla_dom_WorkerEventTarget_h