[FIX] web: properly define at method in array polyfill
Commit [1] introduced a fix for old browsers to make the `at` method of the Array class. It did so by simply adding a property on the prototype of the Array class. Unfortunately this way of adding a method means that it is exposed in `for...in` loops. To avoid this, this commit uses Object.defineProperty and sets the property as not enumerable, removing it from the for..in loop. [1]: https://github.com/odoo/odoo/commit/6e39e31030c28a8eb09ddcd93ca9ca382b4f6f10 opw-3824593 closes odoo/odoo#161891 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
if (!Array.prototype.at) {
|
||||
Array.prototype.at = function (index) {
|
||||
if (index >= 0) {
|
||||
return this[index];
|
||||
Object.defineProperty(Array.prototype, "at", {
|
||||
enumerable: false,
|
||||
value: function (index) {
|
||||
if (index >= 0) {
|
||||
return this[index];
|
||||
}
|
||||
return this[this.length + index];
|
||||
}
|
||||
return this[this.length + index];
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user