Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to construct a callback function #328

Merged
merged 3 commits into from
Mar 27, 2017
Merged

Conversation

domenic
Copy link
Member

@domenic domenic commented Mar 23, 2017

This helps move some of the heavy lifting into IDL, to avoid issues like whatwg/html#2381.


Preview | Diff

This helps move some of the heavy lifting into IDL, to avoid issues like whatwg/html#2381.
index.bs Outdated
perform the following steps.
These steps will either return an IDL value or throw an exception.

1. Let |completion| be an uninitialized variable.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I factored out the arguments conversion, which I think factors the most cleanly. The rest varies a bit too much IMO.

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|.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a preexisting "problem" that ideally I'd like to not fix in this PR.

Personally I think it is OK for specs to treat returning completion values and traditional return/throw flow the same way, without an explicit conversion step. (And similarly, treating return/flow throw as returning completion values.) It's a bit strange that the ES completion record holds a Web IDL value, but IMO fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could mention this equivalence and our expanded use of ES completion values in the conventions section.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we seem to mix that up all over the place. I guess we should define it more clearly. Maybe that's yet another thing for the infra standard?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having an explicit equivalence here is fine, fwiw. We should just do that.

Copy link
Collaborator

@tobie tobie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the WebIDL arg refactoring. That's pretty neat.

We should indeed clean-up the completion story. I'm wondering whether that's something for WebIDL to define more precisely, or for the infra standard flow control.

index.bs Outdated
A <dfn>Web IDL arguments list</dfn> is a [=list=] of values each of which is either an IDL value or
the special value “missing”, which represents a missing optional argument.

<div algorithm="convert an IDL arguments list to an ECMAScript arguments list">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have a dfn within the algorithm, you don't need to give the algorithm attribute a value.

index.bs Outdated
1. [=list/Append=] |convertResult| to |esArgs|.
1. Set |count| to |i| + 1.
1. Set |i| to |i| + 1.
1. [=list/Remove=] all items from |esArgs| except the first |count|, so that |esArgs|'s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Truncate" is a lot clearer to read, even though it's not defined in infra. Should it be defined there? (see whatwg/infra#100)

|args|[|i|] to an ECMAScript value. Rethrow any exceptions.
1. [=list/Append=] |convertResult| to |esArgs|.
1. Set |count| to |i| + 1.
1. Set |i| to |i| + 1.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increment? (see whatwg/infra#99).

<a href="#construct-return"><i>return</i></a>.
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>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we use steps labelled "return" all over the place. I still find that icky. Of course we shouldn't change it here.

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|.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we seem to mix that up all over the place. I guess we should define it more clearly. Maybe that's yet another thing for the infra standard?

Copy link
Collaborator

@bzbarsky bzbarsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modulo Tobie's comment, this looks great. Thank you!

@domenic domenic merged commit 36b3646 into master Mar 27, 2017
@domenic domenic deleted the construct-helper branch March 27, 2017 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants