Description
derived from tc39/proposal-idl#9 (comment)
While looking into introducing IDL into ECMAScript, the existence of the explicit function length ('The "length" property of this function is ...' paragraph') becomes slightly problematic, especially when the length doesn't match the parameter notation, given it requires extra annotation on the IDL.
If the length property is not programatically used in wild, dropping the explicit function length and always using the implicit length will make things simpler.
Here's the list of affected cases:
Function | Explicit length | Implicit length |
---|---|---|
Object ( [ value ] ) |
1 | 0 |
Object.assign ( target, ...sources ) |
2 | 1 |
Number.prototype.toString ( [ radix ] ) |
1 | 0 |
Math.hypot ( ...args ) |
2 | 0 |
Math.max ( ...args ) |
2 | 0 |
Math.min ( ...args ) |
2 | 0 |
Date ( ...values ) |
7 | 0 |
Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ) |
7 | 1 |
Date.prototype.setFullYear ( year [ , month [ , date ] ] ) |
3 | 1 |
Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ) |
4 | 1 |
Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ) |
3 | 1 |
Date.prototype.setMonth ( month [ , date ] ) |
2 | 1 |
Date.prototype.setSeconds ( sec [ , ms ] ) |
2 | 1 |
Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] ) |
3 | 1 |
Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] ) |
4 | 1 |
Date.prototype.setUTCMinutes ( min [ , sec [ , ms ] ] ) |
3 | 1 |
Date.prototype.setUTCMonth ( month [ , date ] ) |
2 | 1 |
Date.prototype.setUTCSeconds ( sec [ , ms ] ) |
2 | 1 |
String.fromCharCode ( ...codeUnits ) |
1 | 0 |
String.fromCodePoint ( ...codePoints ) |
1 | 0 |
String.prototype.concat ( ...args ) |
1 | 0 |
Array ( ...values ) |
1 | 0 |
Array.prototype.concat ( ...items ) |
1 | 0 |
Array.prototype.push ( ...items ) |
1 | 0 |
Array.prototype.unshift ( ...items ) |
1 | 0 |
Int8Array ( ...args ) |
3 | 0 |
Uint8Array ( ...args ) |
3 | 0 |
Uint8ClampedArray ( ...args ) |
3 | 0 |
Int16Array ( ...args ) |
3 | 0 |
Uint16Array ( ...args ) |
3 | 0 |
Int32Array ( ...args ) |
3 | 0 |
Uint32Array ( ...args ) |
3 | 0 |
BigInt64Array ( ...args ) |
3 | 0 |
BigUint64Array ( ...args ) |
3 | 0 |
Float16Array ( ...args ) |
3 | 0 |
Float32Array ( ...args ) |
3 | 0 |
Float64Array ( ...args ) |
3 | 0 |
JSON.parse ( text [ , reviver ] ) |
2 | 1 |
JSON.stringify ( value [ , replacer [ , space ] ] ) |
3 | 1 |
Array
, Date
, _TypedArray_
s are using a kind of overloading (#2176), and they may want to use different notation given introducing IDL will allow overloading.
Also, Function
-related constructors are possibly-affected. I'm not sure if the implicit length should take the bodyArg
into account or not.
At least WebIDL doesn't allow non-optional parameter after variadic parameter.
Function | Explicit length | Implicit length |
---|---|---|
Function ( ...parameterArgs, bodyArg ) |
1 | 0? |
GeneratorFunction ( ...parameterArgs, bodyArg ) |
1 | 0? |
AsyncGeneratorFunction ( ...parameterArgs, bodyArg ) |
1 | 0? |
AsyncFunction ( ...parameterArgs, bodyArg ) |
1 | 0? |
Also, there are some cases where the explicit length match the implicit length, which could just simply be removed:
%TypedArray% ()
- (ECMA402)
String.prototype.localeCompare ( that [ , locales [ , options ] ] )
If necessary, we could look into telemetry or some script corpus to see if the built-in function length is actually accessed by scripts in wild, to see the impact of this change.
#264 suggests that modifying the built-in functions' length properties won't cause too much web-compat issues.
also, #1078 suggests we might still want some explicit length property for anonymous function, but the specific case touched by the issue is already rewritten with CreateBuiltinFunction
call.