mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1888878 - Extract CreatePromise to PromiseUtils.h; r=dom-storage-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D206230
This commit is contained in:
parent
e284e670c3
commit
984836f827
@ -25,6 +25,7 @@
|
||||
#include "mozilla/dom/PBackgroundLSSharedTypes.h"
|
||||
#include "mozilla/dom/PBackgroundLSSimpleRequest.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/quota/PromiseUtils.h"
|
||||
#include "mozilla/dom/quota/QuotaManager.h"
|
||||
#include "mozilla/ipc/BackgroundChild.h"
|
||||
#include "mozilla/ipc/BackgroundUtils.h"
|
||||
@ -154,26 +155,6 @@ class SimpleRequestResolver final : public LSSimpleRequestChildCallback {
|
||||
void OnResponse(const LSSimpleRequestResponse& aResponse) override;
|
||||
};
|
||||
|
||||
nsresult CreatePromise(JSContext* aContext, Promise** aPromise) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aContext);
|
||||
|
||||
nsIGlobalObject* global =
|
||||
xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext));
|
||||
if (NS_WARN_IF(!global)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ErrorResult result;
|
||||
RefPtr<Promise> promise = Promise::Create(global, result);
|
||||
if (result.Failed()) {
|
||||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
promise.forget(aPromise);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult CheckedPrincipalToPrincipalInfo(
|
||||
nsIPrincipal* aPrincipal, mozilla::ipc::PrincipalInfo& aPrincipalInfo) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
@ -320,7 +301,7 @@ LocalStorageManager2::Preload(nsIPrincipal* aPrincipal, JSContext* aContext,
|
||||
RefPtr<Promise> promise;
|
||||
|
||||
if (aContext) {
|
||||
rv = CreatePromise(aContext, getter_AddRefs(promise));
|
||||
rv = quota::CreatePromise(aContext, getter_AddRefs(promise));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -364,7 +345,7 @@ LocalStorageManager2::IsPreloaded(nsIPrincipal* aPrincipal, JSContext* aContext,
|
||||
MOZ_ASSERT(_retval);
|
||||
|
||||
RefPtr<Promise> promise;
|
||||
nsresult rv = CreatePromise(aContext, getter_AddRefs(promise));
|
||||
nsresult rv = quota::CreatePromise(aContext, getter_AddRefs(promise));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -395,7 +376,7 @@ LocalStorageManager2::GetState(nsIPrincipal* aPrincipal, JSContext* aContext,
|
||||
MOZ_ASSERT(_retval);
|
||||
|
||||
RefPtr<Promise> promise;
|
||||
nsresult rv = CreatePromise(aContext, getter_AddRefs(promise));
|
||||
nsresult rv = quota::CreatePromise(aContext, getter_AddRefs(promise));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
40
dom/quota/PromiseUtils.cpp
Normal file
40
dom/quota/PromiseUtils.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=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/. */
|
||||
|
||||
#include "mozilla/dom/quota/PromiseUtils.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "MainThreadUtils.h"
|
||||
#include "nsDebug.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
|
||||
namespace mozilla::dom::quota {
|
||||
|
||||
nsresult CreatePromise(JSContext* aContext, Promise** aPromise) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aContext);
|
||||
|
||||
nsIGlobalObject* global =
|
||||
xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext));
|
||||
if (NS_WARN_IF(!global)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ErrorResult result;
|
||||
RefPtr<Promise> promise = Promise::Create(global, result);
|
||||
if (result.Failed()) {
|
||||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
promise.forget(aPromise);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom::quota
|
25
dom/quota/PromiseUtils.h
Normal file
25
dom/quota/PromiseUtils.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* -*- 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 DOM_QUOTA_PROMISEUTILS_H_
|
||||
#define DOM_QUOTA_PROMISEUTILS_H_
|
||||
|
||||
#include "ErrorList.h"
|
||||
#include "jstypes.h"
|
||||
|
||||
struct JS_PUBLIC_API JSContext;
|
||||
|
||||
namespace mozilla::dom {
|
||||
class Promise;
|
||||
}
|
||||
|
||||
namespace mozilla::dom::quota {
|
||||
|
||||
nsresult CreatePromise(JSContext* aContext, Promise** aPromise);
|
||||
|
||||
} // namespace mozilla::dom::quota
|
||||
|
||||
#endif // DOM_QUOTA_PROMISEUTILS_H_
|
@ -60,6 +60,7 @@ EXPORTS.mozilla.dom.quota += [
|
||||
"NSSCipherStrategy.h",
|
||||
"OriginScope.h",
|
||||
"PersistenceType.h",
|
||||
"PromiseUtils.h",
|
||||
"QuotaCommon.h",
|
||||
"QuotaManager.h",
|
||||
"QuotaManagerImpl.h",
|
||||
@ -108,6 +109,7 @@ UNIFIED_SOURCES += [
|
||||
"OriginOperations.cpp",
|
||||
"OriginParser.cpp",
|
||||
"PersistenceType.cpp",
|
||||
"PromiseUtils.cpp",
|
||||
"QMResult.cpp",
|
||||
"QuotaCommon.cpp",
|
||||
"QuotaManagerService.cpp",
|
||||
|
Loading…
Reference in New Issue
Block a user