Skip to content

Commit

Permalink
Editorial: add PromiseCapability Record assertions (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 15, 2020
1 parent f8e7557 commit cbc8c46
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -24077,7 +24077,7 @@ <h1>Runtime Semantics: HostImportModuleDynamically ( _referencingScriptOrModule_

<emu-clause id="sec-finishdynamicimport" aoid="FinishDynamicImport">
<h1>Runtime Semantics: FinishDynamicImport ( _referencingScriptOrModule_, _specifier_, _promiseCapability_, _completion_ )</h1>
<p>The abstract operation FinishDynamicImport takes arguments _referencingScriptOrModule_, _specifier_, _promiseCapability_, and _completion_. FinishDynamicImport completes the process of a dynamic import originally started by an <emu-xref href="#sec-import-calls">`import()`</emu-xref> call, resolving or rejecting the promise returned by that call as appropriate according to _completion_. It is performed by host environments as part of HostImportModuleDynamically. It performs the following steps when called:</p>
<p>The abstract operation FinishDynamicImport takes arguments _referencingScriptOrModule_, _specifier_, _promiseCapability_ (a PromiseCapability Record), and _completion_. FinishDynamicImport completes the process of a dynamic import originally started by an <emu-xref href="#sec-import-calls">`import()`</emu-xref> call, resolving or rejecting the promise returned by that call as appropriate according to _completion_. It is performed by host environments as part of HostImportModuleDynamically. It performs the following steps when called:</p>

<emu-alg>
1. If _completion_ is an abrupt completion, then perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _completion_.[[Value]] »).
Expand Down Expand Up @@ -38932,7 +38932,7 @@ <h1>Properties of Async-from-Sync Iterator Instances</h1>

<emu-clause id="sec-asyncfromsynciteratorcontinuation" aoid="AsyncFromSyncIteratorContinuation">
<h1>AsyncFromSyncIteratorContinuation ( _result_, _promiseCapability_ )</h1>
<p>The abstract operation AsyncFromSyncIteratorContinuation takes arguments _result_ and _promiseCapability_. It performs the following steps when called:</p>
<p>The abstract operation AsyncFromSyncIteratorContinuation takes arguments _result_ and _promiseCapability_ (a PromiseCapability Record). It performs the following steps when called:</p>

<emu-alg>
1. Let _done_ be IteratorComplete(_result_).
Expand Down Expand Up @@ -39485,7 +39485,7 @@ <h1>AsyncGeneratorRequest Records</h1>
</tr>
<tr>
<td>[[Capability]]</td>
<td>A PromiseCapability record</td>
<td>A PromiseCapability Record</td>
<td>The promise capabilities associated with this request.</td>
</tr>
</tbody>
Expand Down Expand Up @@ -39528,6 +39528,7 @@ <h1>AsyncGeneratorResolve ( _generator_, _value_, _done_ )</h1>
1. Assert: _queue_ is not an empty List.
1. Remove the first element from _queue_ and let _next_ be the value of that element.
1. Let _promiseCapability_ be _next_.[[Capability]].
1. Assert: _promiseCapability_ is a PromiseCapability Record.
1. Let _iteratorResult_ be ! CreateIterResultObject(_value_, _done_).
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _iteratorResult_ &raquo;).
1. Perform ! AsyncGeneratorResumeNext(_generator_).
Expand All @@ -39544,6 +39545,7 @@ <h1>AsyncGeneratorReject ( _generator_, _exception_ )</h1>
1. Assert: _queue_ is not an empty List.
1. Remove the first element from _queue_ and let _next_ be the value of that element.
1. Let _promiseCapability_ be _next_.[[Capability]].
1. Assert: _promiseCapability_ is a PromiseCapability Record.
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _exception_ &raquo;).
1. Perform ! AsyncGeneratorResumeNext(_generator_).
1. Return *undefined*.
Expand Down Expand Up @@ -39695,7 +39697,7 @@ <h1>Promise Abstract Operations</h1>
<h1>PromiseCapability Records</h1>
<p>A PromiseCapability is a Record value used to encapsulate a promise object along with the functions that are capable of resolving or rejecting that promise object. PromiseCapability Records are produced by the NewPromiseCapability abstract operation.</p>
<p>PromiseCapability Records have the fields listed in <emu-xref href="#table-57"></emu-xref>.</p>
<emu-table id="table-57" caption="PromiseCapability Record Fields">
<emu-table id="table-57" caption="<dfn>PromiseCapability Record</dfn> Fields">
<table>
<tbody>
<tr>
Expand Down Expand Up @@ -39900,7 +39902,7 @@ <h1>NewPromiseCapability ( _C_ )</h1>
<emu-alg>
1. If IsConstructor(_C_) is *false*, throw a *TypeError* exception.
1. NOTE: _C_ is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see <emu-xref href="#sec-promise-executor"></emu-xref>).
1. Let _promiseCapability_ be the PromiseCapability { [[Promise]]: *undefined*, [[Resolve]]: *undefined*, [[Reject]]: *undefined* }.
1. Let _promiseCapability_ be the PromiseCapability Record { [[Promise]]: *undefined*, [[Resolve]]: *undefined*, [[Reject]]: *undefined* }.
1. Let _steps_ be the algorithm steps defined in <emu-xref href="#sec-getcapabilitiesexecutor-functions" title></emu-xref>.
1. Let _executor_ be ! CreateBuiltinFunction(_steps_, &laquo; [[Capability]] &raquo;).
1. Set _executor_.[[Capability]] to _promiseCapability_.
Expand Down Expand Up @@ -40012,6 +40014,7 @@ <h1>NewPromiseReactionJob ( _reaction_, _argument_ )</h1>
1. If _promiseCapability_ is *undefined*, then
1. Assert: _handlerResult_ is not an abrupt completion.
1. Return NormalCompletion(~empty~).
1. Assert: _promiseCapability_ is a PromiseCapability Record.
1. If _handlerResult_ is an abrupt completion, then
1. Let _status_ be Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _handlerResult_.[[Value]] &raquo;).
1. Else,
Expand Down Expand Up @@ -40126,10 +40129,9 @@ <h1>Runtime Semantics: GetPromiseResolve ( _promiseConstructor_ )</h1>

