forked from mirrors/gecko-dev
Bug 1842007 - Part 6: Replace DomPromiseLIstener use with Promise method in IdentityNetworkHelpers r=bvandersloot
No behavior change, just prefers newer method. Differential Revision: https://phabricator.services.mozilla.com/D183025
This commit is contained in:
parent
10c1bbe82a
commit
9663b1918b
1 changed files with 18 additions and 9 deletions
|
|
@ -7,6 +7,8 @@
|
||||||
#ifndef mozilla_dom_IdentityNetworkHelpers_h
|
#ifndef mozilla_dom_IdentityNetworkHelpers_h
|
||||||
#define mozilla_dom_IdentityNetworkHelpers_h
|
#define mozilla_dom_IdentityNetworkHelpers_h
|
||||||
|
|
||||||
|
#include "mozilla/dom/Promise.h"
|
||||||
|
#include "mozilla/dom/Promise-inl.h"
|
||||||
#include "mozilla/dom/Request.h"
|
#include "mozilla/dom/Request.h"
|
||||||
#include "mozilla/dom/Response.h"
|
#include "mozilla/dom/Response.h"
|
||||||
#include "mozilla/dom/WindowGlobalParent.h"
|
#include "mozilla/dom/WindowGlobalParent.h"
|
||||||
|
|
@ -39,8 +41,9 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the response
|
// Handle the response
|
||||||
RefPtr<DomPromiseListener> listener = new DomPromiseListener(
|
fetchPromise->AddCallbacksWithCycleCollectedArgs(
|
||||||
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue) {
|
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||||
|
ErrorResult&) {
|
||||||
// Get the Response object from the argument to the callback
|
// Get the Response object from the argument to the callback
|
||||||
if (NS_WARN_IF(!aValue.isObject())) {
|
if (NS_WARN_IF(!aValue.isObject())) {
|
||||||
resultPromise->Reject(NS_ERROR_FAILURE, __func__);
|
resultPromise->Reject(NS_ERROR_FAILURE, __func__);
|
||||||
|
|
@ -70,8 +73,9 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the parsed JSON from the Response body
|
// Handle the parsed JSON from the Response body
|
||||||
RefPtr<DomPromiseListener> jsonListener = new DomPromiseListener(
|
jsonPromise->AddCallbacksWithCycleCollectedArgs(
|
||||||
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue) {
|
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||||
|
ErrorResult&) {
|
||||||
// Parse the JSON into the correct type, validating fields and
|
// Parse the JSON into the correct type, validating fields and
|
||||||
// types
|
// types
|
||||||
T result;
|
T result;
|
||||||
|
|
@ -83,13 +87,18 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
||||||
|
|
||||||
resultPromise->Resolve(result, __func__);
|
resultPromise->Resolve(result, __func__);
|
||||||
},
|
},
|
||||||
[resultPromise](nsresult aRv) {
|
[resultPromise](JSContext*, JS::Handle<JS::Value> aValue,
|
||||||
resultPromise->Reject(aRv, __func__);
|
ErrorResult&) {
|
||||||
|
resultPromise->Reject(
|
||||||
|
Promise::TryExtractNSResultFromRejectionValue(aValue),
|
||||||
|
__func__);
|
||||||
});
|
});
|
||||||
jsonPromise->AppendNativeHandler(jsonListener);
|
|
||||||
},
|
},
|
||||||
[resultPromise](nsresult aRv) { resultPromise->Reject(aRv, __func__); });
|
[resultPromise](JSContext*, JS::Handle<JS::Value> aValue, ErrorResult&) {
|
||||||
fetchPromise->AppendNativeHandler(listener);
|
resultPromise->Reject(
|
||||||
|
Promise::TryExtractNSResultFromRejectionValue(aValue), __func__);
|
||||||
|
});
|
||||||
|
|
||||||
return resultPromise;
|
return resultPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue