From 0bae5e24020a1eebb2a4d790f76d1a17de9f6ac1 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 7 Mar 2019 10:34:02 +0000 Subject: [PATCH] [FIX] web: bad conversion from ES6 to ES5 We had to manually convert the unhandled-rejection-polyfill lib, and we forgot to replace this by self in two arrow functions. This was causing crashes e.g. on Firefox. We also forgot some uses of const, which is not really an issue as const is supported on all browsers, but it is not ES5. Issue reported on the jquery update pad. closes odoo/odoo#31658 Signed-off-by: VincentSchippefilt --- .../unhandled-rejection-polyfill.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/web/static/lib/unhandled-rejection-polyfill/unhandled-rejection-polyfill.js b/addons/web/static/lib/unhandled-rejection-polyfill/unhandled-rejection-polyfill.js index 16b5125fe27..5d1786e69ec 100644 --- a/addons/web/static/lib/unhandled-rejection-polyfill/unhandled-rejection-polyfill.js +++ b/addons/web/static/lib/unhandled-rejection-polyfill/unhandled-rejection-polyfill.js @@ -2,11 +2,11 @@ (function () { "use strict"; -const self = window; -const OriginalPromise = self.Promise; +var self = window; +var OriginalPromise = self.Promise; function dispatchUnhandledRejectionEvent(promise, reason) { - const event = document.createEvent('Event'); + var event = document.createEvent('Event'); Object.defineProperties(event, { promise: { value: promise, @@ -25,8 +25,8 @@ function MyPromise(resolver) { if (!(this instanceof MyPromise)) { throw new TypeError('Cannot call a class as a function'); } - const promise = new OriginalPromise(function (resolve, reject) { - const customReject = function (reason) { + var promise = new OriginalPromise(function (resolve, reject) { + var customReject = function (reason) { // macro-task (setTimeout) will execute after micro-task (promise) setTimeout(function () { if (promise.handled !== true) { @@ -50,15 +50,17 @@ MyPromise.prototype.__proto__ = OriginalPromise.prototype; MyPromise.prototype.then = function (resolve, reject) { + var self = this; return OriginalPromise.prototype.then.call(this, resolve, reject && (function reason() { - this.handled = true; + self.handled = true; return reject(reason); })); }; MyPromise.prototype.catch = function (reject) { + var self = this; return OriginalPromise.prototype.catch.call(this, reject && (function reason() { - this.handled = true; + self.handled = true; return reject(reason); })); };