Bug 1633344 - Throw RangeError when creating PaymentRequest with a duplicate payment method. r=alchen

Differential Revision: https://phabricator.services.mozilla.com/D74686
This commit is contained in:
Eden Chuang
2020-05-19 13:17:13 +00:00
parent 6500778960
commit 0031cac8e0

View File

@@ -305,6 +305,7 @@ void PaymentRequest::IsValidMethodData(
return;
}
nsTArray<nsString> methods;
for (const PaymentMethodData& methodData : aMethodData) {
IsValidPaymentMethodIdentifier(methodData.mSupportedMethods, aRv);
if (aRv.Failed()) {
@@ -325,6 +326,13 @@ void PaymentRequest::IsValidMethodData(
return;
}
}
if (!methods.Contains(methodData.mSupportedMethods)) {
methods.AppendElement(methodData.mSupportedMethods);
} else {
aRv.ThrowRangeError(nsPrintfCString(
"Duplicate payment method '%s'",
NS_ConvertUTF16toUTF8(methodData.mSupportedMethods).get()));
}
}
}