-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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_. |
There was a problem hiding this comment.
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.
There was a problem hiding this 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_). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
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" --> |
There was a problem hiding this comment.
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/
There was a problem hiding this 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_). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_). |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good :-)
What's the outcome of the discussion as to whether calls to |
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> |
There was a problem hiding this comment.
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_. |
There was a problem hiding this comment.
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
- Assert: length ≥ 0 and ToInteger(length) is equal to length.
is necessary.
@tobie yes, please include the ! in this PR. |
There was a problem hiding this 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 !
Hey, any idea what the timeline looks like to get this merged in? |
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. |
Thanks a lot. Getting put to good use here: whatwg/webidl#549. :) |
No description provided.