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

Normative: change default function length value to not include optional arguments #266

Merged
merged 1 commit into from
Dec 20, 2015

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Dec 19, 2015

Fixes #264.

  • A few legacy methods that have deviating lengths are documented explicitly.
  • Any unneeded explicit lengths are removed.
  • Needed legacy explicit lengths are added.
  • Spacing inside optional argument brackets is made consistent
  • Fixed a bug with a DataView note having the wrong argument name
  • replaced two instances of a spreaded argument using an ellipsis with three dots

The DataView prototype get/set methods have inconsistent lengths across all browsers, so rather than select one of them as legacy, I decided to let them fall into the default category, which hopefully implementations will align with.

@ljharb
Copy link
Member Author

ljharb commented Dec 19, 2015

(I count 59 explicit length removals, 16 explicit length additions)

@domenic
Copy link
Member

domenic commented Dec 19, 2015

It would be good to list functions whose normative lengths have changed, even if we think their previous lengths were a bug.

@ljharb
Copy link
Member Author

ljharb commented Dec 19, 2015

The only functions that applies to is the DataView ones:

  • DataView.prototype.getFloat32 (sometimes 0 or 2, now 1)
  • DataView.prototype.getFloat64 (sometimes 0 or 2, now 1)
  • DataView.prototype.getInt16 (sometimes 0 or 2, now 1)
  • DataView.prototype.getInt32 (sometimes 0 or 2, now 1)
  • DataView.prototype.getUint16 (sometimes 0 or 2, now 1)
  • DataView.prototype.getUint32 (sometimes 0 or 2, now 1)
  • DataView.prototype.setFloat32 (sometimes 0 or 3, now 2)
  • DataView.prototype.setFloat64 (sometimes 0 or 3, now 2)
  • DataView.prototype.setInt16 (sometimes 0 or 3, now 2)
  • DataView.prototype.setInt32 (sometimes 0 or 3, now 2)
  • DataView.prototype.setUint16 (sometimes 0 or 3, now 2)
  • DataView.prototype.setUint32 (sometimes 0 or 3, now 2)

Note that the "int 8" methods had no optional arguments, and thus were always 2 - this brings all the DataView get and set methods into alignment with 1 for get, and 2 for set - since they all have the same number of required arguments respectively.

@domenic
Copy link
Member

domenic commented Dec 19, 2015

I thought e.g. Map's length changed, from previously 1 (since optional arguments were counted) to 0 (since now they are not).

@ljharb
Copy link
Member Author

ljharb commented Dec 19, 2015

Map has always had an explicit length of 0, per #264 (comment). There are very few instances of functions deviating from the proposed Chapter 17 language, and most are Date prototype methods.

<emu-note>
<p>For example, the function object that is the initial value of the `slice` property of the String prototype object is described under the subclause heading &ldquo;String.prototype.slice (start, end)&rdquo; which shows the two named arguments start and end; therefore the value of the `length` property of that Function object is `2`.</p>
<p>For example, the function object that is the initial value of the `map` property of the Array prototype object is described under the subclause heading «Array.prototype.map (callbackFn [ , thisArg])» which shows the two named arguments callbackFn and thisArg, the latter being optional; therefore the value of the `length` property of that Function object is `1`.</p>
Copy link
Member

Choose a reason for hiding this comment

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

This note's language is needlessly pedantic but you can leave it :-P

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 don't mind simplifying it, I just wanted to be explicit :-) Suggestions welcome.

@ljharb ljharb force-pushed the fix_function_length branch 4 times, most recently from 44343a5 to 3cf8b06 Compare December 20, 2015 19:01
@ljharb ljharb changed the title [Normative] change default function length value to not include optional arguments Normative: change default function length value to not include optional arguments Dec 20, 2015
@ljharb ljharb force-pushed the fix_function_length branch 3 times, most recently from 6761173 to 3fd722e Compare December 20, 2015 19:05
…al arguments.

Fixes tc39#264.

 - A few legacy methods that have deviating lengths are documented explicitly.
 - Any unneeded explicit lengths are removed.
 - Needed legacy explicit lengths are added.
 - Spacing inside optional argument brackets is made consistent
 - Fixed a bug with a `DataView` note having the wrong argument name

