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

Reference impl: Use arrow functions for size functions #1142

Merged
merged 2 commits into from
Jul 7, 2021

Conversation

ninevra
Copy link
Contributor

@ninevra ninevra commented Jun 30, 2021

The reference implementation uses function expressions to create the size() functions for CountQueuingStrategy and ByteLengthQueuingStrategy, which results in them being constructible and having prototype properties. This PR changes to using arrow functions to better conform to the spec; see original discussion below:

Printing

new ByteLengthQueuingStrategy({ highWaterMark: 100 }).size.prototype

gives undefined in Chrome and Firefox. The Streams spec calls CreateBuiltinFunction without calling MakeConstructor, which is the abstract op that adds the prototype property. So it would appear that we should in fact use arrow functions after all

Originally posted by @TimothyGu in jsdom/jsdom#3200 (comment)

@ricea
Copy link
Collaborator

ricea commented Jun 30, 2021

This doesn't set the name property. I'm not sure if it's sufficient just to assign it after creating the function. @domenic what's the best thing to do here?

@MattiasBuelens
Copy link
Collaborator

Chrome and Firefox do seem to infer a name property from the variable assignment. But I don't think ECMAScript requires that, so it's probably not a good idea to rely on it for the reference implementation.

const size = () => 1;
size.name // -> "size"

@TimothyGu
Copy link
Member

ECMAScript does indeed require the name property to be set. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#inferred_function_names.

@ninevra
Copy link
Contributor Author

ninevra commented Jul 1, 2021

I do find this to be very odd and unexpected behavior, but it is required by ecmascript.

Relevant part of the spec, from 14.3.1.2 Runtime Semantics: Evaluation of let or const bindings:

3. If IsAnonymousFunctionDefinition(Initializer) is true, then
    a. Let value be NamedEvaluation of Initializer with argument bindingId.

capturing bindingId and passing it into the evaluation of the anonymous function expression, where it's eventually passed through to 15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression, and then to SetFunctionName.

Copy link
Collaborator

@ricea ricea left a comment

Choose a reason for hiding this comment

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

Thanks!

@ricea
Copy link
Collaborator

ricea commented Jul 1, 2021

@ninevra Sorry for the trouble, but could you sign the CLA? https://participate.whatwg.org/agreement-status?user=ninevra&repo=streams&pull=1142

@ricea
Copy link
Collaborator

ricea commented Jul 1, 2021

Optionally, if you could add a test to https://github.com/web-platform-tests/wpt/blob/master/streams/queuing-strategies.any.js that fails without this change it would be a big help.

@ninevra
Copy link
Contributor Author

ninevra commented Jul 1, 2021

@ricea I think I've already signed the CLA; it says I need to be verified?

I'll try to get a test submitted today.

domenic pushed a commit to web-platform-tests/wpt that referenced this pull request Jul 1, 2021
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jul 2, 2021
…ion prototype, constructibility, a=testonly

Automatic update from web-platform-tests
Add tests for QueuingStrategy size function prototype, constructibility

See whatwg/streams#1142.
--

wpt-commits: c7e9917fc03880d1bb217b99119a3c5d0fe65810
wpt-pr: 29555
@domenic domenic merged commit c46742f into whatwg:main Jul 7, 2021
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Jul 16, 2021
…ion prototype, constructibility, a=testonly

Automatic update from web-platform-tests
Add tests for QueuingStrategy size function prototype, constructibility

See whatwg/streams#1142.
--

wpt-commits: c7e9917fc03880d1bb217b99119a3c5d0fe65810
wpt-pr: 29555
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.

None yet

5 participants