Drop function-bind dependency with saving safety#17
Conversation
There was a problem hiding this comment.
Most people most likely already have it; it’s true that “most likely” means some people wont.
You’re also correct that in pre-ES5 engines, reliance on .call is unavoidable.
I don’t think this is a helpful change (worth the churn), but i agree it’s not a harmful/broken one.
Co-authored-by: Jordan Harband <ljharb@gmail.com>
|
"Most likely" should mean more than a half. I'm sure that it is not. Even |
|
https://npmjs.com/call-bind (18m) also depends on function-bind (23m, about the same as |
|
Anyway, it's not crucial since this PR removes 1KB from bundles that haven't other |
|
1.5 months and some tenths of millions harmful |
|
bytes aren't harm. |
|
Yes, they are extremely use 😂 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@ljharb unlike my approach, this your approach steals some milliseconds from the life of almost each internet user every day. |
|
Merged, thanks @zloirock Pushed 1.0.4 without the dependency |
|
@tarruda this is a breaking change; it should have been a v2, and v1 needs to keep the dependency. |
|
@ljharb Why is this a breaking change? The API and behavior are still the same |
|
@tarruda not in an ES3 environment where Function bind doesn't exist. That's the purpose of the dependency. If this dep is not restored, I'll have to replace |
|
@ljharb Isn´t this ternary operator already checking for the presence of |
|
In particular, it means it's no longer robust against |
|
|
|
How many |
|
I've stated my piece; i consider this a breaking change, and if it remains I'll have to drop |
|
@ljharb Do you have a test case which breaks on the new version and passes on the previous one? |
|
I'm traveling right now, so I'll need time to come up with it - suddenly merging and releasing a PR with nearly 2 years of silence is pretty jarring - but either way, on some level the effort may be better spent just migrating to something I can rely on for stability. |
|
@ljharb the arguments presented for merging this PR made sense to me, and I didn't see any counter arguments. If you have a test case showing that this change breaks compatibility, I would be happy to fix it. |
|
@tarruda sure. run: delete Function.prototype.bind;
var has = require("has@1.0.3");
Object.defineProperty(Function.prototype.call, 'call', { value: undefined });
has({}, 'toString') === false && has({toString:1}, 'toString');vs delete Function.prototype.bind;
var has = require("has@1.0.4");
Object.defineProperty(Function.prototype.call, 'call', { value: undefined });
has({}, 'toString') === false && has({toString:1}, 'toString'); |
|
Let's replace Object.defineProperty(Function.prototype.call, 'call', { value: undefined });to Object.defineProperty(Array.prototype.slice, 'call', { value: undefined });or delete Function.prototype.apply;or to many other alternative options. The new version is significantly more protected. If you see this as a breaking change, then a significant part of patch releases of your projects are also breaking. |
|
@ljharb I'm fine with breaking compatibility scenarios where the user is actively trying to destroy his JS context. We could protect against this situation by storing If you have a more realistic test case showing that |
|
I suppose I'll have to make my own package, then. It matters because no realistic JS program has a single author's code running in it - every environment has untrusted code running, and thus everyone should be protecting against malice. |
|
And for the sake of this, you insist on more vulnerable code. Everything is logical -) |
|
You are more than welcome to file issues on a project you find vulnerable to robustness concerns, as I do. |
|
Why, if without it this package will work better anyway and it won't be possible to implement such a level of safety with |


That reduces the minified size of the package from 1KB to a hundred bytes.
The argument about protection from
delete Function.prototype.calldoes not work here since in ES5+ engines.callis not used after loading, but in ES3 enginesfunction-binduse.callinternally anyway.The argument that "most likely you have
function-bindin your dependencies chain" also does not work - I haven't it in any other places.