tor-browser

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

PromiseUtils.cpp (1124B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=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 "mozilla/dom/quota/PromiseUtils.h"
      8 
      9 #include "MainThreadUtils.h"
     10 #include "jsapi.h"
     11 #include "mozilla/Assertions.h"
     12 #include "mozilla/ErrorResult.h"
     13 #include "mozilla/RefPtr.h"
     14 #include "mozilla/dom/Promise.h"
     15 #include "nsDebug.h"
     16 #include "xpcpublic.h"
     17 
     18 namespace mozilla::dom::quota {
     19 
     20 nsresult CreatePromise(JSContext* aContext, Promise** aPromise) {
     21  MOZ_ASSERT(NS_IsMainThread());
     22  MOZ_ASSERT(aContext);
     23 
     24  nsIGlobalObject* global =
     25      xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext));
     26  if (NS_WARN_IF(!global)) {
     27    return NS_ERROR_FAILURE;
     28  }
     29 
     30  ErrorResult result;
     31  RefPtr<Promise> promise = Promise::Create(global, result);
     32  if (result.Failed()) {
     33    return result.StealNSResult();
     34  }
     35 
     36  promise.forget(aPromise);
     37  return NS_OK;
     38 }
     39 
     40 }  // namespace mozilla::dom::quota