Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add abort reason to AbortSignal #1027

Merged
merged 20 commits into from
Nov 8, 2021
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ interface AbortController {

[SameObject] readonly attribute AbortSignal signal;

undefined abort();
undefined abort(optional any reason);
};
</pre>

Expand All @@ -1741,8 +1741,9 @@ interface AbortController {
<dt><code><var>controller</var> . <a attribute for=AbortController>signal</a></code>
<dd>Returns the {{AbortSignal}} object associated with this object.

<dt><code><var>controller</var> . <a method for=AbortController lt=abort()>abort</a>()</code>
<dd>Invoking this method will set this object's {{AbortSignal}}'s [=AbortSignal/aborted flag=] and
<dt><code><var>controller</var> . <a method for=AbortController lt=abort()>abort</a>(reason)</code>
<dd>Invoking this method will set this object's {{AbortSignal}}'s [=AbortSignal/aborted flag=],
store <var ignore>reason</var> in this object's {{AbortSignal}}'s [=AbortSignal/abort reason=], and
signal to any observers that the associated activity is to be aborted.
</dl>

Expand All @@ -1762,25 +1763,33 @@ constructor steps are:
<p>The <dfn attribute for=AbortController><code>signal</code></dfn> getter steps are to return
<a>this</a>'s <a for=AbortController>signal</a>.

<p>The <dfn method for=AbortController><code>abort()</code></dfn> method steps are to
<a for=AbortSignal>signal abort</a> on <a>this</a>'s <a for=AbortController>signal</a>.

<p>The <dfn method for=AbortController><code>abort(reason)</code></dfn> method steps are to
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved
<a for=AbortSignal>signal abort</a> on <a>this</a>'s <a for=AbortController>signal</a> with
<var>reason</var> if it is given.

<h3 id=interface-AbortSignal>Interface {{AbortSignal}}</h3>

<pre class=idl>
[Exposed=(Window,Worker)]
interface AbortSignal : EventTarget {
[NewObject] static AbortSignal abort();
[NewObject] static AbortSignal abort(optional any reason);

readonly attribute boolean aborted;

readonly attribute any reason;
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved

attribute EventHandler onabort;
};</pre>

annevk marked this conversation as resolved.
Show resolved Hide resolved
<dl class=domintro>
<dt><code>AbortSignal . <a method for="AbortSignal">abort()</a></code>
<dd>Returns an {{AbortSignal}} instance whose <a for=AbortSignal>aborted flag</a> is set.
<dt><code>AbortSignal . <a method for=AbortSignal>abort</a>(reason)</code>
<dd>Returns an {{AbortSignal}} instance whose <a for=AbortSignal>aborted flag</a> is set, and
<a for=AbortSignal>abort reason</a> is set to <var>reason</var> if provided, otherwise to an
"{{AbortError!!exception}}" {{DOMException}}.
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved

<dt><code><var>signal</var> . <a attribute for=AbortSignal>reason</a></code>
<dd>Returns the <a for=AbortSignal>abort reason</a> for an {{AbortSignal}}; by default this will
be an "{{AbortError!!exception}}" {{DOMException}}.
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved

<dt><code><var>signal</var> . <a attribute for=AbortSignal>aborted</a></code>
<dd>Returns true if this {{AbortSignal}}'s {{AbortController}} has signaled to abort; otherwise
Expand All @@ -1790,6 +1799,9 @@ interface AbortSignal : EventTarget {
<p>An {{AbortSignal}} object has an associated <dfn export for=AbortSignal>aborted flag</dfn>. It is
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this broke the builds of specs that use the aborted flag. No objections to the change; we just need to keep looking for better ways to do this sort of migration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's continue to discuss in #1030.

unset unless specified otherwise.

<p>An {{AbortSignal}} object has an associated <dfn export for=AbortSignal>abort reason</dfn>, which is a
JavaScript value given to {{AbortController}}'s {{AbortController/abort()}}, or undefined.
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved

<p>An {{AbortSignal}} object has associated <dfn for=AbortSignal>abort algorithms</dfn>, which is a
<a for=/>set</a> of algorithms which are to be executed when its [=AbortSignal/aborted flag=] is
set. Unless specified otherwise, its value is the empty set.
Expand All @@ -1813,19 +1825,25 @@ requirements to react in a reasonable way to {{AbortController/abort()}}. For ex
[=AbortSignal/aborted flag=] might need to be propagated to a cross-thread environment, such as a
service worker.

<p>The static <dfn method for=AbortSignal><code>abort()</code></dfn> method steps are:
<p>The static <dfn method for=AbortSignal><code>abort(reason)</code></dfn> method steps are:
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved

<ol>
<li><p>Let <var>signal</var> be a new {{AbortSignal}} object.

<li><p>Set <var>signal</var>'s [=AbortSignal/aborted flag=].

<li><p>Set <var>signal</var>'s [=AbortSignal/abort reason=] to <var>reason</var> if it is given,
and a new "{{AbortError!!exception}}" {{DOMException}} otherwise.
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved

<li>Return <var>signal</var>.
</ol>

<p>The <dfn attribute for=AbortSignal>aborted</dfn> getter steps are to return true if <a>this</a>'s
[=AbortSignal/aborted flag=] is set; otherwise false.

<p>The <dfn attribute for=AbortSignal>reason</dfn> getter steps are to return <a>this</a>'s
<a for=AbortSignal>abort reason</a>.

<p>The <dfn attribute for=AbortSignal><code>onabort</code></dfn> attribute is an
<a>event handler IDL attribute</a> for the <dfn export for=AbortSignal><code>onabort</code></dfn>
<a>event handler</a>, whose <a>event handler event type</a> is
Expand All @@ -1836,13 +1854,16 @@ service worker.
them. For instance, if the operation has already completed.

<p>To <dfn export for=AbortSignal>signal abort</dfn>, given an {{AbortSignal}} object
<var>signal</var>, run these steps:
<var>signal</var> and an optional <var>reason</var>, run these steps:

<ol>
<li><p>If <var>signal</var>'s [=AbortSignal/aborted flag=] is set, then return.

<li><p>Set <var>signal</var>'s [=AbortSignal/aborted flag=].

<li><p>Set <var>signal</var>'s [=AbortSignal/abort reason=] to <var>reason</var> if it is given,
and a new "{{AbortError!!exception}}" {{DOMException}} otherwise.
nidhijaju marked this conversation as resolved.
Show resolved Hide resolved

<li><p><a for=set>For each</a> <var>algorithm</var> in <var>signal</var>'s
[=AbortSignal/abort algorithms=]: run <var>algorithm</var>.

Expand All @@ -1859,14 +1880,16 @@ these steps:
<li><p>If <var>followingSignal</var>'s [=AbortSignal/aborted flag=] is set, then return.

<li><p>If <var>parentSignal</var>'s [=AbortSignal/aborted flag=] is set, then
<a for=AbortSignal>signal abort</a> on <var>followingSignal</var>.
<a for=AbortSignal>signal abort</a> on <var>followingSignal</var> with <var>parentSignal</var>'s
[=AbortSignal/abort reason=].

<li>
<p>Otherwise, <a for=AbortSignal lt=add>add the following abort steps</a> to
<var>parentSignal</var>:

<ol>
<li><p><a for=AbortSignal>Signal abort</a> on <var>followingSignal</var>.
<li><p><a for=AbortSignal>Signal abort</a> on <var>followingSignal</var> with
<var>parentSignal</var>'s [=AbortSignal/abort reason=].
</ol>
</ol>

Expand Down