Skip to content

Commit 9a8adf2

Browse files
committed
[WIP] Top-level await integration
The purpose of this patch is to nail down how HTML would adjust to the needs of top-level await. The relevant change is, the module.Evaluate() method will return a Promise that resolves when the module is ready, and this will be passed to FinishDynamicImport to wait on before resolving the Promise it returns. It doesn't seem like anyone else needs to wait for a module script to "finish" evaluating besides dynamic import. This PR is just a sketch, not to be landed. Top-level await should reach stage 3 before this change lands. The PR where Evaluate returns a Promise is guybedford/proposal-top-level-await#1
1 parent 1d6eb99 commit 9a8adf2

File tree

1 file changed

+17
-35
lines changed

1 file changed

+17
-35
lines changed

source

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -87761,12 +87761,9 @@ interface <dfn>ApplicationCache</dfn> : <span>EventTarget</span> {
8776187761

8776287762
<li><p><span>Prepare to run script</span> given <var>settings</var>.</p></li>
8776387763

87764-
<li><p>Let <var>evaluationStatus</var> be null.</p></li>
87765-
8776687764
<li><p>If <var>script</var>'s <span data-x="concept-script-error-to-rethrow">error to
87767-
rethrow</span> is not null, then set <var>evaluationStatus</var> to Completion { [[Type]]: throw,
87768-
[[Value]]: <var>script</var>'s <span data-x="concept-script-error-to-rethrow">error to
87769-
rethrow</span>, [[Target]]: empty }.</p></li>
87765+
rethrow</span> is not null, then let <var>evaluationPromise</var> be a promise rejected with <var>script</var>'s <span data-x="concept-script-error-to-rethrow">error to
87766+
rethrow</span>.</p></li>
8777087767

8777187768
<li>
8777287769
<p>Otherwise:</p>
@@ -87776,35 +87773,26 @@ interface <dfn>ApplicationCache</dfn> : <span>EventTarget</span> {
8777687773
data-x="concept-script-record">record</span>.</p>
8777787774

8777887775
<li>
87779-
<p>Set <var>evaluationStatus</var> to <var>record</var>.<span
87776+
<p>Let <var>evaluationPromise</var> be <var>record</var>.<span
8778087777
data-x="js-Evaluate">Evaluate</span>().</p>
8778187778

8778287779
<p class="note">This step will recursively evaluate all of the module's dependencies.</p>
8778387780

8778487781
<p>If <span data-x="js-Evaluate">Evaluate</span> fails to complete as a result of the user agent
87785-
<span data-x="abort a running script">aborting the running script</span>, then set
87786-
<var>evaluationStatus</var> to Completion { [[Type]]: throw, [[Value]]: a new
87787-
<span>"<code>QuotaExceededError</code>"</span> <code>DOMException</code>, [[Target]]: empty
87788-
}.</p>
87782+
<span data-x="abort a running script">aborting the running script</span>, then let
87783+
<var>evaluationPromise</var> be a promise rejected with a new
87784+
<span>"<code>QuotaExceededError</code>"</span> <code>DOMException</code>.</p>
8778987785
</li>
8779087786
</ol>
8779187787
</li>
8779287788

87793-
<li>
87794-
<p>If <var>evaluationStatus</var> is an <span>abrupt completion</span>, then:</p>
87795-
87796-
<ol>
87797-
<li><p>If <var>rethrow errors</var> is true, rethrow the exception given by
87798-
<var>evaluationStatus</var>.[[Value]].</p></li>
87799-
87800-
<li><p>Otherwise, <span>report the exception</span> given by
87789+
<li><p>If <var>rethrow errors</var> is false, then upon rejection of
87790+
<var>evaluationPromise</var>, <span>report the exception</span> given by
8780187791
<var>evaluationStatus</var>.[[Value]] for <var>script</var>.</p></li>
87802-
</ol>
87803-
</li>
8780487792

8780587793
<li><p><span>Clean up after running script</span> with <var>settings</var>.</p></li>
8780687794

87807-
<li><p>Return <var>evaluationStatus</var>.</p></li>
87795+
<li><p>Return <var>evaluationPromise</var>.</p></li>
8780887796
</ol>
8780987797

8781087798
<p>The steps to <dfn>check if we can run script</dfn> with an <span>environment settings
@@ -88882,11 +88870,10 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8888288870
<p>If <var>url</var> is failure, then:</p>
8888388871

8888488872
<ol>
88885-
<li><p>Let <var>completion</var> be Completion { [[Type]]: throw, [[Value]]: a new
88886-
<code>TypeError</code>, [[Target]]: empty }.</p></li>
88873+
<li><p>Let <var>promise</var> be a promise rejected with a new <code>TypeError</code>.</p></li>
8888788874

8888888875
<li><p>Perform <span>FinishDynamicImport</span>(<var>referencingScriptOrModule</var>,
88889-
<var>specifier</var>, <var>promiseCapability</var>, <var>completion</var>).</p></li>
88876+
<var>specifier</var>, <var>promiseCapability</var>, <var>promise</var>).</p></li>
8889088877

8889188878
<li><p>Return.</p></li>
8889288879
</ol>
@@ -88900,28 +88887,23 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
8890088887
<p>If <var>result</var> is null, then:</p>
8890188888

8890288889
<ol>
88903-
<li><p>Let <var>completion</var> be Completion { [[Type]]: throw, [[Value]]: a new
88904-
<code>TypeError</code>, [[Target]]: empty }.</p></li>
88890+
<li><p>Let <var>promise</var> be a promise rejected with a new <code>TypeError</code>.</p></li>
8890588891

8890688892
<li><p>Perform <span>FinishDynamicImport</span>(<var>referencingScriptOrModule</var>,
88907-
<var>specifier</var>, <var>promiseCapability</var>, <var>completion</var>).</p></li>
88893+
<var>specifier</var>, <var>promiseCapability</var>, <var>promise</var>).</p></li>
8890888894

8890988895
<li><p>Return.</p></li>
8891088896
</ol>
8891188897
</li>
8891288898

8891388899
<li><p><span data-x="run a module script">Run the module script</span> <var>result</var>, with
88914-
the rethrow errors boolean set to true.</p></li>
88900+
the rethrow errors boolean set to true, and let the result be <var>promise</var>.</p></li>
8891588901

88916-
<li><p>If running the module script throws an exception, then perform
88902+
<li><p>Perform
8891788903
<span>FinishDynamicImport</span>(<var>referencingScriptOrModule</var>, <var>specifier</var>,
88918-
<var>promiseCapability</var>, the thrown exception completion).</p></li>
88904+
<var>promiseCapability</var>, <var>promise</var>).</p></li>
8891988905

88920-
<li><p>Otherwise, perform
88921-
<span>FinishDynamicImport</span>(<var>referencingScriptOrModule</var>, <var>specifier</var>,
88922-
<var>promiseCapability</var>, <span>NormalCompletion</span>(undefined)).</p></li>
88923-
88924-
<li><p>Return undefined.</p></li>
88906+
<li><p>Return.</p></li>
8892588907
</ol>
8892688908

8892788909
<h6

0 commit comments

Comments
 (0)