Bug 1913377 - Comment and assert that `allowedScope` has a very limited set of values...
[gecko.git] / dom / quota / PromiseUtils.cpp
blobbf3cb92b0b783554741d6341b0930555901fea62
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"
9 #include "jsapi.h"
10 #include "MainThreadUtils.h"
11 #include "nsDebug.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());
22 MOZ_ASSERT(aContext);
24 nsIGlobalObject* global =
25 xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext));
26 if (NS_WARN_IF(!global)) {
27 return NS_ERROR_FAILURE;
30 ErrorResult result;
31 RefPtr<Promise> promise = Promise::Create(global, result);
32 if (result.Failed()) {
33 return result.StealNSResult();
36 promise.forget(aPromise);
37 return NS_OK;
40 } // namespace mozilla::dom::quota