TestInterfaceAsyncIterableSingle.h (2857B)
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/. */ 6 7 #ifndef mozilla_dom_TestInterfaceAsyncIterableSingle_h 8 #define mozilla_dom_TestInterfaceAsyncIterableSingle_h 9 10 #include "IterableIterator.h" 11 #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h" 12 #include "nsCOMPtr.h" 13 #include "nsTArray.h" 14 #include "nsWrapperCache.h" 15 16 class nsPIDOMWindowInner; 17 18 namespace mozilla { 19 20 class ErrorResult; 21 22 namespace dom { 23 24 class GlobalObject; 25 struct TestInterfaceAsyncIterableSingleOptions; 26 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) 34 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); 43 44 using Iterator = AsyncIterableIterator<TestInterfaceAsyncIterableSingle>; 45 already_AddRefed<Promise> GetNextIterationResult(Iterator* aIterator, 46 ErrorResult& aRv); 47 48 struct IteratorData { 49 void Traverse(nsCycleCollectionTraversalCallback& cb); 50 void Unlink(); 51 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; 59 }; 60 61 void InitAsyncIteratorData(IteratorData& aData, Iterator::IteratorType aType, 62 ErrorResult& aError); 63 64 protected: 65 already_AddRefed<Promise> GetNextIterationResult( 66 IterableIteratorBase* aIterator, IteratorData& aData, ErrorResult& aRv); 67 68 virtual ~TestInterfaceAsyncIterableSingle() = default; 69 70 private: 71 void ResolvePromise(IterableIteratorBase* aIterator, IteratorData& aData, 72 Promise* aPromise); 73 74 nsCOMPtr<nsPIDOMWindowInner> mParent; 75 bool mFailToInit; 76 }; 77 78 } // namespace dom 79 } // namespace mozilla 80 81 #endif // mozilla_dom_TestInterfaceAsyncIterableSingle_h