Skip to content

Commit

Permalink
Editorial: modernize promise rejection tracking
Browse files Browse the repository at this point in the history
Closes whatwg#10515.
  • Loading branch information
domenic authored Aug 7, 2024
1 parent a607170 commit 2b4f0d2
Showing 1 changed file with 55 additions and 59 deletions.
114 changes: 55 additions & 59 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -17928,16 +17928,16 @@ console.log(style.disabled); // false</code></pre>

<ol>
<li><p>If <var>document</var>'s <span>script-blocking style sheet set</span> is not <span
data-x="list empty">empty</span>, then return true.</p></li>
data-x="list is empty">empty</span>, then return true.</p></li>

<li><p>If <var>document</var>'s <span>node navigable</span> is null, then return false.</p></li>

<li><p>Let <var>containerDocument</var> be <var>document</var>'s <span>node navigable</span>'s
<span data-x="nav-container">container document</span>.</p></li>

<li><p>If <var>containerDocument</var> is non-null and <var>containerDocument</var>'s
<span>script-blocking style sheet set</span> is not <span data-x="list empty">empty</span>, then
return true.</p></li>
<span>script-blocking style sheet set</span> is not <span data-x="list is empty">empty</span>,
then return true.</p></li>

<li><p>Return false.</p></li>
</ol>
Expand Down Expand Up @@ -105427,13 +105427,6 @@ new PaymentRequest(&hellip;); // Allowed to use
<dd>A number used as the baseline for performance-related timestamps. <ref>HRT</ref></dd>
</dl>

<p>An <span>environment settings object</span> also has an <dfn>outstanding rejected promises
weak set</dfn> and an <dfn>about-to-be-notified rejected promises list</dfn>, used to track
<a href="#unhandled-promise-rejections">unhandled promise rejections</a>. The <span>outstanding
rejected promises weak set</span> must not create strong references to any of its members, and
implementations are free to limit its size, e.g. by removing old entries from it when new ones
are added.</p>

<p>An <span>environment settings object</span>'s <dfn export for="environment settings
object">responsible event loop</dfn> is its <span data-x="concept-settings-object-global">global
object</span>'s <span>relevant agent</span>'s <span data-x="concept-agent-event-loop">event
Expand All @@ -105449,6 +105442,20 @@ new PaymentRequest(&hellip;); // Allowed to use
objects</span> that are either <code>Window</code>, <code>WorkerGlobalScope</code>, or
<code>WorkletGlobalScope</code> objects.</p>

<p>A <span>global object</span> has an <dfn for="global object">in error reporting mode</dfn>
boolean, which is initially false.</p>

<p>A <span>global object</span> has an <dfn>outstanding rejected promises weak set</dfn>, a
<span>set</span> of <code data-x="idl-Promise">Promise</code> objects, initially empty. This set
must not create strong references to any of its members, and implementations are free to limit
its size in an <span>implementation-defined</span> manner, e.g., by removing old entries from it
when new ones are added.</p>

<p>A <span>global object</span> has an <dfn>about-to-be-notified rejected promises list</dfn>, a
<span>list</span> of <code data-x="idl-Promise">Promise</code> objects, initially empty.</p>

<hr>

<p>There is always a 1-to-1-to-1 mapping between <span data-x="realm">realms</span>, <span
data-x="global object">global objects</span>, and <span data-x="environment settings
object">environment settings objects</span>:</p>
Expand Down Expand Up @@ -105481,9 +105488,6 @@ new PaymentRequest(&hellip;); // Allowed to use
object">the environment settings object's global object</dfn>.</p></li>
</ul>

<p>A <span>global object</span> has an <dfn for="global object">in error reporting mode</dfn>
boolean, which is initially false.</p>

