mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1843453 - Add MozPromiseRejectOnDestruction r=bvandersloot,xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D183778
This commit is contained in:
parent
55478c757e
commit
1baae48856
@ -808,6 +808,9 @@ IdentityCredential::PromptUserToSelectProvider(
|
||||
resultPromise->Reject(
|
||||
Promise::TryExtractNSResultFromRejectionValue(aValue), __func__);
|
||||
});
|
||||
// Working around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85883
|
||||
showPromptPromise->AppendNativeHandler(
|
||||
new MozPromiseRejectOnDestruction{resultPromise, __func__});
|
||||
|
||||
return resultPromise;
|
||||
}
|
||||
@ -886,6 +889,9 @@ IdentityCredential::PromptUserToSelectAccount(
|
||||
resultPromise->Reject(
|
||||
Promise::TryExtractNSResultFromRejectionValue(aValue), __func__);
|
||||
});
|
||||
// Working around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85883
|
||||
showPromptPromise->AppendNativeHandler(
|
||||
new MozPromiseRejectOnDestruction{resultPromise, __func__});
|
||||
|
||||
return resultPromise;
|
||||
}
|
||||
@ -1007,6 +1013,9 @@ IdentityCredential::PromptUserWithPolicy(
|
||||
Promise::TryExtractNSResultFromRejectionValue(aValue),
|
||||
__func__);
|
||||
});
|
||||
// Working around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85883
|
||||
showPromptPromise->AppendNativeHandler(
|
||||
new MozPromiseRejectOnDestruction{resultPromise, __func__});
|
||||
return resultPromise;
|
||||
},
|
||||
[](nsresult error) {
|
||||
|
@ -40,10 +40,14 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
||||
return resultPromise;
|
||||
}
|
||||
|
||||
// Working around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85883
|
||||
RefPtr<PromiseNativeHandler> reject =
|
||||
new MozPromiseRejectOnDestruction{resultPromise, __func__};
|
||||
|
||||
// Handle the response
|
||||
fetchPromise->AddCallbacksWithCycleCollectedArgs(
|
||||
[resultPromise](JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||
ErrorResult&) {
|
||||
[resultPromise, reject](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__);
|
||||
@ -93,11 +97,13 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
|
||||
Promise::TryExtractNSResultFromRejectionValue(aValue),
|
||||
__func__);
|
||||
});
|
||||
jsonPromise->AppendNativeHandler(reject);
|
||||
},
|
||||
[resultPromise](JSContext*, JS::Handle<JS::Value> aValue, ErrorResult&) {
|
||||
resultPromise->Reject(
|
||||
Promise::TryExtractNSResultFromRejectionValue(aValue), __func__);
|
||||
});
|
||||
fetchPromise->AppendNativeHandler(reject);
|
||||
|
||||
return resultPromise;
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
NS_IMPL_ISUPPORTS0(MozPromiseRejectOnDestructionBase)
|
||||
|
||||
NS_IMPL_ISUPPORTS0(DomPromiseListener)
|
||||
|
||||
DomPromiseListener::DomPromiseListener(CallbackTypeResolved&& aResolve,
|
||||
|
@ -35,6 +35,44 @@ class PromiseNativeHandler : public nsISupports {
|
||||
ErrorResult& aRv) = 0;
|
||||
};
|
||||
|
||||
// This base class exists solely to use NS_IMPL_ISUPPORTS because it doesn't
|
||||
// support template classes.
|
||||
class MozPromiseRejectOnDestructionBase : public PromiseNativeHandler {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||
ErrorResult& aRv) override {}
|
||||
void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||
ErrorResult& aRv) override {}
|
||||
|
||||
protected:
|
||||
~MozPromiseRejectOnDestructionBase() override = default;
|
||||
};
|
||||
|
||||
// Use this when you subscribe to a JS promise to settle a MozPromise that is
|
||||
// not guaranteed to be settled by anyone else.
|
||||
template <typename T>
|
||||
class MozPromiseRejectOnDestruction final
|
||||
: public MozPromiseRejectOnDestructionBase {
|
||||
public:
|
||||
// (Accepting RefPtr<T> instead of T* because compiler fails to implicitly
|
||||
// convert it at call sites)
|
||||
MozPromiseRejectOnDestruction(const RefPtr<T>& aMozPromise,
|
||||
const char* aCallSite)
|
||||
: mMozPromise(aMozPromise), mCallSite(aCallSite) {
|
||||
MOZ_ASSERT(aMozPromise);
|
||||
}
|
||||
|
||||
protected:
|
||||
~MozPromiseRejectOnDestruction() override {
|
||||
// Rejecting will be no-op if the promise is already settled
|
||||
mMozPromise->Reject(NS_BINDING_ABORTED, mCallSite);
|
||||
}
|
||||
|
||||
RefPtr<T> mMozPromise;
|
||||
const char* mCallSite;
|
||||
};
|
||||
|
||||
// This class is used to set C++ callbacks once a dom Promise a resolved or
|
||||
// rejected.
|
||||
class DomPromiseListener final : public PromiseNativeHandler {
|
||||
|
@ -1,7 +1,6 @@
|
||||
[fedcm-csp.https.html]
|
||||
expected:
|
||||
if os == "linux": [CRASH, TIMEOUT]
|
||||
if os == "mac": [TIMEOUT, OK, CRASH]
|
||||
if os == "mac": [TIMEOUT, OK]
|
||||
TIMEOUT
|
||||
[Provider configURL should honor Content-Security-Policy.]
|
||||
expected:
|
||||
|
Loading…
Reference in New Issue
Block a user