Skip to content

Commit a8a2961

Browse files
authored
Only preserve AC for user generators (tc39#70)
* Only preserve AC for user generators * Fix GeneratorResumeAbrupt
1 parent 7b3bfb4 commit a8a2961

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

spec.html

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ <h1>Properties of Generator Instances</h1>
432432
<ins>[[GeneratorAsyncContextMapping]]</ins>
433433
</td>
434434
<td>
435-
<ins>a List of Async Context Mapping Records</ins>
435+
<ins>a List of Async Context Mapping Records or ~empty~</ins>
436436
</td>
437437
<td>
438438
<ins>The value of the agent's [[AsyncContextMapping]] to use the next time this generator is resumed.</ins>
@@ -491,7 +491,10 @@ <h1>
491491
1. Return CreateIterResultObject(_resultValue_, *true*).
492492
1. Set the code evaluation state of _genContext_ such that when evaluation is resumed for that execution context, _closure_ will be called with no arguments.
493493
1. Set _generator_.[[GeneratorContext]] to _genContext_.
494-
1. <ins>Set _generator_.[[GeneratorAsyncContextMapping]] to AsyncContextSnapshot().</ins>
494+
1. <ins>If _generatorBody_ is a |FunctionBody| Parse Node, then</ins>
495+
1. <ins>Set _generator_.[[GeneratorAsyncContextMapping]] to AsyncContextSnapshot().</ins>
496+
1. <ins>Else,</ins>
497+
1. <ins>Set _generator_.[[GeneratorAsyncContextMapping]] to ~empty~.</ins>
495498
1. Set _generator_.[[GeneratorState]] to ~suspendedStart~.
496499
1. Return ~unused~.
497500
</emu-alg>
@@ -536,12 +539,16 @@ <h1>
536539
1. Let _methodContext_ be the running execution context.
537540
1. Suspend _methodContext_.
538541
1. Set _generator_.[[GeneratorState]] to ~executing~.
539-
1. <ins>Let _asyncContextMapping_ be AsyncContextSwap(_generator_.[[GeneratorAsyncContextMapping]]).</ins>
542+
1. <ins>If _generator_.[[GeneratorAsyncContextMapping]] is ~empty~, then</ins>
543+
1. <ins>Let _previousContextMapping_ be ~empty~.</ins>
544+
1. <ins>Else,</ins>
545+
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(_generator_.[[GeneratorAsyncContextMapping]]).</ins>
540546
1. Push _genContext_ onto the execution context stack; _genContext_ is now the running execution context.
541547
1. <emu-meta effects="user-code">Resume the suspended evaluation of _genContext_</emu-meta> using NormalCompletion(_value_) as the result of the operation that suspended it. Let _result_ be the value returned by the resumed computation.
542548
1. Assert: When we return here, _genContext_ has already been removed from the execution context stack and _methodContext_ is the currently running execution context.
543-
1. <ins>Assert: The result of AsyncContextSnapshot() is _generator_.[[GeneratorAsyncContextMapping]].</ins>
544-
1. <ins>AsyncContextSwap(_asyncContextMapping_).</ins>
549+
1. <ins>If _previousContextMapping_ is not ~empty~, then</ins>
550+
1. <ins>Assert: The result of AsyncContextSnapshot() is _generator_.[[GeneratorAsyncContextMapping]].</ins>
551+
1. <ins>AsyncContextSwap(_previousContextMapping_).</ins>
545552
1. Return ? _result_.
546553
</emu-alg>
547554
</emu-clause>
@@ -571,12 +578,16 @@ <h1>
571578
1. Let _methodContext_ be the running execution context.
572579
1. Suspend _methodContext_.
573580
1. Set _generator_.[[GeneratorState]] to ~executing~.
574-
1. <ins>Let _asyncContextMapping_ be AsyncContextSwap(_generator_.[[GeneratorAsyncContextMapping]]).</ins>
581+
1. <ins>If _generator_.[[GeneratorAsyncContextMapping]] is ~empty~, then</ins>
582+
1. <ins>Let _previousContextMapping_ be ~empty~.</ins>
583+
1. <ins>Else,</ins>
584+
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(_generator_.[[GeneratorAsyncContextMapping]]).</ins>
575585
1. Push _genContext_ onto the execution context stack; _genContext_ is now the running execution context.
576586
1. <emu-meta effects="user-code">Resume the suspended evaluation of _genContext_</emu-meta> using _abruptCompletion_ as the result of the operation that suspended it. Let _result_ be the Completion Record returned by the resumed computation.
577587
1. Assert: When we return here, _genContext_ has already been removed from the execution context stack and _methodContext_ is the currently running execution context.
578-
1. <ins>Assert: The result of AsyncContextSnapshot() is _generator_.[[GeneratorAsyncContextMapping]].</ins>
579-
1. <ins>AsyncContextSwap(_asyncContextMapping_).</ins>
588+
1. <ins>If _previousContextMapping_ is not ~empty~, then</ins>
589+
1. <ins>Assert: The result of AsyncContextSnapshot() is _generator_.[[GeneratorAsyncContextMapping]].</ins>
590+
1. <ins>AsyncContextSwap(_previousContextMapping_).</ins>
580591
1. Return ? _result_.
581592
</emu-alg>
582593
</emu-clause>
@@ -642,7 +653,7 @@ <h1>Properties of AsyncGenerator Instances</h1>
642653
</tr>
643654
<tr>
644655
<td><ins>[[AsyncGeneratorAsyncContextMapping]]</ins></td>
645-
<td><ins>a List of Async Context Mapping Records</ins></td>
656+
<td><ins>a List of Async Context Mapping Records or ~empty~</ins></td>
646657
<td><ins>The value of the agent's [[AsyncContextMapping]] to use the next time this generator is resumed.</ins></td>
647658
</tr>
648659
<tr>
@@ -690,7 +701,10 @@ <h1>
690701
1. Set _generator_.[[AsyncGeneratorContext]] to _genContext_.
691702
1. Set _generator_.[[AsyncGeneratorState]] to ~suspendedStart~.
692703
1. Set _generator_.[[AsyncGeneratorQueue]] to a new empty List.
693-
1. <ins>Set _generator_.[[AsyncGeneratorAsyncContextMapping]] to AsyncContextSnapshot().</ins>
704+
1. <ins>If _generatorBody_ is a |FunctionBody| Parse Node, then</ins>
705+
1. <ins>Set _generator_.[[AsyncGeneratorAsyncContextMapping]] to AsyncContextSnapshot().</ins>
706+
1. <ins>Else,</ins>
707+
1. <ins>Set _generator_.[[AsyncGeneratorAsyncContextMapping]] to ~empty~.</ins>
694708
1. Return ~unused~.
695709
</emu-alg>
696710
</emu-clause>
@@ -729,13 +743,17 @@ <h1>
729743
1. Let _callerContext_ be the running execution context.
730744
1. Suspend _callerContext_.
731745
1. Set _generator_.[[AsyncGeneratorState]] to ~executing~.
732-
1. <ins>Let _asyncContextMapping_ be AsyncContextSwap(_generator_.[[AsyncGeneratorAsyncContextMapping]]).</ins>
746+
1. <ins>If _generator_.[[AsyncGeneratorAsyncContextMapping]] is ~empty~, then</ins>
747+
1. <ins>Let _previousContextMapping_ be ~empty~.</ins>
748+
1. <ins>Else,</ins>
749+
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(_generator_.[[AsyncGeneratorAsyncContextMapping]]).</ins>
733750
1. Push _genContext_ onto the execution context stack; _genContext_ is now the running execution context.
734751
1. <emu-meta effects="user-code">Resume the suspended evaluation of _genContext_</emu-meta> using _completion_ as the result of the operation that suspended it. Let _result_ be the Completion Record returned by the resumed computation.
735752
1. Assert: _result_ is never an abrupt completion.
736753
1. Assert: When we return here, _genContext_ has already been removed from the execution context stack and _callerContext_ is the currently running execution context.
737-
1. <ins>Assert: The result of AsyncContextSnapshot() is _generator_.[[AsyncGeneratorAsyncContextMapping]].</ins>
738-
1. <ins>AsyncContextSwap(_asyncContextMapping_).</ins>
754+
1. <ins>If _previousContextMapping_ is not ~empty~, then</ins>
755+
1. <ins>Assert: The result of AsyncContextSnapshot() is _generator_.[[AsyncGeneratorAsyncContextMapping]].</ins>
756+
1. <ins>AsyncContextSwap(_previousContextMapping_).</ins>
739757
1. Return ~unused~.
740758
</emu-alg>
741759
</emu-clause>

0 commit comments

Comments
 (0)