-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(filters): always call splice()
with 2 arguments or more
#14489
fix(filters): always call splice()
with 2 arguments or more
#14489
Conversation
When calling `.splice()` without a 2nd argument (`deleteCount`), most browsers will splice to the end of the array. As it turns out, this is the behavior specified in [ES2015][es6]. In [ES5][es5], the spec seems to imply that nothing should happen. To avoid inconsistent behavior among browsers implementing different versions of the EcmaScript standart or when ES5 shims are included (e.g. https://github.com/es-shims/es5-shim/), this commit ensures that all calls to `.splice()` provide at least two arguments. [es5]: http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.12 [es6]: http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.splice Fixes angular#14467
(From a quick grepping through the codebase, these seem to be the only places where we called splice with less than 2 arguments.) |
LGTM. We should lool into an eslint task for that once we switch. |
When calling `.splice()` without a 2nd argument (`deleteCount`), most browsers will splice to the end of the array. As it turns out, this is the behavior specified in [ES2015][es6]. In [ES5][es5], the spec seems to imply that nothing should happen. To avoid inconsistent behavior among browsers implementing different versions of the EcmaScript standart or when ES5 shims are included (e.g. https://github.com/es-shims/es5-shim/), this commit ensures that all calls to `.splice()` provide at least two arguments. [es5]: http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.12 [es6]: http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.splice Fixes #14467 Closes #14489
When calling `.splice()` without a 2nd argument (`deleteCount`), most browsers will splice to the end of the array. As it turns out, this is the behavior specified in [ES2015][es6]. In [ES5][es5], the spec seems to imply that nothing should happen. To avoid inconsistent behavior among browsers implementing different versions of the EcmaScript standart or when ES5 shims are included (e.g. https://github.com/es-shims/es5-shim/), this commit ensures that all calls to `.splice()` provide at least two arguments. [es5]: http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.12 [es6]: http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.splice Fixes #14467 Closes #14489
Can we add such specific rules to eslint ? |
There is no built-in rule for that AFAIK (see http://eslint.org/docs/rules/) but if this is a real difference and browsers differ in behavior then perhaps we could get one landed in ESLint core, similar to the I'd like to see which browsers behave in which way, though, before doing anything about that. |
AFAIK, all browsers do it like ES6 (I didn't test with IE8, but that's not supported anyway). It might not be worth it putting too much effort in it, since it will only affect a very small minority (and people are probably going to move to es6-shim soon enough). |
If no browsers follow ES5 behavior here then es5-shim should stop patching that in considering what ES6 says. I'd rather get it fixed there rather than us working around bad shims. |
Browsers follow ES2015 or rather they have implemented the common sense
|
IMO es5-shim shouldn't implement things in a way invalidated by future Michał Gołębiowski |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.
What is the current behavior? (You can also link to an open issue here)
#14467
What is the new behavior (if this is a feature change)?
Consistent behavior in ES5 and ES6 environments.
Does this PR introduce a breaking change?
No.
Please check if the PR fulfills these requirements
Tests for the changes have been added (for bug fixes / features)Docs have been added / updated (for bug fixes / features)Other information:
When calling
.splice()
without a 2nd argument (deleteCount
), most browsers will splice to the end of the array. As it turns out, this is the behavior specified in ES2015. In ES5, the spec seems to imply that nothing should happen.To avoid inconsistent behavior among browsers implementing different versions of the EcmaScript standart or when ES5 shims are included (e.g. https://github.com/es-shims/es5-shim/), this commit ensures that all calls to
.splice()
provide at least two arguments.Fixes #14467