From c7c1f53bef95490bc9f9ba130ea2ae3602f17b74 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Mon, 15 Apr 2024 14:11:56 +0200 Subject: [PATCH] [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) --- addons/web/static/src/polyfills/array.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/polyfills/array.js b/addons/web/static/src/polyfills/array.js index cff897c1792..9aaee003303 100644 --- a/addons/web/static/src/polyfills/array.js +++ b/addons/web/static/src/polyfills/array.js @@ -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]; - }; + }); }