Re: [heycam/webidl] Add the ability to construct a callback function (#328)

bzbarsky commented on this pull request.



> @@ -12374,6 +12374,56 @@ described in the previous section).
             |rejectedPromise| to the callback function's return type.
 </div>
 
+Some callback functions are instead used as constructors. Such callback functions must not have
+a return type that is a [=promise type=].
+
+<div algorithm>
+
+    To <dfn id="construct-a-callback-function" export>construct</dfn> a
+    [=callback function type=] value |callable| with
+    a list of arguments |arg|<sub>0..|n|−1</sub>, each of which is either
+    an IDL value or the special value “missing” (representing a missing optional argument),
+    perform the following steps.
+    These steps will either return an IDL value or throw an exception.
+
+    1.  Let |completion| be an uninitialized variable.

So this algorithm is pretty similar to <https://heycam.github.io/webidl/#invoke-a-callback-function>.  I wonder whether it's worth trying to factor parts of it out...  I guess the main similarity is the preparation (after the basic sanity-check, which is different) and the argument conversions, right?

Maybe that's not enough to worry about it.

> +                href="#construct-return"><i>return</i></a>.
+            1.  Append |convertResult|.\[[Value]] to |esArgs|.
+            1.  Set |count| to |i| + 1.
+        1.  Set |i| to |i| + 1.
+    1.  Truncate |esArgs| to have length |count|.
+    1.  Let |callResult| be [=Construct=](|F|, |esArgs|).
+    1.  If |callResult| is an abrupt completion, set |completion| to
+        |callResult| and jump to the step labeled <a href="#construct-return"><i>return</i></a>.
+    1.  Set |completion| to the result of [=converted to an IDL value|converting=]
+        |callResult|.\[[Value]] to an IDL value of the same type as the operation’s
+        return type.
+    1.  <i id="construct-return">Return:</i> at this
+        point |completion| will be set to an ECMAScript completion value.
+        1.  [=Clean up after running a callback=] with |stored settings|.
+        1.  [=Clean up after running script=] with |relevant settings|.
+        1.  Return |completion|.

Up front we said "These steps will either return an IDL value or throw an exception."  But we're actually returning an ES completion value... I'm not sure how to reconcile those.

Of course I'm also not sure in what sense "converting callResult.[[Value]] to an IDL value" returns an ES completion value...

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/pull/328#pullrequestreview-28773806

Received on Thursday, 23 March 2017 20:54:45 UTC