From 27eab1742e3383296c01b37407579fcf4a0e1382 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Thu, 9 Feb 2017 17:12:52 -0500 Subject: [PATCH 1/2] Make updateWith() return a promise signaling any update failures This closes #350. It is a slightly backward-incompatible change in that consumers which were previously try-catching errors will no longer see them. But consumers that were always passing valid data, or passing invalid data and not try-catching the errors, will see no changes. --- index.html | 151 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 119 insertions(+), 32 deletions(-) diff --git a/index.html b/index.html index 86d35389..e24838bd 100644 --- a/index.html +++ b/index.html @@ -1818,7 +1818,7 @@

           [Constructor(DOMString type, optional PaymentRequestUpdateEventInit eventInitDict),SecureContext]
           interface PaymentRequestUpdateEvent : Event {
-            void updateWith(Promise<PaymentDetails> detailsPromise);
+            Promise<void> updateWith(Promise<PaymentDetails> detailsPromise);
           };
         

@@ -1831,6 +1831,15 @@

a PaymentDetails dictionary containing changed values that the user agent SHOULD present to the user.

+

+ The promise returned by updateWith() will be fulfilled with + undefined if all of the data is accepted, or rejected with a + TypeError if the update was complete but some data was + rejected as invalid. It can also be rejected if it is called + inappropriately, e.g. on a PaymentRequestUpdateEvent event + that is not being dispatched or is has already been updated, or if + the passed promise rejects. +

The PaymentRequestUpdateEvent constructor MUST set the internal slot [[\waitForUpdate]] to false. @@ -1850,20 +1859,22 @@

target attribute.
  • If target is not a PaymentRequest object, - then throw a TypeError. + then return a promise rejected with a TypeError.
  • -
  • If the dispatch flag is unset, then throw an - "InvalidStateError" DOMException. +
  • If the dispatch flag is unset, then return a promise + rejected with an "InvalidStateError" DOMException.
  • -
  • If event.[[\waitForUpdate]] is true, then - throw an "InvalidStateError" DOMException. +
  • If event.[[\waitForUpdate]] is true, then + return a promise rejected with an "InvalidStateError" + DOMException.
  • If target.[[\state]] is not - interactive, then throw an "InvalidStateError" - DOMException. + interactive, then return a promise rejected with an + "InvalidStateError" DOMException.
  • -
  • If target.[[\updating]] is true, then - throw an "InvalidStateError" DOMException. +
  • If target.[[\updating]] is true, then return + a promise rejected with an "InvalidStateError" + DOMException.
  • Set event's stop propagation flag and stop immediate propagation flag. @@ -1884,10 +1895,12 @@

    Only one update may be processed at a time.

  • +
  • Let returnedPromise be a new promise. +
  • - Return from the method and perform the remaining steps in - parallel. + Return returnedPromise, and perform the remaining + steps in parallel.

    The remaining steps are conditional on the @@ -1914,6 +1927,9 @@

    target.[[\acceptPromise]] with an "AbortError" DOMException.

  • +
  • Reject returnedPromise with an + "AbortError" DOMException. +
  • If the promise detailsPromise is rejected then this @@ -1934,8 +1950,11 @@

    1. Let details be the result of converting value to a PaymentDetails dictionary. If this - throws an exception, abort these substeps, and - optionally show an error message to the user. + throws an exception, reject returnedPromise + with the exception, abort these substeps, and optionally show + an error message to the user. +
    2. +
    3. Let errorsList be an empty list.
    4. If the total member of details is present, then: @@ -1952,6 +1971,13 @@

      target.[[\details]]. (Negative total amounts are ignored.)

    5. +
    6. Otherwise, add an error message describing the fact + that details.total.amount.value was invalid to + errorsList. +
  • If the displayItems field of target.[[\details]].
  • +
  • Otherwise, add an error message describing the fact + that one of the displayItems had an + invalid amount.value to + errorsList. +
  • If the modifiers @@ -1987,10 +2021,20 @@

    member.total.amount.value is not a - valid decimal monetary value, then set - modifiers to an empty sequence and - serializedModifierData to an empty list, and - jump to the step labeled copy modifiers below. + valid decimal monetary value, then: +
      +
    1. Set modifiers to an empty sequence. +
    2. +
    3. Set serializedModifierData to an + empty list. +
    4. +
    5. Add an error describing the invalid total value + to errorsList. +
    6. +
    7. Jump to the step labeled copy modifiers + below. +
    8. +

  • If the additionalDisplayItems member of modifier is present, then for each @@ -2003,11 +2047,21 @@

    "PaymentCurrencyAmount.value">value.

  • If amountValue is not a valid - decimal monetary value, then set - modifiers to an empty sequence and - serializedModifierData to an empty list, - and jump to the step labeled copy - modifiers below. + decimal monetary value, then: +
      +
    1. Set modifiers to an empty + sequence. +
    2. +
    3. Set serializedModifierData to an + empty list. +
    4. +
    5. Add an error describing the invalid item + value to errorsList. +
    6. +
    7. Jump to the step labeled copy + modifiers below. +
    8. +
  • @@ -2017,11 +2071,22 @@

    if the data member of modifier is present, or null if it is not. - If JSON-serializing throws an exception, then - set modifiers to an empty sequence and - serializedModifierData to an empty list, - and jump to the step labeled copy modifiers - below. + If JSON-serializing throws an exception, then: +
      +
    1. Set modifiers to an empty sequence. +
    2. +
    3. Set serializedModifierData to an + empty list. +
    4. +
    5. Add an error describing the fact that the given + modifier's data was not + JSON-parseable to errorsList. +
    6. +
    7. Jump to the step labeled copy modifiers + below. +
    8. +
  • Add serializedData to serializedModifierData. @@ -2059,13 +2124,29 @@

  • If option.amount.value is not a - valid decimal monetary value, then set - options to the empty sequence and break. + valid decimal monetary value, then: +
      +
    1. Set options to the empty sequence. +
    2. +
    3. Add an error describing the invalid option + value to errorsList. +
    4. +
    5. Break. +
    6. +
  • If seenIDs contains option.id, then set - options to an empty sequence and break. + "PaymentShippingOption.id">id, then: +
      +
    1. Set options to the empty sequence. +
    2. +
    3. Add an error describing the fact that there are + duplicate option IDs to errorsList. +
    4. +
    5. Break. +
    6. +
  • Append option.id to @@ -2096,6 +2177,12 @@

    should update the user interface to display the error message contained in error.

  • +
  • If errorsList is empty, fulfill + returnedPromise with undefined. Otherwise, reject + returnedPromise with a TypeError. User agents + SHOULD use the information from errorsList to + provide the message for the TypeError. +
  • In either case, run the following steps, after either the upon From 3416d776482c3cbed1693f207839f227d91a340d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Mon, 13 Feb 2017 19:31:37 +1100 Subject: [PATCH 2/2] editorial: fix typo --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index e24838bd..7f0503c3 100644 --- a/index.html +++ b/index.html @@ -1837,7 +1837,7 @@

    TypeError if the update was complete but some data was rejected as invalid. It can also be rejected if it is called inappropriately, e.g. on a PaymentRequestUpdateEvent event - that is not being dispatched or is has already been updated, or if + that is not being dispatched or has already been updated, or if the passed promise rejects.