Skip to content
Snippets Groups Projects
Commit 1ed3ce2b authored by Marius Dumitru Florea's avatar Marius Dumitru Florea
Browse files

XWIKI-22377: Prototype.js can still break the standard Array.from method

* Prevent Prototype.js from overriding Array.from, second try

(cherry picked from commit 8e8cf7ec)
parent 7dc3ed6b
No related branches found
No related tags found
No related merge requests found
...@@ -18,12 +18,25 @@ ...@@ -18,12 +18,25 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/ */
(function () { (function () {
// Code executed before Prototype.js is loaded. // We expect this code to be loaded right before Prototype.js code.
// Restore the original code, since Prototype.js is overriding the Array.from method. See
// https://github.com/prototypejs/prototype/issues/338. // Prevent Prototype.js from overriding the Array.from function.
const originalArrayFrom = Array.from; // See https://github.com/prototypejs/prototype/issues/338.
setTimeout(() => { let arrayFrom = Array.from;
// Code executed after Prototype.js is loaded. Object.defineProperty(Array, "from", {
Array.from = originalArrayFrom; get: () => arrayFrom,
}, 0); set: function(newArrayFrom) {
if (window.Prototype && newArrayFrom === window.$A) {
// Prototype.js tries to override the Array.from function.
// We delete the defined property because we don't want to to prevent anyone from overriding Array.from, we just
// want to prevent Prototype.js from doing it because we know that Prototype's implementation is outdated and
// causes new code to fail.
delete this.from;
this.from = arrayFrom;
} else {
// Allow others to override Array.from (their need may be valid, we don't know).
arrayFrom = newArrayFrom;
}
}
});
})(); })();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment