Skip to content

Commit 2b4f0d2

Browse files
authored
Editorial: modernize promise rejection tracking
Closes whatwg#10515.
1 parent a607170 commit 2b4f0d2

File tree

1 file changed

+55
-59
lines changed

1 file changed

+55
-59
lines changed

source

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17928,16 +17928,16 @@ console.log(style.disabled); // false</code></pre>
1792817928

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

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

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

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

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

105430-
<p>An <span>environment settings object</span> also has an <dfn>outstanding rejected promises
105431-
weak set</dfn> and an <dfn>about-to-be-notified rejected promises list</dfn>, used to track
105432-
<a href="#unhandled-promise-rejections">unhandled promise rejections</a>. The <span>outstanding
105433-
rejected promises weak set</span> must not create strong references to any of its members, and
105434-
implementations are free to limit its size, e.g. by removing old entries from it when new ones
105435-
are added.</p>
105436-
105437105430
<p>An <span>environment settings object</span>'s <dfn export for="environment settings
105438105431
object">responsible event loop</dfn> is its <span data-x="concept-settings-object-global">global
105439105432
object</span>'s <span>relevant agent</span>'s <span data-x="concept-agent-event-loop">event
@@ -105449,6 +105442,20 @@ new PaymentRequest(&hellip;); // Allowed to use
105449105442
objects</span> that are either <code>Window</code>, <code>WorkerGlobalScope</code>, or
105450105443
<code>WorkletGlobalScope</code> objects.</p>
105451105444

105445+
<p>A <span>global object</span> has an <dfn for="global object">in error reporting mode</dfn>
105446+
boolean, which is initially false.</p>
105447+
105448+
<p>A <span>global object</span> has an <dfn>outstanding rejected promises weak set</dfn>, a
105449+
<span>set</span> of <code data-x="idl-Promise">Promise</code> objects, initially empty. This set
105450+
must not create strong references to any of its members, and implementations are free to limit
105451+
its size in an <span>implementation-defined</span> manner, e.g., by removing old entries from it
105452+
when new ones are added.</p>
105453+
105454+
<p>A <span>global object</span> has an <dfn>about-to-be-notified rejected promises list</dfn>, a
105455+
<span>list</span> of <code data-x="idl-Promise">Promise</code> objects, initially empty.</p>
105456+
105457+
<hr>
105458+
105452105459
<p>There is always a 1-to-1-to-1 mapping between <span data-x="realm">realms</span>, <span
105453105460
data-x="global object">global objects</span>, and <span data-x="environment settings
105454105461
object">environment settings objects</span>:</p>
@@ -105481,9 +105488,6 @@ new PaymentRequest(&hellip;); // Allowed to use
105481105488
object">the environment settings object's global object</dfn>.</p></li>
105482105489
</ul>
105483105490

105484-
<p>A <span>global object</span> has an <dfn for="global object">in error reporting mode</dfn>
105485-
boolean, which is initially false.</p>
105486-
105487105491
<p>To <dfn data-x="creating a new realm" export id="creating-a-new-javascript-realm">create a new
105488105492
realm</dfn> in an <span>agent</span> <var>agent</var>, optionally with instructions to create a
105489105493
global object or a global <b>this</b> binding (or both), the following steps are taken:</p>
@@ -107962,58 +107966,49 @@ dictionary <dfn dictionary>ErrorEventInit</dfn> : <span>EventInit</span> {
107962107966

107963107967
<div w-nodev>
107964107968

107965-
<p>To <dfn>notify about rejected promises</dfn> on a given <span>environment settings object</span>
107966-
<var>settings object</var>:</p>
107969+
<p>To <dfn>notify about rejected promises</dfn> given a <span>global object</span>
107970+
<var>global</var>:</p>
107967107971

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

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

107974-
<li><p>Clear <var>settings object</var>'s <span>about-to-be-notified rejected promises
107975-
list</span>.</p></li>
107976-
107977-
<li><p>Let <var>global</var> be <var>settings object</var>'s <span
107978-
data-x="concept-settings-object-global">global object</span>.</p></li>
107978+
<li><p><span data-x="list empty">Empty</span> <var>global</var>'s <span>about-to-be-notified
107979+
rejected promises list</span>.</p></li>
107979107980

107980107981
<li>
107981107982
<p><span>Queue a global task</span> on the <span>DOM manipulation task source</span> given
107982-
<var>global</var> to run the following substep:</p>
107983+
<var>global</var> to run the following step:</p>
107983107984

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

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

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

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

108003-
<li><p>If <var>p</var>'s [[PromiseIsHandled]] internal slot is false, add <var>p</var> to
108004-
<var>settings object</var>'s <span>outstanding rejected promises weak set</span>.
108003+
<li><p>If <var>p</var>.[[PromiseIsHandled]] is false, then <span data-x="set
108004+
append">append</span> <var>p</var> to <var>global</var>'s <span>outstanding rejected
108005+
promises weak set</span>.</p></li>
108005108006
</ol>
108006108007
</li>
108007108008
</ol>
108008108009
</li>
108009108010
</ol>
108010108011

108011-
<p>This algorithm results in promise rejections being marked as <dfn
108012-
data-x="concept-promise-rejection-handled"><i>handled</i></dfn> or <dfn
108013-
data-x="concept-promise-rejection-nothandled"><i>not handled</i></dfn>. If a rejection is still
108014-
<i data-x="concept-promise-rejection-nothandled">not handled</i> after this, then the rejection
108015-
may be reported to a developer console.</p>
108016-
108017108012
<p id="the-promiserejectionevent-interface">The <code>PromiseRejectionEvent</code> interface is
108018108013
defined as follows:</p>
108019108014

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

109043-
<li><p>Let <var>settings object</var> be the <span>current settings object</span>.</p></li>
109038+
<li><p>Let <var>settingsObject</var> be the <span>current settings object</span>.</p></li>
109044109039

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

109044+
<li><p>Let <var>global</var> be <var>settingsObject</var>'s <span
109045+
data-x="concept-settings-object-global">global object</span>.</p></li>
109046+
109049109047
<li>
109050109048
<p>If <var>operation</var> is "<code data-x="">reject</code>", then:</p>
109051109049

109052109050
<ol>
109053-
<li><p><span data-x="list append">Append</span> <var>promise</var> to <var>settings
109054-
object</var>'s <span>about-to-be-notified rejected promises list</span>.</p></li>
109051+
<li><p><span data-x="list append">Append</span> <var>promise</var> to <var>global</var>'s
109052+
<span>about-to-be-notified rejected promises list</span>.</p></li>
109055109053
</ol>
109056109054
</li>
109057109055

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

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

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

109069-
<li><p><span data-x="list remove">Remove</span> <var>promise</var> from <var>settings
109070-
object</var>'s <span>outstanding rejected promises weak set</span>.</p></li>
109071-
109072-
<li><p>Let <var>global</var> be <var>settings object</var>'s <span
109073-
data-x="concept-settings-object-global">global object</span>.</p></li>
109067+
<li><p><span data-x="list remove">Remove</span> <var>promise</var> from <var>global</var>'s
109068+
<span>outstanding rejected promises weak set</span>.</p></li>
109074109069

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

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

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

0 commit comments

Comments
 (0)