<p>To <dfn data-x="creating a new realm" export id="creating-a-new-javascript-realm">create a new
realm</dfn> in an <span>agent</span> <var>agent</var>, optionally with instructions to create a
global object or a global <b>this</b> binding (or both), the following steps are taken:</p>
Expand Down Expand Up @@ -107962,58 +107966,49 @@ dictionary <dfn dictionary>ErrorEventInit</dfn> : <span>EventInit</span> {

<div w-nodev>

<p>To <dfn>notify about rejected promises</dfn> on a given <span>environment settings object</span>
<var>settings object</var>:</p>
<p>To <dfn>notify about rejected promises</dfn> given a <span>global object</span>
<var>global</var>:</p>

<ol>
<li><p>Let <var>list</var> be a copy of <var>settings object</var>'s <span>about-to-be-notified
rejected promises list</span>.</p></li>
<li><p>Let <var>list</var> be a <span data-x="list clone">clone</span> of <var>global</var>'s
<span>about-to-be-notified rejected promises list</span>.</p></li>

<li><p>If <var>list</var> is empty, return.</p></li>
<li><p>If <var>list</var> <span data-x="list is empty">is empty</span>, then return.</p></li>

<li><p>Clear <var>settings object</var>'s <span>about-to-be-notified rejected promises
list</span>.</p></li>

<li><p>Let <var>global</var> be <var>settings object</var>'s <span
data-x="concept-settings-object-global">global object</span>.</p></li>
<li><p><span data-x="list empty">Empty</span> <var>global</var>'s <span>about-to-be-notified
rejected promises list</span>.</p></li>

<li>
<p><span>Queue a global task</span> on the <span>DOM manipulation task source</span> given
<var>global</var> to run the following substep:</p>
<var>global</var> to run the following step:</p>

<ol>
<li><p>For each promise <var>p</var> in <var>list</var>:</p>
<li><p><span data-x="list iterate">For each</span> promise <var>p</var> of <var>list</var>:</p>

<ol>
<li><p>If <var>p</var>'s [[PromiseIsHandled]] internal slot is true, continue to the next
iteration of the loop.</p></li>
<li><p>If <var>p</var>.[[PromiseIsHandled]] is true, then <span>continue</span>.</p></li>

<li><p>Let <var>notHandled</var> be the result of <span data-x="concept-event-fire">firing an
event</span> named <code data-x="event-unhandledrejection">unhandledrejection</code> at
<li><p>Let <var>notCanceled</var> be the result of <span data-x="concept-event-fire">firing
an event</span> named <code data-x="event-unhandledrejection">unhandledrejection</code> at
<var>global</var>, using <code>PromiseRejectionEvent</code>, with the <code
data-x="dom-Event-cancelable">cancelable</code> attribute initialized to true, the <code
data-x="dom-PromiseRejectionEvent-promise">promise</code> attribute initialized to
<var>p</var>, and the <code data-x="dom-PromiseRejectionEvent-reason">reason</code> attribute
initialized to the value of <var>p</var>'s [[PromiseResult]] internal slot.</p></li>
<var>p</var>, and the <code data-x="dom-PromiseRejectionEvent-reason">reason</code>
attribute initialized to <var>p</var>.[[PromiseResult]].</p></li>

<li><p>If <var>notHandled</var> is false, then the promise rejection is <i
data-x="concept-promise-rejection-handled">handled</i>. Otherwise, the promise rejection is
<i data-x="concept-promise-rejection-nothandled">not handled</i>.</p></li>
<li id="concept-promise-rejection-handled"><p id="concept-promise-rejection-nothandled">If
<var>notCanceled</var> is true, then the user agent may report
<var>p</var>.[[PromiseResult]] to a developer console.</p></li>

<li><p>If <var>p</var>'s [[PromiseIsHandled]] internal slot is false, add <var>p</var> to
<var>settings object</var>'s <span>outstanding rejected promises weak set</span>.
<li><p>If <var>p</var>.[[PromiseIsHandled]] is false, then <span data-x="set
append">append</span> <var>p</var> to <var>global</var>'s <span>outstanding rejected
promises weak set</span>.</p></li>
</ol>
</li>
</ol>
</li>
</ol>

<p>This algorithm results in promise rejections being marked as <dfn
data-x="concept-promise-rejection-handled"><i>handled</i></dfn> or <dfn
data-x="concept-promise-rejection-nothandled"><i>not handled</i></dfn>. If a rejection is still
<i data-x="concept-promise-rejection-nothandled">not handled</i> after this, then the rejection
may be reported to a developer console.</p>

<p id="the-promiserejectionevent-interface">The <code>PromiseRejectionEvent</code> interface is
defined as follows:</p>

Expand Down Expand Up @@ -109040,37 +109035,37 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
<li><p>If <var>script</var> is a <span>classic script</span> and <var>script</var>'s <span>muted
errors</span> is true, then return.</p></li>

<li><p>Let <var>settings object</var> be the <span>current settings object</span>.</p></li>
<li><p>Let <var>settingsObject</var> be the <span>current settings object</span>.</p></li>

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

<li><p>Let <var>global</var> be <var>settingsObject</var>'s <span
data-x="concept-settings-object-global">global object</span>.</p></li>

<li>
<p>If <var>operation</var> is "<code data-x="">reject</code>", then:</p>

<ol>
<li><p><span data-x="list append">Append</span> <var>promise</var> to <var>settings
object</var>'s <span>about-to-be-notified rejected promises list</span>.</p></li>
<li><p><span data-x="list append">Append</span> <var>promise</var> to <var>global</var>'s
<span>about-to-be-notified rejected promises list</span>.</p></li>
</ol>
</li>

<li>
<p>If <var>operation</var> is "<code data-x="">handle</code>", then:</p>

<ol>
<li><p>If <var>settings object</var>'s <span>about-to-be-notified rejected promises
list</span> <span data-x="list contains">contains</span> <var>promise</var>, then <span
data-x="list remove">remove</span> <var>promise</var> from that list and return.</p></li>
<li><p>If <var>global</var>'s <span>about-to-be-notified rejected promises list</span> <span
data-x="list contains">contains</span> <var>promise</var>, then <span data-x="list
remove">remove</span> <var>promise</var> from that list and return.</p></li>

<li><p>If <var>settings object</var>'s <span>outstanding rejected promises weak set</span>
does not <span data-x="list contains">contain</span> <var>promise</var>, then return.</p></li>
<li><p>If <var>global</var>'s <span>outstanding rejected promises weak set</span> does not
<span data-x="list contains">contain</span> <var>promise</var>, then return.</p></li>

<li><p><span data-x="list remove">Remove</span> <var>promise</var> from <var>settings
object</var>'s <span>outstanding rejected promises weak set</span>.</p></li>

<li><p>Let <var>global</var> be <var>settings object</var>'s <span
data-x="concept-settings-object-global">global object</span>.</p></li>
<li><p><span data-x="list remove">Remove</span> <var>promise</var> from <var>global</var>'s
<span>outstanding rejected promises weak set</span>.</p></li>

<li><p><span>Queue a global task</span> on the <span>DOM manipulation task source</span> given
<var>global</var> to <span data-x="concept-event-fire">fire an event</span> named <code
Expand Down Expand Up @@ -110588,9 +110583,10 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
</ol>
</li>

<li><p>For each <span>environment settings object</span> whose <span>responsible event
loop</span> is this <span>event loop</span>, <span>notify about rejected promises</span> on that
<span>environment settings object</span>.</p></li>
<li><p>For each <span>environment settings object</span> <var>settingsObject</var> whose
<span>responsible event loop</span> is this <span>event loop</span>, <span>notify about rejected
promises</span> given <var>settingsObject</var>'s <span
data-x="concept-settings-object-global">global object</span>.</p></li>

<li><p><span>Cleanup Indexed Database transactions</span>.</p></li>

Expand Down

0 comments on commit 2b4f0d2

Please sign in to comment.