From 8bbc136cb394c9f30e3b446faba977f7e6afe6ca Mon Sep 17 00:00:00 2001 From: Kenneth Christiansen Date: Fri, 30 Nov 2018 17:09:33 +0000 Subject: [PATCH] Replace cancelPush with AbortSignal --- index.html | 412 ++++++++++++++++++++++++++--------------------------- 1 file changed, 205 insertions(+), 207 deletions(-) diff --git a/index.html b/index.html index 5672e66..d5af366 100644 --- a/index.html +++ b/index.html @@ -1438,7 +1438,7 @@

The NFCRecordType enum

The NFC object provides a way for the browsing context to use NFC functionality. It allows for pushing Web NFC messages to NFC tags - or NFC peers within range, and to set up and cancel NFC watches + or NFC peers within range, and to set up and abort NFC watches to handle incoming Web NFC messages either from an NFC tag or an NFC peer.
@@ -1447,7 +1447,6 @@ 

The NFCRecordType enum

[SecureContext] interface NFC { Promise<void> push(NFCPushMessage message, optional NFCPushOptions options); - Promise<void> cancelPush(optional NFCPushTarget target="any"); Promise<long> watch(MessageCallback callback, optional NFCWatchOptions options); }; @@ -1561,12 +1560,20 @@

The NFCRecordType enum

Set nfc@[[\suspended]] to true.
  • - Run the nfc.cancelPush() - steps with "tag" as parameter. -
  • -
  • - Run the nfc.cancelPush() - steps with "peer" as parameter. + For each pending NFC.push: +
      +
    1. + Stop the instance's timer if it is active. +
    2. +
    3. + If the instance has already initiated NFC data transfer, + continue. +
    4. +
    5. + Reject p with an "AbortError" DOMException + and abort these steps. +
    6. +
  • Stop the dispatch NFC content steps. @@ -1593,6 +1600,7 @@

    The NFCRecordType enum

    NFCPushTarget target = "any"; unrestricted double timeout = Infinity; boolean ignoreRead = true; + AbortSignal? signal; };
  • @@ -1615,6 +1623,10 @@

    The NFCRecordType enum

    will skip invoking the receiving and parsing steps for an NFC tag.

    +

    + The NFCPushOptions.signal property allows to abort + the push. +

    @@ -1694,7 +1706,7 @@

    The NFCPushTarget enum

    Web NFC content or any NFC content will be watched.

    - The NFCWatchOptions.signal property allows to abort / cancel + The NFCWatchOptions.signal property allows to abort the watch.

    @@ -1755,200 +1767,228 @@

    The NFCWatchMode enum

    At any time there is at maximum of two Web NFC messages that can be set for pushing for an origin: one targeted to NFC tags and one to NFC peers, until - the current message is sent, or a timeout happens, or the push is - canceled by the - cancelPush() method. + the current message is sent, a timeout happens, or the push is + aborted.

    The push() method

    The - NFC.push(message, options) - method, when invoked, MUST run the + NFC.push method, when invoked, MUST run the push a message algorithm:

    1. - Return a new Promise promise, and - then continue running this algorithm in parallel. -
    2. -
    3. - If any exception occurs while running these steps, reject - promise with that exception and abort these steps. -
    4. -
    5. - An implementation MAY reject promise with - "NotSupportedError" and abort these steps. -
      - The UA might terminate message push at this point. The reasons - for terminations are implementation details. For example, the user - could have has set a preference to allow a given origin only to - read, write, or push data to peers. Also, the implementation might - be unable to support the operation requested. -
      -
    6. -
    7. - Let target be options.target. -
    8. -
    9. - Let timeout be options.timeout. + Let p be a new Promise object.
    10. - If the message parameter is not of type defined by - the NFCPushMessage union, reject promise - with "TypeError", and abort these steps. + Let message be the first argument.
    11. - If the message parameter is of - NFCMessage type, and message.records is an - empty sequence, reject promise with - "TypeError" and abort these steps. + Let options be the second callback.
    12. - If timeout value is NaN or negative, reject - promise with "TypeError" and abort - these steps. + Let signal be the options’ dictionary member of the same + name if present, or null otherwise.
    13. - If timeout value is not supported by the UA, reject - promise with "NotSupportedError" and - abort these steps. + If signal’s aborted flag is set, then reject p + with an "AbortError" DOMException and return p.
    14. - Let output be the notation for the NDEF message - to be created by UA, as the result of passing - message to create Web NFC message. - If this throws an exception, reject promise with that - exception and abort these steps. + If signal is not null, then + + add the following abort steps to signal: +
        +
      1. + Stop the instance's timer if it is active. +
      2. +
      3. + If the instance has already initiated NFC data transfer, + reject p with + "NoModificationAllowedError" and abort these + steps. +
      4. +
      5. + Reject p with an "AbortError" DOMException + and abort these steps. +
      6. +
    15. - If target is "any", run the following - steps twice, once with slot set to the value - "tag", and once set to the value "peer"; - otherwise run the following step once, with - slot set to the value of target. -
    16. -
        -
      • - If there are any existing instance of this algorithm running whose - target is equal to slot, abort that - instance of this algorithm by rejecting its promise - with "AbortError". -

        - In other words, the current invocation of push() - rejects and replaces existing running invocations handling the - same slot. At any given moment there may be - maximum two instances of this algorithm running: one targeting - NFC tags, and another targeting NFC peers. -

        -

        - Implementations are expected to clean up state on aborting these - steps, e.g. stop the related timer, clear the related push - message, as well as release any resources bound to NFC - functionality, so that new invocations of this algorithm do not - depend on previous invocations. -

        -
      • -
      • - Associate output with slot. -
      • -
      -
    17. - If timeout value is not equal to Infinity, - start a timer timer with the timeout value set to - timeout. -
    18. -
    19. - Wait until one of the following events happens: -
        + Run the following steps in parallel: +
          +
        1. + An implementation MAY reject p with + "NotSupportedError" and abort these steps. +
          + The UA might terminate message push at this point. The reasons + for terminations are implementation details. For example, the user + could have has set a preference to allow a given origin only to + read, write, or push data to peers. Also, the implementation might + be unable to support the operation requested. +
          +
        2. +
        3. + Let target be options.target. +
        4. +
        5. + Let timeout be options.timeout. +
        6. +
        7. + If the message parameter is not of type defined by + the NFCPushMessage union, reject p + with "TypeError", and abort these steps. +
        8. - If timer expires, reject promise with - "TimeoutError" and abort these steps. + If the message parameter is of + NFCMessage type, and message.records is an + empty sequence, reject p with + "TypeError" and abort these steps.
        9. - If the cancelPush() - method is called while timer is active with - target or "any", then reject - promise with "AbortError" and - abort these steps, as described in the - cancelPush() steps. + If timeout value is NaN or negative, reject + p with "TypeError" and abort + these steps.
        10. - If an NFC device device comes within - communication range, verify the following conditions: + If timeout value is not supported by the UA, reject + p with "NotSupportedError" and + abort these steps. +
        11. +
        12. + Let output be the notation for the NDEF message + to be created by UA, as the result of passing + message to create Web NFC message. + If this throws an exception, reject p with that + exception and abort these steps. +
        13. +
        14. + If target is "any", run the following + steps twice, once with slot set to the value + "tag", and once set to the value "peer"; + otherwise run the following step once, with + slot set to the value of target. +
        15. +
            +
          • + If there are any existing instance of this algorithm running whose + target is equal to slot, abort that + instance of this algorithm by rejecting its p + with "AbortError". +

            + In other words, the current invocation of push() + rejects and replaces existing running invocations handling the + same slot. At any given moment there may be + maximum two instances of this algorithm running: one targeting + NFC tags, and another targeting NFC peers. +

            +

            + Implementations are expected to clean up state on aborting these + steps, e.g. stop the related timer, clear the related push + message, as well as release any resources bound to NFC + functionality, so that new invocations of this algorithm do not + depend on previous invocations. +

            +
          • +
          • + Associate output with slot. +
          • +
          +
        16. + If timeout value is not equal to Infinity, + start a timer timer with the timeout value set to + timeout. +
        17. +
        18. + Wait until one of the following events happens:
          • - if device is an NFC tag, target - is "tag" or "any" + Promise p is rejected for a reason such as being + aborted by the user. In that case, abort these steps.
          • - if device is an NFC peer, - target is "peer" or - "any" + If timer expires, reject p with + "TimeoutError" and abort these steps.
          • - this@[[\suspended]] is false. -
          • -
          - In case of success, run the following sub-steps: -
            -
          1. - Stop timer if active. -
          2. -
          3. - If device is an NFC tag, + If an NFC device device comes within + communication range, verify the following conditions: + In case of success, run the following sub-steps: +
              +
            1. + Stop timer if active. +
            2. +
            3. + If device is an NFC tag, + +
            4. +
            5. + Initiate data transfer to device using + output as buffer, using the NFC adapter + in communication range with (connected to) + device. +
            6. +
            7. + If the transfer fails, reject p with + "NetworkError" and abort these + steps. +

              + Multiple adapters should be used sequentially by users. + There is very small likelihood that a simultaneous tap + will happen on two or multiple different and connected + NFC adapters. + If it happens, the user will likely need to repeat the + taps until success, preferably one device at a time. + The error here gives an indication that the operation + needs to be repeated. Otherwise the user may think the + operation succeeded on all connected NFC adapters. +

              +
            8. +
            9. + When the transfer has completed, clear output + associated with target, resolve + p. +
            10. +
          4. -
          5. - Initiate data transfer to device using - output as buffer, using the NFC adapter - in communication range with (connected to) - device. -
          6. -
          7. - If the transfer fails, reject promise with - "NetworkError" and abort these - steps. -

            - Multiple adapters should be used sequentially by users. - There is very small likelihood that a simultaneous tap - will happen on two or multiple different and connected - NFC adapters. - If it happens, the user will likely need to repeat the - taps until success, preferably one device at a time. - The error here gives an indication that the operation - needs to be repeated. Otherwise the user may think the - operation succeeded on all connected NFC adapters. -

            -
          8. -
          9. - When the transfer has completed, clear output - associated with target, resolve - promise. -
          10. -
          +
    20. -

      - If this@[[\suspended]] is true, - continue waiting until timer expires (if set), or - until cancelPush() is called, or until - an NFC device comes within communication range. -

      - +
    +

    + If this@[[\suspended]] is true, + continue waiting until timer expires (if set), or + promise is aborted by the user, or until an NFC device + comes within communication range. +

    @@ -2426,48 +2466,6 @@

    The NFCWatchMode enum

    -

    The cancelPush() method

    -

    - The - NFC.cancelPush(target) - method, when invoked, MUST run cancel push algorithm: -

    -
      -
    1. - Return a new Promise promise and - then continue running this algorithm in parallel. -
    2. -
    3. - If there is an instance of the NFC.push() - algorithm running with its options.target equal to - target or "any", then -
        -
      1. - Stop the instance's timer if it is active. -
      2. -
      3. - If the instance has already initiated NFC data transfer, - reject promise with - "NoModificationAllowedError" and abort these - steps. -
      4. -
      5. - Reject the instance's pending promise with - "AbortError" and abort the steps of the - instance. -
      6. -
      -
    4. - Resolve promise. -
    5. - -
    -

    - The cancelPush() method does not interrupt ongoing - transfers, it only cancels pushing before an NFC device - comes in range. -

    -

    Watching for content