Skip to content

Commit

Permalink
Update uses of Web IDL "invoke a callback function"
Browse files Browse the repository at this point in the history
It's now required for non-promise-returning uses to specify how exceptions are handled. Also make the way it is called more consistent.

Part of whatwg/webidl#1425.

Co-authored-by: Domenic Denicola <d@domenic.me>
  • Loading branch information
jeremyroman and domenic authored Aug 7, 2024
1 parent 8c74909 commit a607170
Showing 1 changed file with 30 additions and 55 deletions.
85 changes: 30 additions & 55 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -64478,7 +64478,7 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
<ref>FILEAPI</ref></p></li>

<li><p><span data-x="es-invoking-callback-functions">Invoke</span> <var>callback</var> with
« <var>result</var> ».</p></li>
« <var>result</var> » and "<code data-x="">report</code>".</p></li>
</ol>
</li>
</ol>
Expand Down Expand Up @@ -72939,13 +72939,9 @@ customElements.define("x-foo", class extends HTMLElement {
<dt><span>callback reaction</span></dt>
<dd>
<p><span data-x="es-invoking-callback-functions">Invoke</span> <var>reaction</var>'s
callback function with <var>reaction</var>'s arguments, and with <var>element</var> as
the <span data-x="dfn-callback-this-value">callback this value</span>.</p>

<p>If this throws an exception, catch it, and <span data-x="report an
exception">report</span> it for <var>reaction</var>'s callback function's corresponding
JavaScript object's <span>associated realm</span>'s <span
data-x="concept-realm-global">global object</span>.</p>
callback function with <var>reaction</var>'s arguments and "<code
data-x="">report</code>", and <i data-x="dfn-callback-this-value">callback this value</i>
set to <var>element</var>.</p>
</dd>
</dl>
</li>
Expand Down Expand Up @@ -111507,37 +111503,32 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
<p>Process the <code>Event</code> object <var>event</var> as follows:</p>

<dl class="switch">

<dt>If <var>special error event handling</var> is true</dt>

<dd>
<p><span data-x="es-invoking-callback-functions">Invoke</span> <var>callback</var> with five
arguments, the first one having the value of <var>event</var>'s <code
data-x="dom-ErrorEvent-message">message</code> attribute, the second having the value of
<var>event</var>'s <code data-x="dom-ErrorEvent-filename">filename</code> attribute, the third
having the value of <var>event</var>'s <code data-x="dom-ErrorEvent-lineno">lineno</code>
attribute, the fourth having the value of <var>event</var>'s <code
data-x="dom-ErrorEvent-colno">colno</code> attribute, the fifth having the value of
<var>event</var>'s <code data-x="dom-ErrorEvent-error">error</code> attribute, and with the <i
<p>Let <var>return value</var> be the result of <span
data-x="es-invoking-callback-functions">invoking</span> <var>callback</var> with «
<var>event</var>'s <code data-x="dom-ErrorEvent-message">message</code>, <var>event</var>'s
<code data-x="dom-ErrorEvent-filename">filename</code>, <var>event</var>'s <code
data-x="dom-ErrorEvent-lineno">lineno</code>, <var>event</var>'s <code
data-x="dom-ErrorEvent-colno">colno</code>, <var>event</var>'s <code
data-x="dom-ErrorEvent-error">error</code> », "<code data-x="">rethrow</code>", and with <i
data-x="dfn-callback-this-value">callback this value</i> set to <var>event</var>'s <code
data-x="dom-Event-currentTarget">currentTarget</code>. Let <var>return value</var> be the
callback's return value. <ref>WEBIDL</ref></p>
data-x="dom-Event-currentTarget">currentTarget</code>.</p>
</dd>

<dt>Otherwise</dt>

<dd>
<p><span data-x="es-invoking-callback-functions">Invoke</span> <var>callback</var>
with one argument, the value of which is the <code>Event</code> object <var>event</var>,
with the <i data-x="dfn-callback-this-value">callback this value</i> set to <var>event</var>'s
<code data-x="dom-Event-currentTarget">currentTarget</code>. Let <var>return value</var> be
the callback's return value. <ref>WEBIDL</ref></p>
<p>Let <var>return value</var> be the result of <span
data-x="es-invoking-callback-functions">invoking</span> <var>callback</var> with «
<var>event</var> », "<code data-x="">rethrow</code>", and with <i
data-x="dfn-callback-this-value">callback this value</i> set to <var>event</var>'s <code
data-x="dom-Event-currentTarget">currentTarget</code>.</p>
</dd>
</dl>

<p>If an exception gets thrown by the callback, end these steps and allow the exception to
propagate. (It will propagate to the <span data-x="concept-event-dispatch">DOM event dispatch
logic</span>, which will then <span data-x="report an exception">report</span> it.)</p>
<p class="note">If an exception gets thrown by the callback, it will be rethrown, ending these
steps. The exception will propagate to the <span data-x="concept-event-dispatch">DOM event
dispatch logic</span>, which will then <span data-x="report an exception">report</span> it.</p>
</li>

<li>
Expand Down Expand Up @@ -113702,17 +113693,10 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
<li><p><span>Record timing info for timer handler</span> given <var>handler</var>, <var>global</var>'s
<span>relevant settings object</span>, and <var>repeat</var>.</p></li>

<li>
<p>If <var>handler</var> is a <code data-x="idl-Function">Function</code>, then <span
data-x="es-invoking-callback-functions">invoke</span> <var>handler</var> given
<var>arguments</var> with the <span data-x="dfn-callback-this-value">callback this
value</span> set to <var>thisArg</var>. If this throws an exception, catch it, and <span
data-x="report an exception">report</span> it for <var>handler</var>'s corresponding
JavaScript object's <span>associated realm</span>'s <span
data-x="concept-realm-global">global object</span>.</p>

<p class="note">This global object not necessarily the same as <var>global</var>, if
<var>handler</var> comes from another <span>realm</span>.</p>
<li><p>If <var>handler</var> is a <code data-x="idl-Function">Function</code>, then <span
data-x="es-invoking-callback-functions">invoke</span> <var>handler</var> given
<var>arguments</var> and "<code data-x="">report</code>", and with <i
data-x="dfn-callback-this-value">callback this value</i> set to <var>thisArg</var>.</p>
</li>

<li>
Expand Down Expand Up @@ -113958,12 +113942,7 @@ scheduleWork(); // queues a task to do lots of work</code></pre>
<p w-nodev>The <dfn method for="WindowOrWorkerGlobalScope"><code
data-x="dom-queueMicrotask">queueMicrotask(<var>callback</var>)</code></dfn> method must
<span>queue a microtask</span> to <span data-x="es-invoking-callback-functions">invoke</span>
<var>callback</var>, and if <var>callback</var> throws an exception, <span data-x="report an
exception">report</span> it for <var>callback</var>'s corresponding JavaScript object's
<span>associated realm</span>'s <span data-x="concept-realm-global">global object</span>.</p>

<p w-nodev class="note">This global object not necessarily the same as <span>this</span>, if
<var>callback</var> comes from another <span>realm</span>.</p>
<var>callback</var> with « » and "<code data-x="">report</code>".</p>

<p>The <code data-x="dom-queueMicrotask">queueMicrotask()</code> method allows authors to schedule
a callback on the <span>microtask queue</span>. This allows their code to run once the
Expand Down Expand Up @@ -116107,13 +116086,8 @@ interface mixin <dfn interface>AnimationFrameProvider</dfn> {
<li><p><span data-x="map remove">Remove</span>
<var>callbacks</var>[<var>handle</var>].</p></li>

<li><p><span data-x="es-invoking-callback-functions">Invoke</span> <var>callback</var>, passing
<var>now</var> as the only argument, and if an exception is thrown,
<span data-x="report an exception">report</span> it for <var>callback</var>'s
corresponding JavaScript object's <span>associated realm</span>'s
<span data-x="concept-realm-global">global object</span>.</p>
<p class="note">This global object not necessarily the same as <var>this</var>, if
<var>callback</var> comes from another <span>realm</span>.</p></li>
<li><p><span data-x="es-invoking-callback-functions">Invoke</span> <var>callback</var> with «
<var>now</var> » and "<code data-x="">report</code>".</p></li>
</ol>
</li>
</ol>
Expand Down Expand Up @@ -120410,8 +120384,9 @@ window.fakeWorklet1.addModule("script.mjs");</code></pre>
data-x="idl-Function">Function</code> instance.</p></li>

<li><p>Return the result of <span data-x="es-invoking-callback-functions">invoking</span>
<var>callback</var> with the arguments « true » and with <var>classInstance</var> as the <span
data-x="dfn-callback-this-value">callback this value</span>.</p></li>
<var>callback</var> with « true » and "<code data-x="">rethrow</code>", and with <i
data-x="dfn-callback-this-value">callback this value</i> set to
<var>classInstance</var>.</p></li>
</ol>

<p class="note">Another, perhaps better, specification architecture would be to extract the "<code
Expand Down

0 comments on commit a607170

Please sign in to comment.