Skip to content
Permalink
Browse files

Fix #715: clarify how aborting a running script works

Previously it wasn't clear exactly which parts of the processing model
the vague phrase "abort the script" impacted. This gives us a specific
term that at least outlines the concept, and makes all other places
that are impacted by script abortion reference that term.
  • Loading branch information...
domenic committed Feb 19, 2016
1 parent efe130a commit 6a48bfbf1066034eab4786d62ba4017593c48430
Showing with 37 additions and 23 deletions.
  1. +37 −23 source
60 source
data-x="js-ScriptEvaluation">ScriptEvaluation</span>(<var>result</var>).</p></li>

<li><p>If <var>evaluationStatus</var> is an abrupt completion, set <var>result</var> to
<var>evaluationStatus</var>.[[value]] and go to the step labeled <i>error</i>.</p></li>

<li><p>If we have reached this step, skip to the step labeled <i>cleanup</i>.</p></li>
<var>evaluationStatus</var>.[[value]] and go to the next step (labeled <i>error</i>). If
<var>evaluationStatus</var> is a normal completion, or if <span
data-x="js-ScriptEvaluation">ScriptEvaluation</span> does not complete because the user agent
has <span data-x="abort a running script">aborted the running script</span>, skip to the step
labeled <i>cleanup</i>.</p></li>

<li>
<p><i>Error</i>: At this point <var>result</var> must be an error object. Perform the following
<p><i>Error</i>: At this point <var>result</var> must be an exception. Perform the following
steps:</p>

<ol>
<li><p><i>Cleanup</i>: <span>Clean up after running script</span> with
<var>settings</var>.</p></li>

<li><p>If <var>evaluationStatus</var> exists and is not an abrupt completion, return
<li><p>If <var>evaluationStatus</var> exists and is a normal completion, return
<var>evaluationStatus</var>.[[value]]. Otherwise, script execution was unsuccessful, either
because an error occurred during parsing, or an exception occurred during evaluation, or because
it was aborted prematurely.</p></li>
it was <span data-x="abort a running script">aborted prematurely</span>.</p></li>

</ol>

</li>

<li><p>If <var>evaluationStatus</var> is an abrupt completion, <span>report the exception</span>
given by <var>evaluationStatus</var>.[[value]] for <var>s</var>.</p></li>
given by <var>evaluationStatus</var>.[[value]] for <var>s</var>. (Do not perform this step if
<span data-x="js-ScriptEvaluation">ScriptEvaluation</span> fails to complete as a result of the
user agent <span data-x="abort a running script">aborting the running script</span>.)</p></li>

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

<h5>Killing scripts</h5>

<p>Although the JavaScript specification does not account for this possibility, it's sometimes
necessary to <dfn>abort a running script</dfn>. This causes any <span
data-x="js-ScriptEvaluation">ScriptEvaluation</span> or <span
data-x="js-ModuleEvaluation">ModuleEvaluation</span> to cease immediately, emptying the
<span>JavaScript execution context stack</span> without triggering any of the normal mechanisms
like <code data-x="">finally</code> blocks. <ref spec=ECMA262></p>

<p>User agents may impose resource limitations on scripts, for example CPU quotas, memory limits,
total execution time limits, or bandwidth limitations. When a script exceeds a limit, the user
agent may either throw a <code>QuotaExceededError</code> exception, abort the script without an
exception, prompt the user, or throttle script execution.</p>
agent may either throw a <code>QuotaExceededError</code> exception, <span data-x="abort a running
script">abort the script</span> without an exception, prompt the user, or throttle script
execution.</p>

<div class="example">

<var>script</var>.</p>

<p class="note">In addition to the usual possibilities of returning a value or failing due to
an exception, this could be prematurely aborted by the "<span>kill a worker</span>" or
"<span>terminate a worker</span>" algorithms defined below.</p>
an exception, this could be <span data-x="abort a running script">prematurely aborted</span> by
the "<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms defined
below.</p>
</li>

<li><p>Enable <var>outside port</var>'s <span>port message queue</span>.</p></li>
event loop</span> specified by <var>settings object</var> until it is destroyed.</p>

<p class="note">The handling of events or the execution of callbacks by <span
data-x="concept-task">tasks</span> run by the <span>event loop</span> might get prematurely
aborted by the "<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms
defined below.</p>
data-x="concept-task">tasks</span> run by the <span>event loop</span> might get <span
data-x="abort a running script">prematurely aborted</span> by the "<span>kill a worker</span>"
or "<span>terminate a worker</span>" algorithms defined below.</p>

<p class="note">The worker processing model remains on this step until the event loop is
destroyed, which happens after the <span data-x="dom-WorkerGlobalScope-closing">closing</span>

<li><p>Wait a user-agent-defined amount of time.</p></li>

<li><p>Abort the script currently running in the worker.</p></li>
<li><p><span data-x="abort a running script">Abort the script</span> currently running in the
worker.</p></li>

</ol>

<code>WorkerGlobalScope</code> object's <span>event loop</span>'s <span data-x="task queue">task
queues</span>, discard them without processing them.</p></li>

<li><p>Abort the script currently running in the worker.</p></li>
<li><p><span data-x="abort a running script">Abort the script</span> currently running in the
worker.</p></li>

<li><p>If the worker's <code>WorkerGlobalScope</code> object is actually a
<code>DedicatedWorkerGlobalScope</code> object (i.e. the worker is a dedicated worker), then
passing the <var>rethrow errors</var> flag.</p>

<p class="note"><var>script</var> 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>
catch an exception, or gets <span data-x="abort a running script">prematurely aborted</span>
by the "<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms defined
above.</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
<p>If an exception was thrown or if the script was <span data-x="abort a running
script">prematurely aborted</span>, 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>

<p>If the "<span>kill a worker</span>" or "<span>terminate a worker</span>" algorithms abort
the script then abort all these steps.</p>

</li>

</ol>

0 comments on commit 6a48bfb

Please sign in to comment.
You can’t perform that action at this time.