tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DetailedPromise.cpp (2037B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 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 #include "DetailedPromise.h"
      8 
      9 #include "VideoUtils.h"
     10 #include "mozilla/dom/DOMException.h"
     11 #include "nsPrintfCString.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 DetailedPromise::DetailedPromise(nsIGlobalObject* aGlobal,
     16                                 const nsACString& aName)
     17    : Promise(aGlobal), mName(aName), mStartTime(TimeStamp::Now()) {}
     18 
     19 DetailedPromise::~DetailedPromise() {
     20  // It would be nice to assert that mResponded is identical to
     21  // GetPromiseState() == PromiseState::Rejected.  But by now we've been
     22  // unlinked, so don't have a reference to our actual JS Promise object
     23  // anymore.
     24 }
     25 
     26 void DetailedPromise::LogRejectionReason(uint32_t aErrorCode,
     27                                         const nsACString& aReason) {
     28  nsPrintfCString msg("%s promise rejected 0x%" PRIx32 " '%s'", mName.get(),
     29                      aErrorCode, PromiseFlatCString(aReason).get());
     30  EME_LOG("%s", msg.get());
     31 
     32  LogToBrowserConsole(NS_ConvertUTF8toUTF16(msg));
     33 }
     34 
     35 void DetailedPromise::MaybeReject(nsresult aArg, const nsACString& aReason) {
     36  LogRejectionReason(static_cast<uint32_t>(aArg), aReason);
     37 
     38  Promise::MaybeRejectWithDOMException(aArg, aReason);
     39 }
     40 
     41 void DetailedPromise::MaybeReject(ErrorResult&& aArg,
     42                                  const nsACString& aReason) {
     43  LogRejectionReason(aArg.ErrorCodeAsInt(), aReason);
     44  Promise::MaybeReject(std::move(aArg));
     45 }
     46 
     47 /* static */
     48 already_AddRefed<DetailedPromise> DetailedPromise::Create(
     49    nsIGlobalObject* aGlobal, ErrorResult& aRv, const nsACString& aName) {
     50  RefPtr<DetailedPromise> promise = new DetailedPromise(aGlobal, aName);
     51  promise->CreateWrapper(aRv);
     52  return aRv.Failed() ? nullptr : promise.forget();
     53 }
     54 
     55 }  // namespace mozilla::dom