<emu-clause id="sec-performpromiseall" aoid="PerformPromiseAll">
<h1>Runtime Semantics: PerformPromiseAll ( _iteratorRecord_, _constructor_, _resultCapability_, _promiseResolve_ )</h1>
<p>The abstract operation PerformPromiseAll takes arguments _iteratorRecord_, _constructor_, _resultCapability_, and _promiseResolve_. It performs the following steps when called:</p>
<p>The abstract operation PerformPromiseAll takes arguments _iteratorRecord_, _constructor_, _resultCapability_ (a PromiseCapability Record), and _promiseResolve_. It performs the following steps when called:</p>
<emu-alg>
1. Assert: IsConstructor(_constructor_) is *true*.
1. Assert: _resultCapability_ is a PromiseCapability Record.
1. Assert: IsCallable(_promiseResolve_) is *true*.
1. Let _values_ be a new empty List.
1. Let _remainingElementsCount_ be the Record { [[Value]]: 1 }.
Expand Down Expand Up @@ -40175,6 +40177,7 @@ <h1>`Promise.all` Resolve Element Functions</h1>
1. Let _index_ be _F_.[[Index]].
1. Let _values_ be _F_.[[Values]].
1. Let _promiseCapability_ be _F_.[[Capability]].
1. Assert: _promiseCapability_ is a PromiseCapability Record.
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]].
1. Set _values_[_index_] to _x_.
1. Set _remainingElementsCount_.[[Value]] to _remainingElementsCount_.[[Value]] - 1.
Expand Down Expand Up @@ -40209,10 +40212,9 @@ <h1>Promise.allSettled ( _iterable_ )</h1>

<emu-clause id="sec-performpromiseallsettled" aoid="PerformPromiseAllSettled">
<h1>Runtime Semantics: PerformPromiseAllSettled ( _iteratorRecord_, _constructor_, _resultCapability_, _promiseResolve_ )</h1>
<p>The abstract operation PerformPromiseAllSettled takes arguments _iteratorRecord_, _constructor_, _resultCapability_, and _promiseResolve_. It performs the following steps when called:</p>
<p>The abstract operation PerformPromiseAllSettled takes arguments _iteratorRecord_, _constructor_, _resultCapability_ (a PromiseCapability Record), and _promiseResolve_. It performs the following steps when called:</p>
<emu-alg>
1. Assert: ! IsConstructor(_constructor_) is *true*.
1. Assert: _resultCapability_ is a PromiseCapability Record.
1. Assert: IsCallable(_promiseResolve_) is *true*.
1. Let _values_ be a new empty List.
1. Let _remainingElementsCount_ be the Record { [[Value]]: 1 }.
Expand Down Expand Up @@ -40266,6 +40268,7 @@ <h1>`Promise.allSettled` Resolve Element Functions</h1>
1. Let _index_ be _F_.[[Index]].
1. Let _values_ be _F_.[[Values]].
1. Let _promiseCapability_ be _F_.[[Capability]].
1. Assert: _promiseCapability_ is a PromiseCapability Record.
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]].
1. Let _obj_ be ! OrdinaryObjectCreate(%Object.prototype%).
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"status"*, *"fulfilled"*).
Expand All @@ -40292,6 +40295,7 @@ <h1>`Promise.allSettled` Reject Element Functions</h1>
1. Let _index_ be _F_.[[Index]].
1. Let _values_ be _F_.[[Values]].
1. Let _promiseCapability_ be _F_.[[Capability]].
1. Assert: _promiseCapability_ is a PromiseCapability Record.
1. Let _remainingElementsCount_ be _F_.[[RemainingElements]].
1. Let _obj_ be ! OrdinaryObjectCreate(%Object.prototype%).
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"status"*, *"rejected"*).
Expand Down Expand Up @@ -40338,10 +40342,9 @@ <h1>Promise.race ( _iterable_ )</h1>

