Skip to content

Commit 192be41

Browse files
authored
Allow users of "invoke a callback function" to report the exception
This makes it more concise for users to, as is frequently desired for undefined-returning callbacks especially, immediately catch and report the exception rather than needing to handle it themselves. This isn't appropriate for other types of callback functions, where a result may be expected or the exception needs to be rethrown. Callers need to explicitly decide which behavior they want, unless the callback returns a promise type, in which case exceptions are turned into rejected promises implicitly. Fixes #1423, except for updating the call sites.
1 parent 155ae10 commit 192be41

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

index.bs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14399,11 +14399,22 @@ described in the previous section).
1439914399
<div algorithm>
1440014400

1440114401
To <dfn id="invoke-a-callback-function" export>invoke</dfn> a
14402-
[=callback function type=] value |callable| with a [=Web IDL arguments list=] |args|
14402+
[=callback function type=] value |callable| with a [=Web IDL arguments list=] |args|,
14403+
exception behavior |exceptionBehavior| (either "<code>report</code>" or "<code>rethrow</code>"),
1440314404
and an optional [=callback this value|callback this value=] |thisArg|,
1440414405
perform the following steps.
1440514406
These steps will either return an IDL value or throw an exception.
1440614407

14408+
The |exceptionBehavior| argument must be supplied if, and only if, |callable|'s
14409+
[=return type=] is not a [=promise type=]. If |callable|'s return type is neither
14410+
{{undefined}} nor {{any}}, it must be "<code>rethrow</code>".
14411+
14412+
<div class="XXX">
14413+
Until call sites are updated to respect this, specifications which fail to
14414+
provide a value here when it would be mandatory should be understood as
14415+
supplying "<code>rethrow</code>".
14416+
</div>
14417+
1440714418
1. Let |completion| be an uninitialized variable.
1440814419
1. If |thisArg| was not given, let |thisArg| be <emu-val>undefined</emu-val>.
1440914420
1. Let |F| be the JavaScript object corresponding to |callable|.
@@ -14433,8 +14444,13 @@ described in the previous section).
1443314444
1. [=Clean up after running a callback=] with |stored settings|.
1443414445
1. [=Clean up after running script=] with |relevant settings|.
1443514446
1. If |completion| is an IDL value, return |completion|.
14436-
1. If |completion| is an [=abrupt completion=] and the callback function has a
14437-
[=return type=] that is <em>not</em> a [=promise type=], throw |completion|.\[[Value]].
14447+
1. [=Assert=]: |completion| is an [=abrupt completion=].
14448+
1. If |exceptionBehavior| is "<code>rethrow</code>", throw |completion|.\[[Value]].
14449+
1. Otherwise, if |exceptionBehavior| is "<code>report</code>":
14450+
1. [=Assert=]: |callable|'s [=return type=] is {{undefined}} or {{any}}.
14451+
1. [=Report an exception=] |completion|.\[[Value]] for |realm|'s [=realm/global object=].
14452+
1. Return the unique {{undefined}} IDL value.
14453+
1. [=Assert=]: |callable|'s [=return type=] is a [=promise type=].
1443814454
1. Let |rejectedPromise| be [=!=] <a abstract-op>Call</a>({{%Promise.reject%}},
1443914455
{{%Promise%}}, «|completion|.\[[Value]]»).
1444014456
1. Return the result of [=converted to an IDL value|converting=]

0 commit comments

Comments
 (0)