[Payment Request] Updates PaymentRequestUpdateEvent.updateWith function
Updates the updateWith function to accept an instance of
window.PaymentDetails as well as a promise that fulfills with one:
https://w3c.github.io/browser-payment-api/#paymentrequestupdateevent-interface
BUG=602666
Review-Url: https://codereview.chromium.org/2850723003
Cr-Original-Commit-Position: refs/heads/master@{#467985}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 5b56f229932277a95f08420e0d2031656d66e471
diff --git a/chrome/browser/web/resources/payment_request.js b/chrome/browser/web/resources/payment_request.js
index e31b819..2a2cd2b 100644
--- a/chrome/browser/web/resources/payment_request.js
+++ b/chrome/browser/web/resources/payment_request.js
@@ -230,20 +230,21 @@
/**
* Handles invocation of updateWith() on the updateEvent object. Updates the
- * payment details when the |updateWithPromise| is resolved. Throws an error
- * if |updateWithPromise| is not a valid instance of Promise or if it fulfills
- * with an invalid instance of window.PaymentDetails.
- * @param {?Promise<?window.PaymentDetails|undefined>|undefined}
- * updateWithPromise
+ * payment details. Throws an error if |detailsOrPromise| is not a valid
+ * instance of window.PaymentDetails or it is a promise that does not fulfill
+ * with a valid one.
+ * @param {!Promise<!window.PaymentDetails>|!window.PaymentDetails}
+ * detailsOrPromise
*/
- __gCrWeb['paymentRequestManager'].updateWith = function(updateWithPromise) {
- // Check to see |updateWithPromise| is an instance of Promise.
- if (!updateWithPromise || !(updateWithPromise.then instanceof Function) ||
- !(updateWithPromise.catch instanceof Function)) {
- throw new TypeError('An instance of Promise must be provided');
+ __gCrWeb['paymentRequestManager'].updateWith = function(detailsOrPromise) {
+ // if |detailsOrPromise| is not an instance of a Promise, wrap it in a
+ // Promise that fulfills with |detailsOrPromise|.
+ if (!detailsOrPromise || !(detailsOrPromise.then instanceof Function) ||
+ !(detailsOrPromise.catch instanceof Function)) {
+ detailsOrPromise = Promise.resolve(detailsOrPromise);
}
- updateWithPromise
+ detailsOrPromise
.then(function(paymentDetails) {
if (!paymentDetails)
throw new TypeError(