<emu-clause id="sec-performpromiserace" aoid="PerformPromiseRace">
<h1>Runtime Semantics: PerformPromiseRace ( _iteratorRecord_, _constructor_, _resultCapability_, _promiseResolve_ )</h1>
<p>The abstract operation PerformPromiseRace takes arguments _iteratorRecord_, _constructor_, _resultCapability_, and _promiseResolve_. It performs the following steps when called:</p>
<p>The abstract operation PerformPromiseRace takes arguments _iteratorRecord_, _constructor_, _resultCapability_ (a PromiseCapability Record), and _promiseResolve_. It performs the following steps when called:</p>
<emu-alg>
1. Assert: IsConstructor(_constructor_) is *true*.
1. Assert: _resultCapability_ is a PromiseCapability Record.
1. Assert: IsCallable(_promiseResolve_) is *true*.
1. Repeat,
1. Let _next_ be IteratorStep(_iteratorRecord_).
Expand Down Expand Up @@ -40513,13 +40516,9 @@ <h1>Promise.prototype.then ( _onFulfilled_, _onRejected_ )</h1>

<emu-clause id="sec-performpromisethen" aoid="PerformPromiseThen">
<h1>PerformPromiseThen ( _promise_, _onFulfilled_, _onRejected_ [ , _resultCapability_ ] )</h1>
<p>The abstract operation PerformPromiseThen takes arguments _promise_, _onFulfilled_, and _onRejected_ and optional argument _resultCapability_. It performs the &ldquo;then&rdquo; operation on _promise_ using _onFulfilled_ and _onRejected_ as its settlement actions. If _resultCapability_ is passed, the result is stored by updating _resultCapability_'s promise. If it is not passed, then PerformPromiseThen is being called by a specification-internal operation where the result does not matter. It performs the following steps when called:</p>
<p>The abstract operation PerformPromiseThen takes arguments _promise_, _onFulfilled_, and _onRejected_ and optional argument _resultCapability_ (a PromiseCapability Record). It performs the &ldquo;then&rdquo; operation on _promise_ using _onFulfilled_ and _onRejected_ as its settlement actions. If _resultCapability_ is passed, the result is stored by updating _resultCapability_'s promise. If it is not passed, then PerformPromiseThen is being called by a specification-internal operation where the result does not matter. It performs the following steps when called:</p>
<emu-alg>
1. Assert: IsPromise(_promise_) is *true*.
1. If _resultCapability_ is present, then
1. Assert: _resultCapability_ is a PromiseCapability Record.
1. Else,
1. Set _resultCapability_ to *undefined*.
1. If IsCallable(_onFulfilled_) is *false*, then
1. Set _onFulfilled_ to *undefined*.
1. If IsCallable(_onRejected_) is *false*, then
Expand Down Expand Up @@ -40716,7 +40715,7 @@ <h1>Async Functions Abstract Operations</h1>

<emu-clause id="sec-async-functions-abstract-operations-async-function-start" aoid="AsyncFunctionStart">
<h1>AsyncFunctionStart ( _promiseCapability_, _asyncFunctionBody_ )</h1>
<p>The abstract operation AsyncFunctionStart takes arguments _promiseCapability_ and _asyncFunctionBody_. It performs the following steps when called:</p>
<p>The abstract operation AsyncFunctionStart takes arguments _promiseCapability_ (a PromiseCapability Record) and _asyncFunctionBody_. It performs the following steps when called:</p>
<emu-alg>
1. Let _runningContext_ be the running execution context.
1. Let _asyncContext_ be a copy of _runningContext_.
Expand Down

0 comments on commit cbc8c46

Please sign in to comment.