/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_dom_Promise_inl_h #define mozilla_dom_Promise_inl_h #include "mozilla/TupleCycleCollection.h" #include "mozilla/TypeTraits.h" #include "mozilla/ResultExtensions.h" #include "mozilla/dom/PromiseNativeHandler.h" namespace mozilla { namespace dom { class PromiseNativeThenHandlerBase : public PromiseNativeHandler { NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_CLASS(PromiseNativeThenHandlerBase) PromiseNativeThenHandlerBase(Promise& aPromise) : mPromise(&aPromise) {} void ResolvedCallback(JSContext* aCx, JS::Handle aValue) override; void RejectedCallback(JSContext* aCx, JS::Handle aValue) override; protected: virtual ~PromiseNativeThenHandlerBase() = default; virtual already_AddRefed CallResolveCallback( JSContext* aCx, JS::Handle aValue) = 0; virtual void Traverse(nsCycleCollectionTraversalCallback&) = 0; virtual void Unlink() = 0; RefPtr mPromise; }; namespace { template ::Type>::value, bool = (IsConvertible::value || IsConvertible::value)> struct StorageTypeHelper { using Type = T; }; template struct StorageTypeHelper { using Type = nsCOMPtr; }; template struct StorageTypeHelper, true, true> { using Type = nsCOMPtr; }; template struct StorageTypeHelper { using Type = RefPtr; }; template