no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / dom / abort / AbortSignal.h
blobfef80b9dd2b3631af23d27a650044b1bf7639bb2
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_AbortSignal_h
8 #define mozilla_dom_AbortSignal_h
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/dom/AbortFollower.h"
12 #include "mozilla/DOMEventTargetHelper.h"
14 namespace mozilla::dom {
16 // AbortSignal the spec concept includes the concept of a child signal
17 // "following" a parent signal -- internally, adding abort steps to the parent
18 // signal that will then signal abort on the child signal -- to propagate
19 // signaling abort from one signal to another. See
20 // <https://dom.spec.whatwg.org/#abortsignal-follow>.
22 // This requires that AbortSignal also inherit from AbortFollower.
24 // This ability to follow isn't directly exposed in the DOM; as of this writing
25 // it appears only to be used internally in the Fetch API. It might be a good
26 // idea to split AbortSignal into an implementation that can follow, and an
27 // implementation that can't, to provide this complexity only when it's needed.
28 class AbortSignal : public DOMEventTargetHelper, public AbortSignalImpl {
29 public:
30 NS_DECL_ISUPPORTS_INHERITED
31 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(AbortSignal,
32 DOMEventTargetHelper)
34 AbortSignal(nsIGlobalObject* aGlobalObject, bool aAborted,
35 JS::Handle<JS::Value> aReason);
37 JSObject* WrapObject(JSContext* aCx,
38 JS::Handle<JSObject*> aGivenProto) override;
40 IMPL_EVENT_HANDLER(abort);
42 static already_AddRefed<AbortSignal> Abort(GlobalObject& aGlobal,
43 JS::Handle<JS::Value> aReason);
45 static already_AddRefed<AbortSignal> Timeout(GlobalObject& aGlobal,
46 uint64_t aMilliseconds,
47 ErrorResult& aRv);
49 static already_AddRefed<AbortSignal> Any(
50 GlobalObject& aGlobal,
51 const Sequence<OwningNonNull<AbortSignal>>& aSignals);
52 static already_AddRefed<AbortSignal> Any(
53 nsIGlobalObject* aGlobal,
54 const Span<const OwningNonNull<AbortSignal>>& aSignals);
56 void ThrowIfAborted(JSContext* aCx, ErrorResult& aRv);
58 virtual bool IsTaskSignal() const { return false; }
60 bool Dependent() const;
62 protected:
63 ~AbortSignal();
65 void MakeDependentOn(AbortSignal* aSignal);
67 void SignalAbortWithDependents() override;
69 void RunAbortSteps() override;
71 nsTArray<WeakPtr<AbortSignal>> mSourceSignals;
72 nsTArray<RefPtr<AbortSignal>> mDependentSignals;
74 bool mDependent;
77 } // namespace mozilla::dom
79 #endif // mozilla_dom_AbortSignal_h