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
|
||||
#define mozilla_dom_IdentityNetworkHelpers_h
|
||||
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/Promise-inl.h"
|
||||
#include "mozilla/dom/Request.h"
|
||||
#include "mozilla/dom/Response.h"
|
||||
#include "mozilla/dom/WindowGlobalParent.h"
|
||||
|
|
@ -39,8 +41,9 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
|||
}
|
||||
|
||||
// Handle the response
|
||||
RefPtr<DomPromiseListener> listener = new DomPromiseListener(
|
||||
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue) {
|
||||
fetchPromise->AddCallbacksWithCycleCollectedArgs(
|
||||
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||
ErrorResult&) {
|
||||
// Get the Response object from the argument to the callback
|
||||
if (NS_WARN_IF(!aValue.isObject())) {
|
||||
resultPromise->Reject(NS_ERROR_FAILURE, __func__);
|
||||
|
|
@ -70,8 +73,9 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
|||
}
|
||||
|
||||
// Handle the parsed JSON from the Response body
|
||||
RefPtr<DomPromiseListener> jsonListener = new DomPromiseListener(
|
||||
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue) {
|
||||
jsonPromise->AddCallbacksWithCycleCollectedArgs(
|
||||
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||
ErrorResult&) {
|
||||
// Parse the JSON into the correct type, validating fields and
|
||||
// types
|
||||
T result;
|
||||
|
|
@ -83,13 +87,18 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
|||
|
||||
resultPromise->Resolve(result, __func__);
|
||||
},
|
||||
[resultPromise](nsresult aRv) {
|
||||
resultPromise->Reject(aRv, __func__);
|
||||
[resultPromise](JSContext*, JS::Handle<JS::Value> aValue,
|
||||
ErrorResult&) {
|
||||
resultPromise->Reject(
|
||||
Promise::TryExtractNSResultFromRejectionValue(aValue),
|
||||
__func__);
|
||||
});
|
||||
jsonPromise->AppendNativeHandler(jsonListener);
|
||||
},
|
||||
[resultPromise](nsresult aRv) { resultPromise->Reject(aRv, __func__); });
|
||||
fetchPromise->AppendNativeHandler(listener);
|
||||
[resultPromise](JSContext*, JS::Handle<JS::Value> aValue, ErrorResult&) {
|
||||
resultPromise->Reject(
|
||||
Promise::TryExtractNSResultFromRejectionValue(aValue), __func__);
|
||||
});
|
||||
|
||||
return resultPromise;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue