From 5d16c564ba3634a2887736396234983a3dc12cf4 Mon Sep 17 00:00:00 2001 From: Matt Reynolds Date: Fri, 26 Apr 2024 17:01:18 -0700 Subject: [PATCH 1/2] Add sequenceId slot and fix effect promises --- index.html | 110 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index 8ca6304..3d789c4 100644 --- a/index.html +++ b/index.html @@ -1122,6 +1122,19 @@

playing. + + + [[\sequenceId]] + + + 0 + + + An {{unsigned long}} incremented for each call to + {{GamepadHapticActuator/playEffect}} or + {{GamepadHapticActuator/reset}}. + +
@@ -1165,6 +1178,8 @@

`"hidden"`, return [=a promise rejected with=] an "{{InvalidStateError}}" {{DOMException}}. +
  • Increment [=this=].{{GamepadHapticActuator/[[sequenceId]]}}. +
  • If [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} is not `null`:
      @@ -1185,8 +1200,11 @@

      type=] |type|, return [=a promise rejected with=] reason {{NotSupportedError}}. -
    1. Let {{GamepadHapticActuator/[[playingEffectPromise]]}} be [=a - new promise=]. +
    2. Let [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + be [=a new promise=]. +
    3. +
    4. Let |effectSequenceId:unsigned long| be + [=this=].{{GamepadHapticActuator/[[sequenceId]]}}.
    5. Let |playEffectTimestamp:DOMHighResTimestamp| be the [=current high resolution time=] given the |document|'s [=relevant global @@ -1197,29 +1215,29 @@

    6. [=Issue a haptic effect=] to the actuator with |type|, |params|, and the |playEffectTimestamp|.
    7. -
    8. When the effect completes, if - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} is - not `null`, [=queue a global task=] on the [=relevant global - object=] of [=this=] using the [=gamepad task source=] to run - the following steps: +
    9. When the effect completes, [=queue a global task=] on the + [=relevant global object=] of [=this=] using the [=gamepad task + source=] to run the following steps:
        -
      1. If - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - is `null`, abort these steps. -
      2. -
      3. [=Resolve=] - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - with {{GamepadHapticsResult/"complete"}}. -
      4. -
      5. Set - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - to `null`. +
      6. If [=this=].{{GamepadHapticActuator/[[sequenceId]]}} is + |effectSequenceId|: +
          +
        1. [=Resolve=] + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + with {{GamepadHapticsResult/"complete"}}. +
        2. +
        3. Set + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + to `null`. +
        4. +
  • -
  • Return {{GamepadHapticActuator/[[playingEffectPromise]]}}. +
  • Return + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}}.
  • @@ -1239,37 +1257,57 @@

    `"hidden"`, return [=a promise rejected with=] an "{{InvalidStateError}}" {{DOMException}}. -
  • Let |resetResultPromise:Promise| be [=a new promise=]. +
  • Increment [=this=].{{GamepadHapticActuator/[[sequenceId]]}}.
  • If [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - is not `null`, do the following steps [=in parallel=]: + is not `null`:
    1. Let |effectPromise| be [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}}.
    2. +
    3. Set + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} to + `null`. +
    4. +
    5. [=Queue a global task=] on the [=relevant global object=] + of [=this=] using the [=gamepad task source=] to [=resolve=] + |effectPromise| with {{GamepadHapticsResult/"preempted"}}. +
    6. +
    +
  • +
  • Let [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + be [=a new promise=]. +
  • +
  • Let |resetSequenceId:unsigned long| be + [=this=].{{GamepadHapticActuator/[[sequenceId]]}}. +
  • +
  • Do the following steps [=in parallel=]: +
    1. [=Stop haptic effects=] on [=this=]'s gamepad's actuator.
    2. -
    3. If the effect has been successfully stopped, do: +
    4. If the effect has been successfully stopped, [=queue a + global task=] on the [=relevant global object=] of [=this=] + using the [=gamepad task source=] to run the following steps:
        -
      1. If |effectPromise| and - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - are still the same, set - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - to `null`. -
      2. -
      3. [=Queue a global task=] on the [=relevant global - object=] of [=this=] using the [=gamepad task source=] to - [=resolve=] |effectPromise| with - {{GamepadHapticsResult/"preempted"}}. +
      4. If [=this=].{{GamepadHapticActuator/[[sequenceId]]}} is + |resetSequenceId|: +
          +
        1. [=Resolve=] + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + with {{GamepadHapticsResult/"complete"}}. +
        2. +
        3. Set + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + to `null`. +
        4. +
    5. -
    6. [=Resolve=] |resetResultPromise| with - {{GamepadHapticsResult/"complete"}} -
  • -
  • Return |resetResultPromise|. +
  • Return + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}}.
  • From 432bf058169abe4961ac999b88f686cee25e13ff Mon Sep 17 00:00:00 2001 From: Matt Reynolds Date: Fri, 24 May 2024 17:37:48 -0700 Subject: [PATCH 2/2] Early returns and nullness assertions --- index.html | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index 3d789c4..01a916e 100644 --- a/index.html +++ b/index.html @@ -1200,6 +1200,10 @@

    type=] |type|, return [=a promise rejected with=] reason {{NotSupportedError}}. +
  • [=Assert=] + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} is + `null`. +
  • Let [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} be [=a new promise=].
  • @@ -1220,17 +1224,15 @@

    source=] to run the following steps:
    1. If [=this=].{{GamepadHapticActuator/[[sequenceId]]}} is - |effectSequenceId|: -
        -
      1. [=Resolve=] - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - with {{GamepadHapticsResult/"complete"}}. -
      2. -
      3. Set - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - to `null`. -
      4. -
      + not |effectSequenceId|, abort these steps. +
    2. +
    3. [=Resolve=] + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + with {{GamepadHapticsResult/"complete"}}. +
    4. +
    5. Set + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + to `null`.
    @@ -1275,6 +1277,10 @@

    +
  • [=Assert=] + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} is + `null`. +
  • Let [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} be [=a new promise=].
  • @@ -1290,17 +1296,15 @@

    using the [=gamepad task source=] to run the following steps:
    1. If [=this=].{{GamepadHapticActuator/[[sequenceId]]}} is - |resetSequenceId|: -
        -
      1. [=Resolve=] - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - with {{GamepadHapticsResult/"complete"}}. -
      2. -
      3. Set - [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} - to `null`. -
      4. -
      + not |resetSequenceId|, abort these steps. +
    2. +
    3. [=Resolve=] + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + with {{GamepadHapticsResult/"complete"}}. +
    4. +
    5. Set + [=this=].{{GamepadHapticActuator/[[playingEffectPromise]]}} + to `null`.