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"
12 #include "nsWrapperCache.h"
14 #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h"
16 class nsPIDOMWindowInner
;
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
{
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
,
49 void Traverse(nsCycleCollectionTraversalCallback
& cb
);
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
,
65 already_AddRefed
<Promise
> GetNextIterationResult(
66 IterableIteratorBase
* aIterator
, IteratorData
& aData
, ErrorResult
& aRv
);
68 virtual ~TestInterfaceAsyncIterableSingle() = default;
71 void ResolvePromise(IterableIteratorBase
* aIterator
, IteratorData
& aData
,
74 nsCOMPtr
<nsPIDOMWindowInner
> mParent
;
79 } // namespace mozilla
81 #endif // mozilla_dom_TestInterfaceAsyncIterableSingle_h