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

Editorial: add a SetFunctionLength abstract operation #1096

Merged
merged 6 commits into from
Apr 19, 2018

Conversation

tobie
Copy link
Contributor

@tobie tobie commented Feb 9, 2018

No description provided.

spec.html Outdated
<emu-alg>
1. Assert: _F_ is an extensible object that does not have a `length` own property.
1. Assert: Type(_length_) is Number.
1. Assert: ToLength(_length_) is equal to _length_.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unsure if that's the best way to assert that length is an integer within the right bounds.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks, this seems like a great cleanup.

1. Let _len_ be the ExpectedArgumentCount of _ParameterList_.
1. Perform ! DefinePropertyOrThrow(_F_, `"length"`, PropertyDescriptor{[[Value]]: _len_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true*}).
1. Perform ! SetFunctionLength(_F_, _len_).
Copy link
Contributor Author

@tobie tobie Feb 9, 2018

Choose a reason for hiding this comment

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

Not sure whether this should be prefixed with "!". I assume it should, but then SetFunctionName often isn't elsewhere in the spec and I'm not sure why.

Copy link
Collaborator

@jmdyck jmdyck Feb 10, 2018

Choose a reason for hiding this comment

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

If an operation cannot ever return an abrupt completion, then I'd say invocations of it shouldn't be preceded by '!'. It isn't wrong, but it's unnecessary clutter. (This would be more persuasive if you could easily tell from an operation's 'declaration' whether it ever returns an abrupt completion. See issue #253.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So just to clarify my understanding here:

While DefinePropertyOrThrow can throw in some circumstances, it can't in this case, because we know from the first assertion in SetFunctionLength that DefinePropertyOrThrow's first argument is extensible and doesn't have a length own prop which could interfere with setting.

Thus we know that SetFunctionLength won't ever throw.

Preceding an abstract operation call by "!" means that we are in a situation where an abstract operation won't throw, although it might do so in different circumstances.

Operations which never throw should never be prefixed with "!" even though we can't know from looking at the abstract operation's signature or its name that this is the case.

So for now, SetFunctionLength should not be prefixed with anything?

Is my understanding correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Your understanding matches mine. Whether it's correct is up to the editors.

Copy link
Member

Choose a reason for hiding this comment

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

I don't agree with this; I think we should use ! everywhere. (I am also not an editor.)

@tobie
Copy link
Contributor Author

tobie commented Feb 10, 2018

Thanks. As mentioned over irc, I'll make especially good use of it in WebIDL.

spec.html Outdated
</emu-alg>
</emu-clause>

<!-- es6num="9.2.13" -->
Copy link
Member

Choose a reason for hiding this comment

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

To my understanding we should not be moving/adding es6num since it is referring to where a clause was in the ES2015 specification: http://www.ecma-international.org/ecma-262/6.0/

Copy link
Member

@bmeck bmeck left a comment

Choose a reason for hiding this comment

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

LGTM except es6num

spec.html Outdated
1. Let _len_ be the ExpectedArgumentCount of _ParameterList_.
1. Perform ! DefinePropertyOrThrow(_F_, `"length"`, PropertyDescriptor{[[Value]]: _len_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true*}).
1. Perform SetFunctionLength(_F_, _len_).
Copy link
Member

@ljharb ljharb Feb 10, 2018

Choose a reason for hiding this comment

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

I disagree with the above; this should be prefixed with !.

Noise is less of a concern to me than not knowing whether an abstract operation might throw or not, at the callsite, without having to read the resulting operation definition - otherwise i’m not sure what the point of the ! is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you prefix all currently-unprefixed operation-invocations with "!"? There's about 2300 of them.

Alternatively, we could come up with a naming convention that distinguished those operations that can return abrupt completions from those that can't. That would convey the information you want to see at the invocation-point, in a maybe less obtrusive way.

Personally, I think I'd prefer if information about what the operation can return were only a click or mouse-hover away.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I wonder if we should move this discussion to a separate issue.)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, i would, and yes, I’d say that’d be a separate issue.

Copy link
Member

Choose a reason for hiding this comment

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

That there’s 2300 mean it’d be a tedious conversion; when I’m reading a specific part of the spec there wouldn’t be 2300 - there’d be just enough so I’d have to jump elsewhere as rarely as possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Separate issue now created: #1097

spec.html Outdated
@@ -24700,7 +24710,7 @@ <h1>Function.prototype.bind ( _thisArg_, ..._args_ )</h1>
1. Let _targetLen_ be ToInteger(_targetLen_).
1. Let _L_ be the larger of 0 and the result of _targetLen_ minus the number of elements of _args_.
1. Else, let _L_ be 0.
1. Perform ! DefinePropertyOrThrow(_F_, `"length"`, PropertyDescriptor {[[Value]]: _L_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true*}).
1. Perform SetFunctionLength(_F_, _L_).
Copy link
Member

Choose a reason for hiding this comment

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

This also needs a !

spec.html Outdated
<h1>SetFunctionLength ( _F_, _length_ )</h1>
<p>The abstract operation SetFunctionLength requires a Function argument _F_, and a Number argument _length_. This operation adds a `length` property to _F_ by performing the following steps:</p>
<emu-alg>
1. Assert: _F_ is an extensible object that does not have a `length` own property.
Copy link
Member

Choose a reason for hiding this comment

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

Should this also assert on IsCallable? Should it call the internal IsExtensible methodminstead of using “is extensible” prose?

Copy link
Contributor Author

@tobie tobie Feb 10, 2018

Choose a reason for hiding this comment

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

I copied the prose used elsewhere in the spec word for word. I suggest changing all of it in a separate pull request.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good :-)

