Bug 1731763 - Always null-check on ParymentRequest::mAcceptPromise and PaymentResponse::mRetryPromise. r=jstutte

Since PaymentRequest::mAcceptPromise and PaymentResponse::mRetryPromise can be nulled in PaymentRequest::NotifyOwnerDocumentActivityChanged(), always null-check on these promise when calling RespondShowPayment() and RespondRetry().

Differential Revision: https://phabricator.services.mozilla.com/D127110
This commit is contained in:
Eden Chuang 2021-10-05 10:12:46 +00:00
Родитель 3122576765
Коммит 4e9aade4a5
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -790,7 +790,6 @@ void PaymentRequest::RespondShowPayment(const nsAString& aMethodName,
const nsAString& aPayerEmail,
const nsAString& aPayerPhone,
ErrorResult&& aResult) {
MOZ_ASSERT(mAcceptPromise || mResponse);
MOZ_ASSERT(mState == eInteractive);
if (aResult.Failed()) {
@ -805,12 +804,17 @@ void PaymentRequest::RespondShowPayment(const nsAString& aMethodName,
if (mResponse) {
mResponse->RespondRetry(aMethodName, mShippingOption, mShippingAddress,
aDetails, aPayerName, aPayerEmail, aPayerPhone);
} else {
} else if (mAcceptPromise) {
RefPtr<PaymentResponse> paymentResponse = new PaymentResponse(
GetOwner(), this, mId, aMethodName, mShippingOption, mShippingAddress,
aDetails, aPayerName, aPayerEmail, aPayerPhone);
mResponse = paymentResponse;
mAcceptPromise->MaybeResolve(paymentResponse);
} else {
// mAccpetPromise could be nulled through document activity changed. And
// there is nothing to do here.
mState = eClosed;
return;
}
mState = eClosed;

Просмотреть файл

@ -280,6 +280,10 @@ void PaymentResponse::RespondRetry(const nsAString& aMethodName,
const nsAString& aPayerName,
const nsAString& aPayerEmail,
const nsAString& aPayerPhone) {
// mRetryPromise could be nulled when document activity is changed.
if (!mRetryPromise) {
return;
}
mMethodName = aMethodName;
mShippingOption = aShippingOption;
mShippingAddress = aShippingAddress;