<html>
    <head>
      <base href="https://bugs.webkit.org/">
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ESNext] Async iteration - Implement Async Generator"
   href="https://bugs.webkit.org/show_bug.cgi?id=166695#c53">Comment # 53</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ESNext] Async iteration - Implement Async Generator"
   href="https://bugs.webkit.org/show_bug.cgi?id=166695">bug 166695</a>
              from <span class="vcard"><a class="email" href="mailto:caitp&#64;igalia.com" title="Caitlin Potter (:caitp) &lt;caitp&#64;igalia.com&gt;"> <span class="fn">Caitlin Potter (:caitp)</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=305500&amp;action=diff" name="attach_305500" title="Patch">attachment 305500</a> <a href="attachment.cgi?id=305500&amp;action=edit" title="Patch">[details]</a></span>
Patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=305500&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=305500&amp;action=review</a>

<span class="quote">&gt;&gt;&gt; Source/JavaScriptCore/builtins/AsyncGeneratorPrototype.js:123
&gt;&gt;&gt; +                                        generator.&#64;generatorState = &#64;AsyncGeneratorStateCompleted;
&gt;&gt; 
&gt;&gt; This actually looks wrong to me, per the current spec. Unless the committee decides to go with the &quot;yielded rejections don't affect control flow of the generator&quot; thing (which is admittedly pretty popular), closing the generator should be left up to &#64;asyncGeneratorResume().
&gt;&gt; 
&gt;&gt; Even if the proposal is changed, this will prevent finally blocks from being reached.
&gt;&gt; 
&gt;&gt; E.g.
&gt;&gt; 
&gt;&gt; ```js
&gt;&gt; let reject;
&gt;&gt; async function* foo() {
&gt;&gt;   try {
&gt;&gt;     yield new Promise(function(unused, rej) { reject = rej; });
&gt;&gt;   } finally {
&gt;&gt;     doImportantCleanupStuff(); // In this patch, this appears to be unreachable
&gt;&gt;     return 0;
&gt;&gt;   }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; foo().next().then(x =&gt; print(x), e =&gt; print(e));
&gt;&gt; reject(&quot;Oop!&quot;);
&gt;&gt; ```
&gt;&gt; 
&gt;&gt; I could be wrong about this, but I _believe_ this is broken in this patch due to the generator state change here, and I think it is supposed to work in the current spec
&gt; 
&gt; I see following result:
&gt; 
&gt;   do important staff
&gt;   returned value
&gt;   Oop!
&gt; 
&gt; Is this result close to spec or 'important staff' should be returned after Oop!
&gt; To test I used little bit modified function:
&gt; ```
&gt; async function* foo() {
&gt;   try {
&gt;     yield new Promise(function(unused, rej) { reject = rej; });
&gt;   } finally {
&gt;     print('do important staff');
&gt;     return 'returned value';
&gt;   }
&gt; }
&gt; 
&gt; var f= foo()
&gt; f.next().then(({value}) =&gt; print(value), e =&gt; print(e));
&gt; reject(&quot;Oop!&quot;);
&gt; f.next().then(({value}) =&gt; print(value), e =&gt; print(e));
&gt; drainMicrotasks();
&gt; ```</span >

In #jslang I made a gist and spent some time analyzing it, didn't get through the whole thing, but I pretty much get the same result, so I think it's okay. <a href="https://gist.github.com/caitp/9af4de75c5ac6ff7d22b366472617e21">https://gist.github.com/caitp/9af4de75c5ac6ff7d22b366472617e21</a>

And yeah, the finally block would be reached if another request is queued up, regardless of whether the rejection affects control flow or not. But it still shouldn't close the generator, that doesn't really make sense.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>