@jmdyck jmdyck mentioned this pull request Feb 10, 2018
@tobie
Copy link
Contributor Author

tobie commented Feb 12, 2018

What's the outcome of the discussion as to whether calls to SetFunctionLength should be prefixed by "!" in this particular pull request? I don't have an opinion either way, but would like to be able to move forward with this PR.

spec.html Outdated
@@ -7535,6 +7534,17 @@ <h1>SetFunctionName ( _F_, _name_ [ , _prefix_ ] )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-setfunctionlength" aoid="SetFunctionLength">
<h1>SetFunctionLength ( _F_, _length_ )</h1>
<p>The abstract operation SetFunctionLength requires a Function argument _F_, and a Number argument _length_. This operation adds a `length` property to _F_ by performing the following steps:</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: No comma here because there only two arguments.

spec.html Outdated
<emu-alg>
1. Assert: _F_ is an extensible object that does not have a `length` own property.
1. Assert: Type(_length_) is Number.
1. Assert: ToLength(_length_) is equal to _length_.
Copy link
Contributor

Choose a reason for hiding this comment

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

ToLength is not correct here, because if called from Function.prototype.bind length can exceed 2^53-1. If a bounds check is wanted here, something like

  1. Assert: length ≥ 0 and ToInteger(length) is equal to length.

is necessary.

@ljharb
Copy link
Member

ljharb commented Feb 12, 2018

@tobie yes, please include the ! in this PR.

Copy link
Member

@littledan littledan left a comment

Choose a reason for hiding this comment

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

I think the PR is good as it is, though I'd still LGTM it with an extra !

@tobie
Copy link
Contributor Author

tobie commented Apr 7, 2018

Hey, any idea what the timeline looks like to get this merged in?

@bterlson
Copy link
Member

Sorry for the delay. It looks great.

FWIW I think we should be consistently using !/? operators until it is made more clear which abstract ops can never throw.

@bterlson bterlson merged commit 1b2cb5f into tc39:master Apr 19, 2018
@tobie tobie deleted the SetFunctionLength branch April 19, 2018 21:04
@tobie
Copy link
Contributor Author

tobie commented Apr 19, 2018

Thanks a lot. Getting put to good use here: whatwg/webidl#549. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants