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/. */
7 #include "mozilla/dom/quota/PromiseUtils.h"
10 #include "MainThreadUtils.h"
12 #include "xpcpublic.h"
13 #include "mozilla/Assertions.h"
14 #include "mozilla/ErrorResult.h"
15 #include "mozilla/RefPtr.h"
16 #include "mozilla/dom/Promise.h"
18 namespace mozilla::dom::quota
{
20 nsresult
CreatePromise(JSContext
* aContext
, Promise
** aPromise
) {
21 MOZ_ASSERT(NS_IsMainThread());
24 nsIGlobalObject
* global
=
25 xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext
));
26 if (NS_WARN_IF(!global
)) {
27 return NS_ERROR_FAILURE
;
31 RefPtr
<Promise
> promise
= Promise::Create(global
, result
);
32 if (result
.Failed()) {
33 return result
.StealNSResult();
36 promise
.forget(aPromise
);
40 } // namespace mozilla::dom::quota