Skip to content

Commit

Permalink
Fix importScripts() script execution
Browse files Browse the repository at this point in the history
This fixes #193, which notes that importScripts() previously sent errors down the "report an exception" path instead of rethrowing them. It also makes a slight change of rethrowing any early errors that are not SyntaxErrors, instead of converting early ReferenceErrors into SyntaxErrors.
  • Loading branch information
domenic committed Dec 15, 2015
1 parent a2b4606 commit dd665d7
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -85690,8 +85690,8 @@ interface <dfn>NavigatorOnLine</dfn> {
<h5>Calling scripts</h5>

<p>When a user agent is to <dfn>jump to a code entry-point</dfn> for a <span
data-x="concept-script">script</span> <var>s</var>, the user agent must run the
following steps:</p>
data-x="concept-script">script</span> <var>s</var>, given an optional <var>rethrow errors</var>
flag, the user agent must run the following steps:</p>

<ol>

Expand All @@ -85706,15 +85706,35 @@ interface <dfn>NavigatorOnLine</dfn> {
<li><p>Let <var>result</var> be <span data-x="js-ParseScript">ParseScript</span>(<var>s</var>'s
code entry-point, <var>s</var>).</p></li>

<li><p>If <var>result</var> is a List of errors, <span>report the exception</span> given by the
first element in <var>result</var> for the script <var>s</var>, and go to the step labeled
<i>cleanup</i>.</p></li>
<li>
<p>If <var>result</var> is a List of errors, then:</p>

<ol>
<li><p>If the <var>rethrow errors</var> flag is set and <var>s</var>'s <var>muted errors</var>
flag is not set, rethrow the error given by the first element of <var>result</var>.</p></li>

This comment has been minimized.

Copy link
@annevk

annevk Dec 16, 2015

Member

Newline after each <li> that is not followed by </ol>?

<li><p>If the <var>rethrow errors</var> flag is set and <var>s</var>'s <var>muted
errors</var> flag is set, throw a <code>NetworkError</code> exception.</p></li>

This comment has been minimized.

Copy link
@annevk

annevk Dec 16, 2015

Member

I guess this is as specified as the old text, but one thing we need to make clear is this exception cannot have a stack trace and such. I guess that follows from it being a new exception and not the same one, but given the way we normally throw exceptions that might not be entirely clear.

This comment has been minimized.

Copy link
@domenic

domenic Dec 16, 2015

Author Member

Hmm, I think it's pretty clear. But we could add a note like this perhaps:

This new NetworkError exception does not convey any information about the error(s) in result. Since errors are being muted, all information about the original errors is intentionally lost.

How does that sound? Any tweaks?

This comment has been minimized.

Copy link
@annevk

annevk Dec 16, 2015

Member

I guess we don't need the note. I was thinking about "8.1.3.6 Runtime script errors"'s "report an error" algorithm which in step 6 goes in particular detail how things are masked, but none of that really applies here.

<li><p>If the <var>rethrow errors</var> flag is not set, <span>report the exception</span>
given by the first element in <var>result</var> for the script <var>s</var>.</p></li>
<li><p>In all cases, go to the step labeled <i>cleanup</i>.</p></li>
</ol>
</li>

<li><p>Let <var>status</var> be <span
data-x="js-ScriptEvaluation">ScriptEvaluation</span>(<var>result</var>).</p></li>

<li><p>If <var>status</var> is an abrupt completion, <span>report the exception</span> given by
<var>result</var>.[[value]] for the script <var>s</var>.</p></li>
<li>
<p>If <var>status</var> is an abrupt completion, then:</p>

<ol>
<li><p>If the <var>rethrow errors</var> flag is set and <var>s</var>'s <var>muted errors</var>
flag is not set, rethrow the error given by <var>result</var>.[[value]].</p></li>
<li><p>If the <var>rethrow errors</var> flag is set and <var>s</var>'s <var>muted
errors</var> flag is set, throw a <code>NetworkError</code> exception.</p></li>
<li><p>If the <var>rethrow errors</var> flag is not set, <span>report the exception</span>
given <var>result</var>.[[value]] for the script <var>s</var>.</p></li>
</ol>
</li>

<li><p><i>Cleanup</i>: <span>Clean up after running a callback</span> with
<var>settings</var>.</p></li>
Expand Down Expand Up @@ -85871,8 +85891,8 @@ interface <dfn>NavigatorOnLine</dfn> {

<p>When the specification says that a <span data-x="concept-script">script</span> is to be <dfn
data-x="create a script">created</dfn>, given some script source, a script source URL, an
<span>environment settings object</span>, and optionally a <var>muted errors</var> flag, the user
agent must run the following steps:</p>
<span>environment settings object</span>, and optionally <var>muted errors</var> and <var>rethrow
errors</var> flag, the user agent must run the following steps:</p>

<ol>

Expand All @@ -85893,7 +85913,7 @@ interface <dfn>NavigatorOnLine</dfn> {
errors</span> flag.</p></li>

<li><p><span data-x="jump to a code entry-point">Jump</span> to <var>script</var>'s <span>code
entry-point</span>.</p></li>
entry-point</span>, passing the <var>rethrow errors</var> flag if it was given.</p></li>

</ol>

Expand Down Expand Up @@ -95413,24 +95433,18 @@ interface <dfn>SharedWorker</dfn> : <span>EventTarget</span> {
<li>

<p><span>Create a script</span> using <var>source</var> as the script source, the
<span>URL</span> from which <var>source</var> was obtained, and <var>settings object</var> as
the <span>environment settings object</span>.</p>
<span>URL</span> from which <var>source</var> was obtained, <var>settings object</var> as
the <span>environment settings object</span>, and passing the <var>rethrow errors</var>
flag.</p>

<p>If <var>response</var> is <span>CORS-cross-origin</span>, pass the <var>muted errors</var>
flag to the <span>create a script</span> algorithm as well.</p>

<p>Let the newly created <span data-x="concept-script">script</span> run until it either
returns, fails to parse, fails to catch an exception, or gets prematurely aborted by the
"<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms defined
<p class="note">The newly created <span data-x="concept-script">script</span> will run until
it either returns, fails to parse, fails to catch an exception, or gets prematurely aborted
by the "<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms defined
above.</p>

<p>If <var>response</var> is <span>CORS-cross-origin</span> and either it failed to parse or
an exception was thrown, then throw a <code>NetworkError</code> exception and abort all these
steps.</p>

<p>If it failed to parse, then throw an ECMAScript <code
data-x="js-SyntaxError">SyntaxError</code> exception and abort all these steps. <ref spec=ECMA262></p>

<p>If an exception was thrown or if the script was prematurely aborted, then abort all these
steps, letting the exception or aborting continue to be processed by the calling <span
data-x="concept-script">script</span>.</p>
Expand Down

0 comments on commit dd665d7

Please sign in to comment.