RESOLVED FIXED 162377
test262: Function length should be number of parameters before parameters with default values
https://bugs.webkit.org/show_bug.cgi?id=162377
Summary test262: Function length should be number of parameters before parameters wit...
Joseph Pecoraro
Reported 2016-09-22 01:11:32 PDT
Summary: Function length should be number of parameters before parameters with default values Spec: https://tc39.github.io/ecma262/#sec-function-definitions-static-semantics-expectedargumentcount > NOTE: The ExpectedArgumentCount of a FormalParameterList is the number of > FormalParameters to the left of either the rest parameter or the first > FormalParameter with an Initializer. A FormalParameter without an > initializer is allowed after the first parameter with an initializer > but such parameters are considered to be optional with undefined as > their default value. Example: // foo.length should be 1 function foo(a,b=1,c) {}; Notes: - Applies to all functions (getters/setters, generators, methods, arrow functions) - setters require 1 param, but that can have a default value so this needs to be handled - getters require 0 params, so are not affected Covered by 32 tst262 tests with "*-dflt-length.js" in the name.
Attachments
[PATCH] Proposed Fix (53.68 KB, patch)
2016-09-22 01:16 PDT, Joseph Pecoraro
saam: review+
joepeck: commit-queue-
[PATCH] For Landing (54.19 KB, patch)
2016-09-22 11:49 PDT, Joseph Pecoraro
no flags
Joseph Pecoraro
Comment 1 2016-09-22 01:16:03 PDT
Created attachment 289535 [details] [PATCH] Proposed Fix
Joseph Pecoraro
Comment 2 2016-09-22 01:20:19 PDT
Comment on attachment 289535 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=289535&action=review > Source/JavaScriptCore/ChangeLog:19 > + Alongside the parameterCount value, maintain a separate count, > + nonDefaultParameterCount, which will be the count before seeing > + a rest parameter or initialized parameter. Of course after I wrote the patch "nonDefaultParameterCount" is a kind of poor name since (1) you can have non-default-parameters after the first default-parameter and (2) a rest parameter affects this but is not a default parameter. function (a,b=1,c) {} // length === 1 I'm open to better naming suggestions! Here are some suggestions: parameterCountForLength parameterCountForFunctionLength parameterCountBeforeInitializedParameter
Saam Barati
Comment 3 2016-09-22 09:03:29 PDT
Comment on attachment 289535 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=289535&action=review r=me > JSTests/stress/es6-default-parameters.js:236 > +function named11(a=1,...b){}; Can you also add a test like: (a=10, b, c=20, ...r) or something similar. >> Source/JavaScriptCore/ChangeLog:19 >> + a rest parameter or initialized parameter. > > Of course after I wrote the patch "nonDefaultParameterCount" is a kind of poor name since (1) you can have non-default-parameters after the first default-parameter and (2) a rest parameter affects this but is not a default parameter. > > function (a,b=1,c) {} // length === 1 > > I'm open to better naming suggestions! > > Here are some suggestions: > > parameterCountForLength > parameterCountForFunctionLength > parameterCountBeforeInitializedParameter Why not just "functionLength"?
Joseph Pecoraro
Comment 4 2016-09-22 11:49:36 PDT
Created attachment 289589 [details] [PATCH] For Landing
WebKit Commit Bot
Comment 5 2016-09-22 12:13:39 PDT
Comment on attachment 289589 [details] [PATCH] For Landing Clearing flags on attachment: 289589 Committed r206268: <http://trac.webkit.org/changeset/206268>
Note You need to log in before you can comment on or make changes to this bug.