Skip to content

Commit 61c13d4

Browse files
committed
Create new host operation for hosts to specify the assertions they support. Only supported assertions are provided to the host.
1 parent 4d81b2e commit 61c13d4

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

spec.html

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ <h1>Runtime Semantics: Evaluation</h1>
9090
1. <ins>Let _arg_ be ? GetValue(_argRef_).</ins>
9191
1. <ins>If _arg_ is *undefined*, let _assertions_ be an empty List.</ins>
9292
1. <ins>Otherwise,</ins>
93+
1. <ins>Let _supportedAssertions_ ! HostGetSupportedAssertions().</ins>
9394
1. <ins>Let _assertionsObj_ be ? Get(_arg_, *"assert"*).</ins>
9495
1. <ins>Let _assertions_ be a new empty List.</ins>
9596
1. <ins>Let _keys_ be EnumerableOwnPropertyNames(_assertionsObj_, ~key~).</ins>
9697
1. <ins>IfAbruptRejectPromise(_keys_, _promiseCapability_).</ins>
97-
1. <ins>For each String _key_ of _keys_,</ins>
98+
1. <ins>For each String _key_ of _keys_, if _key_ is an entry of _supportedAssertions_,</ins>
9899
1. <ins>Let _value_ be Get(_assertionsObj_, _key_).</ins>
99100
1. <ins>IfAbruptRejectPromise(_value_, _promiseCapability_).</ins>
100101
1. <ins>Append { [[Key]]: _key_, [[Value]]: _value_ } to _assertions_.</ins>
@@ -215,6 +216,28 @@ <h1>Runtime Semantics: FinishDynamicImport ( _referencingScriptOrModule_, <del>_
215216
</emu-alg>
216217
</emu-clause>
217218

219+
<emu-clause id="sec-hostgetsupportedassertions" aoid="HostGetSupportedAssertions">
220+
<h1>Static Semantics: HostGetSupportedAssertions ()</h1>
221+
<p>
222+
HostGetSupportedAssertions is a host-defined abstract operation that allows host environments to specify which import assertions they support.
223+
Only assertions with supported keys will be provided to the host.
224+
</p>
225+
226+
<p>The implementation of HostGetSupportedAssertions must conform to the following requrements:</p>
227+
228+
<ul>
229+
<li>It must return a List whose values are all StringValues, each indicating a supported assertion.</li>
230+
231+
<li>Each time this operation is called, it must return the same List instance with the same contents.</li>
232+
233+
<li>An implementation of HostGetSupportedAssertions must always complete normally (i.e., not return an abrupt completion).</li>
234+
</ul>
235+
236+
<p>The default implementation of HostGetSupportedAssertions is to return an empty List.</p>
237+
238+
<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>
239+
</emu-clause>
240+
218241
<emu-clause id="sec-assert-clause-early-errors">
219242
<h1>Static Semantics: Early Errors</h1>
220243
<emu-grammar>AssertClause : `assert` `{` AssertEntries `,`? `}`</emu-grammar>
@@ -239,15 +262,23 @@ <h1>Static Semantics: AssertClauseToAssertions</h1>
239262

240263
<emu-grammar> AssertEntries : AssertionKey `:` StringLiteral </emu-grammar>
241264
<emu-alg>
242-
1. Let _entry_ be a Record { [[Key]]: StringValue of |AssertionKey|, [[Value]]: StringValue of |StringLiteral| }.
243-
1. Return a new List containing the single element, _entry_.
265+
1. Let _supportedAssertions_ be !HostGetSupportedAssertions().
266+
1. Let _key_ be StringValue of |AssertionKey|.
267+
1. If _key_ is an entry of _supportedAssertions_,
268+
1. Let _entry_ be a Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
269+
1. Return a new List containing the single element, _entry_.
270+
1. Otherwise, return a new empty List.
244271
</emu-alg>
245272

246273
<emu-grammar> AssertEntries : AssertionKey `:` StringLiteral `,` AssertEntries </emu-grammar>
247274
<emu-alg>
248-
1. Let _entry_ be a Record { [[Key]]: StringValue of |AssertionKey|, [[Value]]: StringValue of |StringLiteral| }.
249-
1. Let _rest_ be AssertClauseToAssertions of |AssertEntries|.
250-
1. Return a new List containing _entry_ followed by the entries of _rest_.
275+
1. Let _supportedAssertions_ be !HostGetSupportedAssertions().
276+
1. Let _key_ be StringValue of |AssertionKey|.
277+
1. If _key_ is an entry of _supportedAssertions_,
278+
1. Let _entry_ be a Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
279+
1. Let _rest_ be AssertClauseToAssertions of |AssertEntries|.
280+
1. Return a new List containing _entry_ followed by the entries of _rest_.
281+
1. Otherwise, return AssertClauseToAssertions of |AssertEntries|.
251282
</emu-alg>
252283
</emu-clause>
253284

0 commit comments

Comments
 (0)