Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / promise / PromiseCallback.h
blobb2dbb1378dfa22e64abdefa3ee28efb56cf6a7ab
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_PromiseCallback_h
8 #define mozilla_dom_PromiseCallback_h
10 #include "mozilla/dom/Promise.h"
11 #include "nsCycleCollectionParticipant.h"
13 namespace mozilla {
14 namespace dom {
16 // This is the base class for any PromiseCallback.
17 // It's a logical step in the promise chain of callbacks.
18 class PromiseCallback : public nsISupports
20 protected:
21 virtual ~PromiseCallback();
23 public:
24 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25 NS_DECL_CYCLE_COLLECTION_CLASS(PromiseCallback)
27 PromiseCallback();
29 virtual void Call(JSContext* aCx,
30 JS::Handle<JS::Value> aValue) = 0;
32 enum Task {
33 Resolve,
34 Reject
37 // This factory returns a PromiseCallback object with refcount of 0.
38 static PromiseCallback*
39 Factory(Promise* aNextPromise, JS::Handle<JSObject*> aObject,
40 AnyCallback* aCallback, Task aTask);
43 // WrapperPromiseCallback execs a JS Callback with a value, and then the return
44 // value is sent to the aNextPromise->ResolveFunction() or to
45 // aNextPromise->RejectFunction() if the JS Callback throws.
46 class WrapperPromiseCallback MOZ_FINAL : public PromiseCallback
48 public:
49 NS_DECL_ISUPPORTS_INHERITED
50 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WrapperPromiseCallback,
51 PromiseCallback)
53 void Call(JSContext* aCx,
54 JS::Handle<JS::Value> aValue) MOZ_OVERRIDE;
56 WrapperPromiseCallback(Promise* aNextPromise, JS::Handle<JSObject*> aGlobal,
57 AnyCallback* aCallback);
59 private:
60 ~WrapperPromiseCallback();
62 nsRefPtr<Promise> mNextPromise;
63 JS::Heap<JSObject*> mGlobal;
64 nsRefPtr<AnyCallback> mCallback;
67 // ResolvePromiseCallback calls aPromise->ResolveFunction() with the value
68 // received by Call().
69 class ResolvePromiseCallback MOZ_FINAL : public PromiseCallback
71 public:
72 NS_DECL_ISUPPORTS_INHERITED
73 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ResolvePromiseCallback,
74 PromiseCallback)
76 void Call(JSContext* aCx,
77 JS::Handle<JS::Value> aValue) MOZ_OVERRIDE;
79 ResolvePromiseCallback(Promise* aPromise, JS::Handle<JSObject*> aGlobal);
81 private:
82 ~ResolvePromiseCallback();
84 nsRefPtr<Promise> mPromise;
85 JS::Heap<JSObject*> mGlobal;
88 // RejectPromiseCallback calls aPromise->RejectFunction() with the value
89 // received by Call().
90 class RejectPromiseCallback MOZ_FINAL : public PromiseCallback
92 public:
93 NS_DECL_ISUPPORTS_INHERITED
94 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(RejectPromiseCallback,
95 PromiseCallback)
97 void Call(JSContext* aCx,
98 JS::Handle<JS::Value> aValue) MOZ_OVERRIDE;
100 RejectPromiseCallback(Promise* aPromise, JS::Handle<JSObject*> aGlobal);
102 private:
103 ~RejectPromiseCallback();
105 nsRefPtr<Promise> mPromise;
106 JS::Heap<JSObject*> mGlobal;
109 // NativePromiseCallback wraps a NativePromiseHandler.
110 class NativePromiseCallback MOZ_FINAL : public PromiseCallback
112 public:
113 NS_DECL_ISUPPORTS_INHERITED
114 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(NativePromiseCallback,
115 PromiseCallback)
117 void Call(JSContext* aCx,
118 JS::Handle<JS::Value> aValue) MOZ_OVERRIDE;
120 NativePromiseCallback(PromiseNativeHandler* aHandler,
121 Promise::PromiseState aState);
123 private:
124 ~NativePromiseCallback();
126 nsRefPtr<PromiseNativeHandler> mHandler;
127 Promise::PromiseState mState;
130 } // namespace dom
131 } // namespace mozilla
133 #endif // mozilla_dom_PromiseCallback_h