The DataView prototype get/set methods have inconsistent lengths across all browsers, so rather than select one of them as legacy, I decided to let them fall into the default category, which hopefully implementations will align with. Here are the changes:
 - DataView.prototype.getFloat32 (sometimes 0 or 2, now 1)
 - DataView.prototype.getFloat64 (sometimes 0 or 2, now 1)
 - DataView.prototype.getInt16 (sometimes 0 or 2, now 1)
 - DataView.prototype.getInt32 (sometimes 0 or 2, now 1)
 - DataView.prototype.getUint16 (sometimes 0 or 2, now 1)
 - DataView.prototype.getUint32 (sometimes 0 or 2, now 1)
 - DataView.prototype.setFloat32 (sometimes 0 or 3, now 2)
 - DataView.prototype.setFloat64 (sometimes 0 or 3, now 2)
 - DataView.prototype.setInt16 (sometimes 0 or 3, now 2)
 - DataView.prototype.setInt32 (sometimes 0 or 3, now 2)
 - DataView.prototype.setUint16 (sometimes 0 or 3, now 2)
 - DataView.prototype.setUint32 (sometimes 0 or 3, now 2)

Note that the "int 8" methods had no optional arguments, and thus were always 1 or 2 - this brings all the DataView get and set methods into alignment with 1 for get, and 2 for set - since they all have the same number of required arguments respectively.
@bterlson bterlson merged commit 5512445 into tc39:master Dec 20, 2015
@anba
Copy link
Contributor

anba commented Dec 20, 2015

Issues

  • length for Object.assign removed
  • length=1 for Number.prototype.toString missing
  • length for Math.min and Max.max removed, but Math.hypot unchanged
  • length for Date is defined as part of 20.3.3
  • length=7 for Date.UTC missing
  • %TypedArray%.prototype.set changed from 2 -> 1, why?
  • %TypedArray%.prototype.set should be below 22.2.3.22, not 22.2.3.22.1
  • length for DataView is defined as part of 24.2.3
  • JSON.parse and JSON.stringify length missing

@bterlson
Copy link
Member

...

@ljharb
Copy link
Member Author

ljharb commented Dec 20, 2015

oops, will fix momentarily in a new PR

@anba
Copy link
Contributor

anba commented Dec 20, 2015

I wanted to write proper review comments tomorrow, because I didn't expect this gets merged on a weekend. :-/ (The comments above are basically just my personal notes, that's why they're extra so brief. )

@ljharb
Copy link
Member Author

ljharb commented Dec 20, 2015

@anba re "length for Date is defined as part of 20.3.3" - should I remove it there and put it below the constructor like the rest?

@bterlson
Copy link
Member

Sorry @anba :( Hopefully everything can be fixed in a subsequent PR?

@anba
Copy link
Contributor

anba commented Dec 20, 2015

@ljharb I've just checked the other built-in constructors, except for the Array constructor, all constructor functions define their length property as part of the "Properties of the Constructor" section ("Besides the length property (whose value is ), the constructor has the following properties:"). I think I'd prefer if all built-in constructors have an explicit length definition (like the Array constructor), and the subordinate clauses in "Properties of the Constructor" are removed.

@bterlson No worries. 😄

ljharb added a commit to ljharb/ecma262 that referenced this pull request Dec 20, 2015
@ljharb
Copy link
Member Author

ljharb commented Dec 20, 2015

@anba agreed and done in the imminent PR!

@ljharb ljharb restored the fix_function_length branch December 20, 2015 19:38
ljharb added a commit to ljharb/ecma262 that referenced this pull request Dec 20, 2015
anba added a commit to anba/test262 that referenced this pull request Dec 22, 2015
- Add missing tests for "length" property of built-in functions
- Add missing tests for "name" property of built-in functions
- Add basic surface tests for NativeErrors
- Add basic surface tests for TypedArrays

Notes:
- Already uses the updated DataView function lengths from tc39/ecma262#266 (ES2016 Draft 2015-12-20)
anba added a commit to anba/test262 that referenced this pull request Jan 13, 2016
…tions

Note: Already uses the updated DataView function lengths from tc39/ecma262#266 (ES2016 Draft 2015-12-20)
anba added a commit to anba/test262 that referenced this pull request Jan 15, 2016
…tions

Note: Already uses the updated DataView function lengths from tc39/ecma262#266 (ES2016 Draft 2015-12-20)
@ljharb ljharb deleted the fix_function_length branch October 4, 2019 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants