/work/obj-fuzz/dist/include/mozilla/dom/DOMRequest.h
Line | Count | Source (jump to first uncovered line) |
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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_domrequest_h__ |
8 | | #define mozilla_dom_domrequest_h__ |
9 | | |
10 | | #include "nsIDOMRequestService.h" |
11 | | #include "mozilla/Attributes.h" |
12 | | #include "mozilla/DOMEventTargetHelper.h" |
13 | | #include "mozilla/dom/DOMException.h" |
14 | | #include "mozilla/dom/DOMRequestBinding.h" |
15 | | |
16 | | #include "nsCOMPtr.h" |
17 | | |
18 | | namespace mozilla { |
19 | | |
20 | | class ErrorResult; |
21 | | |
22 | | namespace dom { |
23 | | |
24 | | class AnyCallback; |
25 | | class Promise; |
26 | | |
27 | | class DOMRequest : public DOMEventTargetHelper |
28 | | { |
29 | | protected: |
30 | | JS::Heap<JS::Value> mResult; |
31 | | RefPtr<DOMException> mError; |
32 | | RefPtr<Promise> mPromise; |
33 | | bool mDone; |
34 | | |
35 | | public: |
36 | | NS_DECL_ISUPPORTS_INHERITED |
37 | | |
38 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DOMRequest, |
39 | | DOMEventTargetHelper) |
40 | | |
41 | | // WrapperCache |
42 | | nsPIDOMWindowInner* GetParentObject() const |
43 | 0 | { |
44 | 0 | return GetOwner(); |
45 | 0 | } |
46 | | |
47 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
48 | | |
49 | | // WebIDL Interface |
50 | | DOMRequestReadyState ReadyState() const |
51 | 0 | { |
52 | 0 | return mDone ? DOMRequestReadyState::Done |
53 | 0 | : DOMRequestReadyState::Pending; |
54 | 0 | } |
55 | | |
56 | | void GetResult(JSContext*, JS::MutableHandle<JS::Value> aRetval) const |
57 | 0 | { |
58 | 0 | NS_ASSERTION(mDone || mResult.isUndefined(), |
59 | 0 | "Result should be undefined when pending"); |
60 | 0 | aRetval.set(mResult); |
61 | 0 | } |
62 | | |
63 | | DOMException* GetError() const |
64 | 0 | { |
65 | 0 | NS_ASSERTION(mDone || !mError, |
66 | 0 | "Error should be null when pending"); |
67 | 0 | return mError; |
68 | 0 | } |
69 | | |
70 | | IMPL_EVENT_HANDLER(success) |
71 | | IMPL_EVENT_HANDLER(error) |
72 | | |
73 | | void |
74 | | Then(JSContext* aCx, AnyCallback* aResolveCallback, |
75 | | AnyCallback* aRejectCallback, |
76 | | JS::MutableHandle<JS::Value> aRetval, |
77 | | mozilla::ErrorResult& aRv); |
78 | | |
79 | | void FireSuccess(JS::Handle<JS::Value> aResult); |
80 | | void FireError(const nsAString& aError); |
81 | | void FireError(nsresult aError); |
82 | | void FireDetailedError(DOMException& aError); |
83 | | |
84 | | explicit DOMRequest(nsPIDOMWindowInner* aWindow); |
85 | | explicit DOMRequest(nsIGlobalObject* aGlobal); |
86 | | |
87 | | protected: |
88 | | virtual ~DOMRequest(); |
89 | | |
90 | | void FireEvent(const nsAString& aType, bool aBubble, bool aCancelable); |
91 | | |
92 | | void RootResultVal(); |
93 | | }; |
94 | | |
95 | | class DOMRequestService final : public nsIDOMRequestService |
96 | | { |
97 | | ~DOMRequestService() {} |
98 | | |
99 | | public: |
100 | | NS_DECL_ISUPPORTS |
101 | | NS_DECL_NSIDOMREQUESTSERVICE |
102 | | |
103 | | // No one should call this but the factory. |
104 | | static already_AddRefed<DOMRequestService> FactoryCreate() |
105 | 0 | { |
106 | 0 | return MakeAndAddRef<DOMRequestService>(); |
107 | 0 | } |
108 | | }; |
109 | | |
110 | | } // namespace dom |
111 | | } // namespace mozilla |
112 | | |
113 | | #define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1" |
114 | | |
115 | | #endif // mozilla_dom_domrequest_h__ |