From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/promise/Promise-inl.h | 341 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 341 insertions(+) create mode 100644 dom/promise/Promise-inl.h (limited to 'dom/promise/Promise-inl.h') diff --git a/dom/promise/Promise-inl.h b/dom/promise/Promise-inl.h new file mode 100644 index 0000000000..a7a6ebd0fd --- /dev/null +++ b/dom/promise/Promise-inl.h @@ -0,0 +1,341 @@ +/* -*- 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 +#include + +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/ResultExtensions.h" +#include "mozilla/dom/BindingUtils.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/dom/PromiseNativeHandler.h" +#include "nsCycleCollectionParticipant.h" + +namespace mozilla::dom { + +class PromiseNativeThenHandlerBase : public PromiseNativeHandler { + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PromiseNativeThenHandlerBase) + + PromiseNativeThenHandlerBase(Promise* aPromise) : mPromise(aPromise) {} + + virtual bool HasResolvedCallback() = 0; + virtual bool HasRejectedCallback() = 0; + + MOZ_CAN_RUN_SCRIPT void ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override; + + MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override; + + protected: + virtual ~PromiseNativeThenHandlerBase() = default; + + MOZ_CAN_RUN_SCRIPT virtual already_AddRefed CallResolveCallback( + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) = 0; + MOZ_CAN_RUN_SCRIPT virtual already_AddRefed CallRejectCallback( + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) = 0; + + virtual void Traverse(nsCycleCollectionTraversalCallback&) = 0; + virtual void Unlink() = 0; + virtual void Trace(const TraceCallbacks& aCallbacks, void* aClosure) = 0; + + RefPtr mPromise; +}; + +namespace { + +template >::value, + bool = (std::is_convertible_v || + std::is_convertible_v)> +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 +struct StorageTypeHelper, false, false> { + using Type = JS::Heap; +}; + +template