no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / dom / abort / AbortSignal.h
blobb5732cb022b0ea8c417fecc5b823f55873f9a362
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,
29 public AbortSignalImpl,
30 public AbortFollower {
31 public:
32 NS_DECL_ISUPPORTS_INHERITED
33 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(AbortSignal,
34 DOMEventTargetHelper)
36 AbortSignal(nsIGlobalObject* aGlobalObject, bool aAborted,
37 JS::Handle<JS::Value> aReason);
39 JSObject* WrapObject(JSContext* aCx,
40 JS::Handle<JSObject*> aGivenProto) override;
42 IMPL_EVENT_HANDLER(abort);
44 static already_AddRefed<AbortSignal> Abort(GlobalObject& aGlobal,
45 JS::Handle<JS::Value> aReason);
47 static already_AddRefed<AbortSignal> Timeout(GlobalObject& aGlobal,
48 uint64_t aMilliseconds,
49 ErrorResult& aRv);
51 static already_AddRefed<AbortSignal> Any(
52 GlobalObject& aGlobal,
53 const Sequence<OwningNonNull<AbortSignal>>& aSignals);
55 void ThrowIfAborted(JSContext* aCx, ErrorResult& aRv);
57 // AbortSignalImpl
58 void SignalAbort(JS::Handle<JS::Value> aReason) override;
60 // AbortFollower
61 void RunAbortAlgorithm() override;
63 virtual bool IsTaskSignal() const { return false; }
65 bool Dependent() const;
67 protected:
68 ~AbortSignal();
70 void MakeDependentOn(AbortSignal* aSignal);
72 nsTArray<WeakPtr<AbortSignal>> mSourceSignals;
73 nsTArray<RefPtr<AbortSignal>> mDependentSignals;
75 bool mDependent;
78 } // namespace mozilla::dom
80 #endif // mozilla_dom_AbortSignal_h