Skip to content

Commit

Permalink
Create new host operation for hosts to specify the assertions they su…
Browse files Browse the repository at this point in the history
…pport. Only supported assertions are provided to the host.
  • Loading branch information
dandclark committed Nov 10, 2020
1 parent f5877ab commit 7949cc8
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ <h1>Runtime Semantics: Evaluation</h1>
1. <ins>Let _arg_ be ? GetValue(_argRef_).</ins>
1. <ins>If _arg_ is *undefined*, let _assertions_ be an empty List.</ins>
1. <ins>Otherwise,</ins>
1. <ins>Let _supportedAssertions_ ! HostGetSupportedAssertions().</ins>
1. <ins>Let _assertionsObj_ be ? Get(_arg_, *"assert"*).</ins>
1. <ins>Let _assertions_ be a new empty List.</ins>
1. <ins>Let _keys_ be EnumerableOwnPropertyNames(_assertionsObj_, ~key~).</ins>
1. <ins>IfAbruptRejectPromise(_keys_, _promiseCapability_).</ins>
1. <ins>For each String _key_ of _keys_,</ins>
1. <ins>For each String _key_ of _keys_, if _key_ is an entry of _supportedAssertions_,</ins>
1. <ins>Let _value_ be Get(_assertionsObj_, _key_).</ins>
1. <ins>IfAbruptRejectPromise(_value_, _promiseCapability_).</ins>
1. <ins>Append { [[Key]]: _key_, [[Value]]: _value_ } to _assertions_.</ins>
Expand Down Expand Up @@ -215,6 +216,28 @@ <h1>Runtime Semantics: FinishDynamicImport ( _referencingScriptOrModule_, <del>_
</emu-alg>
</emu-clause>

<emu-clause id="sec-hostgetsupportedassertions" aoid="HostGetSupportedAssertions">
<h1>Static Semantics: HostGetSupportedAssertions ()</h1>
<p>
HostGetSupportedAssertions is a host-defined abstract operation that allows host environments to specify which import assertions they support.
Only assertions with supported keys will be provided to the host.
</p>

<p>The implementation of HostGetSupportedAssertions must conform to the following requrements:</p>

<ul>
<li>It must return a List whose values are all StringValues, each indicating a supported assertion.</li>

<li>Each time this operation is called, it must return the same List instance with the same contents.</li>

<li>An implementation of HostGetSupportedAssertions must always complete normally (i.e., not return an abrupt completion).</li>
</ul>

<p>The default implementation of HostGetSupportedAssertions is to return an empty List.</p>

<emu-note type=editor>The purpose of requiring the host to specify its supported assertions, rather than passing all assertions to the host and letting it then choose which ones it wants to handle, is to ensure that unsupported assertions are handled in a consistent way across different hosts.</emu-note>
</emu-clause>

<emu-clause id="sec-assert-clause-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>AssertClause : `assert` `{` AssertEntries `,`? `}`</emu-grammar>
Expand All @@ -239,15 +262,23 @@ <h1>Static Semantics: AssertClauseToAssertions</h1>

<emu-grammar> AssertEntries : AssertionKey `:` StringLiteral </emu-grammar>
<emu-alg>
1. Let _entry_ be a Record { [[Key]]: AssertClauseToAssertions of |AssertionKey|, [[Value]]: StringValue of |StringLiteral| }.
1. Return a new List containing the single element, _entry_.
1. Let _supportedAssertions_ be !HostGetSupportedAssertions().
1. Let _key_ be StringValue of |AssertionKey|.
1. If _key_ is an entry of _supportedAssertions_,
1. Let _entry_ be a Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
1. Return a new List containing the single element, _entry_.
1. Otherwise, return a new empty List.
</emu-alg>

<emu-grammar> AssertEntries : AssertionKey `:` StringLiteral `,` AssertEntries </emu-grammar>
<emu-alg>
1. Let _entry_ be a Record { [[Key]]: StringValue of |AssertionKey|, [[Value]]: StringValue of |StringLiteral| }.
1. Let _rest_ be AssertClauseToAssertions of |AssertEntries|.
1. Return a new List containing _entry_ followed by the entries of _rest_.
1. Let _supportedAssertions_ be !HostGetSupportedAssertions().
1. Let _key_ be StringValue of |AssertionKey|.
1. If _key_ is an entry of _supportedAssertions_,
1. Let _entry_ be a Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
1. Let _rest_ be AssertClauseToAssertions of |AssertEntries|.
1. Return a new List containing _entry_ followed by the entries of _rest_.
1. Otherwise, return AssertClauseToAssertions of |AssertEntries|.
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit 7949cc8

Please sign in to comment.