Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / dom / bindings / test / TestInterfaceAsyncIterableSingle.h
blobc92b35cc7b62f892f66f37f5ee473f359de05ef6
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_TestInterfaceAsyncIterableSingle_h
8 #define mozilla_dom_TestInterfaceAsyncIterableSingle_h
10 #include "IterableIterator.h"
11 #include "nsCOMPtr.h"
12 #include "nsWrapperCache.h"
13 #include "nsTArray.h"
14 #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h"
16 class nsPIDOMWindowInner;
18 namespace mozilla {
20 class ErrorResult;
22 namespace dom {
24 class GlobalObject;
25 struct TestInterfaceAsyncIterableSingleOptions;
27 // Implementation of test binding for webidl iterable interfaces, using
28 // primitives for value type
29 class TestInterfaceAsyncIterableSingle : public nsISupports,
30 public nsWrapperCache {
31 public:
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TestInterfaceAsyncIterableSingle)
35 explicit TestInterfaceAsyncIterableSingle(nsPIDOMWindowInner* aParent,
36 bool aFailToInit = false);
37 nsPIDOMWindowInner* GetParentObject() const;
38 virtual JSObject* WrapObject(JSContext* aCx,
39 JS::Handle<JSObject*> aGivenProto) override;
40 static already_AddRefed<TestInterfaceAsyncIterableSingle> Constructor(
41 const GlobalObject& aGlobal,
42 const TestInterfaceAsyncIterableSingleOptions& aOptions, ErrorResult& rv);
44 using Iterator = AsyncIterableIterator<TestInterfaceAsyncIterableSingle>;
45 already_AddRefed<Promise> GetNextIterationResult(Iterator* aIterator,
46 ErrorResult& aRv);
48 struct IteratorData {
49 void Traverse(nsCycleCollectionTraversalCallback& cb);
50 void Unlink();
52 uint32_t mIndex = 0;
53 uint32_t mMultiplier = 1;
54 Sequence<OwningNonNull<Promise>> mBlockingPromises;
55 size_t mBlockingPromisesIndex = 0;
56 uint32_t mFailNextAfter = 4294967295;
57 bool mThrowFromNext = false;
58 RefPtr<TestThrowingCallback> mThrowFromReturn;
61 void InitAsyncIteratorData(IteratorData& aData, Iterator::IteratorType aType,
62 ErrorResult& aError);
64 protected:
65 already_AddRefed<Promise> GetNextIterationResult(
66 IterableIteratorBase* aIterator, IteratorData& aData, ErrorResult& aRv);
68 virtual ~TestInterfaceAsyncIterableSingle() = default;
70 private:
71 void ResolvePromise(IterableIteratorBase* aIterator, IteratorData& aData,
72 Promise* aPromise);
74 nsCOMPtr<nsPIDOMWindowInner> mParent;
75 bool mFailToInit;
78 } // namespace dom
79 } // namespace mozilla
81 #endif // mozilla_dom_TestInterfaceAsyncIterableSingle_h