Skip to content

Commit

Permalink
Separate out parse error and error to rethrow
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Sep 8, 2017
1 parent 8658c49 commit 5737282
Showing 1 changed file with 45 additions and 39 deletions.
84 changes: 45 additions & 39 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -86259,16 +86259,23 @@ interface <dfn>NavigatorOnLine</dfn> {
script">module scripts</span>; or null. In the former two cases, it represents a parsed script;
null represents a failure parsing.</p></dd>

<dt>An <dfn data-dfn-for="script" data-export="" data-x="concept-script-error">error</dfn></dt>
<dt>A <dfn data-dfn-for="script" data-export="" data-x="concept-script-parse-error">parse
error</dfn></dt>

<dd><p>A JavaScript value, which has meaning only if the <span
data-x="concept-script-record">record</span> is null, indicating that the corresponding script
source text could not be parsed.</p></dd>

<dt>An <dfn data-dfn-for="script" data-export="" data-x="concept-script-error-to-rethrow">error
to rethrow</dfn></dt>

<dd>
<p>A JavaScript value representing an error that will prevent evaluation from succeeding. It
will be re-thrown by any attempts to <a href="#calling-scripts">run</a> the script.</p>

<p class="note">There are two main categories of such errors: errors parsing the script's source
text, in which case the script's <span data-x="concept-script-record">record</span> will
be null; or more general errors in dependencies of a <span>module script</span>. This
distinction is used by the algorithm for <span>finding the first parse error</span>.</p>
text (equal to the script's <span data-x="concept-script-parse-error">parse error</span>), or
more general errors in dependencies of a <span>module script</span>.</p>

<p class="note">Since this exception value is provided by the JavaScript specification, we know
that it is never null, so we use null to signal that no error has occurred.</p>
Expand Down Expand Up @@ -86965,11 +86972,7 @@ interface <dfn>NavigatorOnLine</dfn> {
<li><p>Let <var>parse error</var> be the result of <span>finding the first parse error</span>
given <var>result</var>.</p></li>

<li><p>If <var>parse error</var> is not null, then set <var>result</var>'s <span
data-x="concept-script-error">error</span> to <var>parse error</var>.</p></li>

<li>
<p>Otherwise:</p>
<li><p>If <var>parse error</var> is null, then:</p>

<ol>
<li><p>Let <var>record</var> be <var>result</var>'s <span
Expand All @@ -86978,15 +86981,19 @@ interface <dfn>NavigatorOnLine</dfn> {
<li>
<p>Perform <var>record</var>.<span data-x="js-Instantiate">Instantiate</span>().</p>

<p class="note">This step will recursively call <span data-x="js-Instantiate">Instantiate</span>
on all of the module's uninstantiated dependencies.</p>
<p class="note">This step will recursively call <span
data-x="js-Instantiate">Instantiate</span> on all of the module's uninstantiated
dependencies.</p>

<p>If this throws an exception, set <var>result</var>'s <span
data-x="concept-script-error">error</span> to that exception.</p>
data-x="concept-script-error-to-rethrow">error to rethrow</span> to that exception.</p>
</li>
</ol>
</li>

<li><p>Otherwise, set <var>result</var>'s <span data-x="concept-script-error-to-rethrow">error to
rethrow</span> to <var>parse error</var>.</p></li>

<li><p>Asynchronously complete this algorithm with <var>result</var>.</p></li>
</ol>

Expand All @@ -87002,17 +87009,9 @@ interface <dfn>NavigatorOnLine</dfn> {
<li><p><span data-x="list append">Append</span> <var>moduleScript</var> to
<var>discoveredSet</var>.</p></li>

<li>
<p>If <var>moduleScript</var>'s <span data-x="concept-script-record">record</span> is null,
then return <var>moduleScript</var>'s <span data-x="concept-script-error">error</span>.</p>

<p class="note">It's important that we check if <var>moduleScript</var>'s <span
data-x="concept-script-record">record</span> is null, and <em>not</em> simply check that
<var>moduleScript</var>'s <span data-x="concept-script-error">error</span> is non-null. This
ensures we only catch errors from parsing <var>moduleScript</var>, and not instantiation errors
or errors from parsing its dependencies that were stored in the <span
data-x="concept-script-error">error</span> field for later re-throwing.</p>
</li>
<li><p>If <var>moduleScript</var>'s <span data-x="concept-script-record">record</span> is null,
then return <var>moduleScript</var>'s <span data-x="concept-script-parse-error">parse
error</span>.</p></li>

<li><p>Let <var>childSpecifiers</var> be the value of <var>moduleScript</var>'s <span
data-x="concept-script-record">record</span>'s [[RequestedModules]] internal slot.</p></li>
Expand Down Expand Up @@ -87069,6 +87068,9 @@ interface <dfn>NavigatorOnLine</dfn> {

<li><p>Set <var>script</var>'s <span>muted errors</span> to <var>muted errors</var>.</p></li>

<li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and
<span data-x="concept-script-error-to-rethrow">error to rethrow</span> to null.</p></li>

<li>
<p>Let <var>result</var> be <span data-x="js-ParseScript">ParseScript</span>(<var>source</var>,
<var>settings</var>'s <span data-x="environment settings object's Realm">Realm</span>,
Expand All @@ -87078,11 +87080,12 @@ interface <dfn>NavigatorOnLine</dfn> {
<var>result</var>.[[HostDefined]] will be <var>script</var>.</p>
</li>

<li><p>If <var>result</var> is a <span>List</span> of errors, then set <var>script</var>'s <span
data-x="concept-script-error">error</span> to <var>result</var>[0].</p></li>
<li><p>If <var>result</var> is a <span>list</span> of errors, then set <var>script</var>'s <span
data-x="concept-script-parse-error">parse error</span> and its <span
data-x="concept-script-error-to-rethrow">error to rethrow</span> to <var>result</var>[0].</p></li>

<li><p>Otherwise, set <var>script</var>'s <span data-x="concept-script-record">record</span> to
<var>result</var> and its <span data-x="concept-script-error">error</span> to null.</p></li>
<var>result</var>.</p></li>

<li><p>Return <var>script</var>.</p></li>
</ol>
Expand All @@ -87105,6 +87108,9 @@ interface <dfn>NavigatorOnLine</dfn> {

<li><p>Set <var>script</var>'s <span>settings object</span> to <var>settings</var>.</p></li>

<li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and
<span data-x="concept-script-error-to-rethrow">error to rethrow</span> to null.</p></li>

<li>
<p>Let <var>result</var> be <span data-x="js-ParseModule">ParseModule</span>(<var>source</var>,
<var>settings</var>'s <span data-x="environment settings object's Realm">Realm</span>,
Expand All @@ -87115,10 +87121,11 @@ interface <dfn>NavigatorOnLine</dfn> {
</li>

<li>
<p>If <var>result</var> is a <span>List</span> of errors, then:</p>
<p>If <var>result</var> is a <span>list</span> of errors, then:</p>

<ol>
<li><p>Set <var>script</var>'s <span data-x="concept-script-error">error</span> to
<li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span> and
its <span data-x="concept-script-error-to-rethrow">error to rethrow</span> to
<var>result</var>[0].</p></li>

<li><p>Return <var>script</var>.</p></li>
Expand All @@ -87139,7 +87146,8 @@ interface <dfn>NavigatorOnLine</dfn> {
<ol>
<li><p>Let <var>error</var> be a new <code>TypeError</code> exception.</p></li>

<li><p>Set <var>script</var>'s <span data-x="concept-script-error">error</span> to
<li><p>Set <var>script</var>'s <span data-x="concept-script-parse-error">parse error</span>
and its <span data-x="concept-script-error-to-rethrow">error to rethrow</span> to
<var>error</var>.</p></li>

<li><p>Return <var>script</var>.</p></li>
Expand All @@ -87156,8 +87164,6 @@ interface <dfn>NavigatorOnLine</dfn> {
<li><p>Set <var>script</var>'s <span data-x="concept-script-record">record</span> to
<var>result</var>.</p></li>

<li><p>Set <var>script</var>'s <span data-x="concept-script-error">error</span> to null.</p></li>

<li><p>Set <var>script</var>'s <span data-x="concept-module-script-base-url">base URL</span> to
<var>baseURL</var>.</p></li>

Expand Down Expand Up @@ -87190,10 +87196,10 @@ interface <dfn>NavigatorOnLine</dfn> {

<li><p>Let <var>evaluationStatus</var> be null.</p></li>

<li><p>If <var>script</var>'s <span data-x="concept-script-error">error</span> is not
null, then set <var>evaluationStatus</var> to Completion { [[Type]]: throw, [[Value]]:
<var>script</var>'s <span data-x="concept-script-error">error</span>, [[Target]]: empty
}.</p></li>
<li><p>If <var>script</var>'s <span data-x="concept-script-error-to-rethrow">error to
rethrow</span> is not null, then set <var>evaluationStatus</var> to Completion { [[Type]]: throw,
[[Value]]: <var>script</var>'s <span data-x="concept-script-error-to-rethrow">error to
rethrow</span>, [[Target]]: empty }.</p></li>

<li>
<p>Otherwise, set <var>evaluationStatus</var> to <span
Expand Down Expand Up @@ -87273,10 +87279,10 @@ interface <dfn>NavigatorOnLine</dfn> {

<li><p>Let <var>evaluationStatus</var> be null.</p></li>

<li><p>If <var>script</var>'s <span data-x="concept-script-error">error</span> is not
null, then set <var>evaluationStatus</var> to Completion { [[Type]]: throw, [[Value]]:
<var>script</var>'s <span data-x="concept-script-error">error</span>, [[Target]]: empty
}.</p></li>
<li><p>If <var>script</var>'s <span data-x="concept-script-error-to-rethrow">error to
rethrow</span> is not null, then set <var>evaluationStatus</var> to Completion { [[Type]]: throw,
[[Value]]: <var>script</var>'s <span data-x="concept-script-error-to-rethrow">error to
rethrow</span>, [[Target]]: empty }.</p></li>

<li>
<p>Otherwise:</p>
Expand Down

0 comments on commit 5737282

Please sign in to comment.