archives

« Bugzilla Issues Index

#3249 — Superfluous HasLengthProperty call in Function.prototype.bind


https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.bind

> 5. Let targetHasLength be HasOwnProperty(Target, "length").
> 6. ReturnIfAbrupt(targetHasLength).
> 7. If targetHasLength is true, then
> a. Let targetLen be Get(Target, "length").
> b. ReturnIfAbrupt(targetLen).
> c. If Type(targetLen) is not Number, then let L be 0.
> d. Else,
> i. Let L be the larger of 0 and the result of targetLen minus
> the number of elements of A.
> 8. Else let L be 0.

It seems like we might as well strike steps 5, 6, and 8 and just do steps 7.a-d.


Also, Step 7.d.i refers to "the number of elements of A", but A isn't defined.


I don't think these steps are superfluous:

js> function f(a){}
js> f.length
1
js> f.bind().length
1
js> Object.defineProperty(Function.prototype, "length", {value: 100})
js> delete f.length
true
js> f.length
100
js> f.bind().length
0 // If steps 5, 6, and 8 are struck, this will be 100


(In reply to ziyunfei from comment #2)
> I don't think these steps are superfluous:
>
>

yes the "own" check is significant because length properties are configurable (ie, deletable)and functions can inherit from other functions (eg, vis class declarations).

fixed reference to A

but won't eliminate the HasLengthPrperty check