From 9663b1918b910dfbecedda11fbad1930bc4ba23f Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Thu, 13 Jul 2023 12:43:41 +0000 Subject: [PATCH] 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 --- .../identity/IdentityNetworkHelpers.h | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/dom/credentialmanagement/identity/IdentityNetworkHelpers.h b/dom/credentialmanagement/identity/IdentityNetworkHelpers.h index a580e678c541..9691c73b0602 100644 --- a/dom/credentialmanagement/identity/IdentityNetworkHelpers.h +++ b/dom/credentialmanagement/identity/IdentityNetworkHelpers.h @@ -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 FetchJSONStructure(Request* aRequest) { } // Handle the response - RefPtr listener = new DomPromiseListener( - [resultPromise](JSContext* aCx, JS::Handle aValue) { + fetchPromise->AddCallbacksWithCycleCollectedArgs( + [resultPromise](JSContext* aCx, JS::Handle 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 FetchJSONStructure(Request* aRequest) { } // Handle the parsed JSON from the Response body - RefPtr jsonListener = new DomPromiseListener( - [resultPromise](JSContext* aCx, JS::Handle aValue) { + jsonPromise->AddCallbacksWithCycleCollectedArgs( + [resultPromise](JSContext* aCx, JS::Handle aValue, + ErrorResult&) { // Parse the JSON into the correct type, validating fields and // types T result; @@ -83,13 +87,18 @@ RefPtr FetchJSONStructure(Request* aRequest) { resultPromise->Resolve(result, __func__); }, - [resultPromise](nsresult aRv) { - resultPromise->Reject(aRv, __func__); + [resultPromise](JSContext*, JS::Handle 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 aValue, ErrorResult&) { + resultPromise->Reject( + Promise::TryExtractNSResultFromRejectionValue(aValue), __func__); + }); + return resultPromise; }