Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / toolkit / components / antitracking / bouncetrackingprotection / PromiseNativeWrapper.h
blob616b62130eff87a4a469a27bfefcd4461ff4da8d
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #ifndef mozilla_PromiseNativeWrapper_h__
5 #define mozilla_PromiseNativeWrapper_h__
7 #include "mozilla/MozPromise.h"
8 #include "mozilla/dom/Promise.h"
9 #include "nsISupports.h"
10 #include "mozilla/dom/PromiseNativeHandler.h"
12 namespace mozilla {
14 // Helper for wrapping JS promises in MozPromise so they can be handled from C++
15 // side.
16 class PromiseNativeWrapper : public dom::PromiseNativeHandler {
17 public:
18 NS_DECL_ISUPPORTS
20 explicit PromiseNativeWrapper(
21 MozPromiseHolder<GenericNonExclusivePromise>&& aHolder)
22 : mHolder(std::move(aHolder)) {}
24 void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
25 ErrorResult& aRv) override {
26 mHolder.Resolve(true, __func__);
29 void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
30 ErrorResult& aRv) override {
31 mHolder.Reject(NS_ERROR_FAILURE, __func__);
34 static RefPtr<GenericNonExclusivePromise> ConvertJSPromiseToMozPromise(
35 const RefPtr<dom::Promise>& jsPromise);
37 private:
38 ~PromiseNativeWrapper() = default;
39 MozPromiseHolder<GenericNonExclusivePromise> mHolder;
42 } // namespace mozilla
44 #endif