From 5ca38da66de00ca6efef307bcb39fc5037903221 Mon Sep 17 00:00:00 2001
From: Nicolas Lempereur <nle@odoo.com>
Date: Thu, 7 Nov 2019 10:23:57 +0000
Subject: [PATCH] [FIX] web: guardedCatch on IE Edge async return

In IE Edge async and await are supported, but guardedCatch is added to
polyfilled MyPromise object and async methods return original Promise so
depending of chain guardedCatch can cause en error or not.

It seems that historically, the MyPromise patching has also had issue in
firefox with it sometimes working or not.

In this changeset we completely remove it (which will have the drawback
of more error shown in console in firefox).

opw-1964486
opw-2116839
closes #39953

Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
---
 .../unhandled-rejection-polyfill.js           | 79 ++-----------------
 addons/web/views/webclient_templates.xml      |  1 -
 2 files changed, 5 insertions(+), 75 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 9422078ac370..8d1d79cd1242 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
@@ -1,75 +1,6 @@
-// based on https://github.com/ustccjw/unhandled-rejection-polyfill
-(function () {
-"use strict";
+/* TODO in master: remove file completely */
 
-var self = window;
-var OriginalPromise = self.Promise;
-
-function dispatchUnhandledRejectionEvent(promise, reason) {
-    var event = document.createEvent('Event');
-    Object.defineProperties(event, {
-        promise: {
-            value: promise,
-            writable: false,
-        },
-        reason: {
-            value: reason,
-            writable: false,
-        },
-    });
-    event.initEvent('unhandledrejection', false, true);
-    window.dispatchEvent(event);
-}
-
-function MyPromise(resolver) {
-    if (!(this instanceof MyPromise)) {
-        throw new TypeError('Cannot call a class as a function');
-    }
-    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) {
-                    dispatchUnhandledRejectionEvent(promise, reason);
-                }
-            }, 0);
-            return reject(reason);
-        };
-        try {
-            return resolver(resolve, customReject);
-        } catch (err) {
-            return customReject(err);
-        }
-    });
-    promise.__proto__ = MyPromise.prototype;
-    return promise;
-}
-
-MyPromise.__proto__ = OriginalPromise;
-MyPromise.prototype.__proto__ = OriginalPromise.prototype;
-
-
-MyPromise.prototype.then = function (resolve, reject) {
-    var self = this;
-    return OriginalPromise.prototype.then.call(this, resolve, reject && (function (reason) {
-        self.handled = true;
-        return reject(reason);
-    }));
-};
-
-MyPromise.prototype.catch = function (reject) {
-    var self = this;
-    return OriginalPromise.prototype.catch.call(this, reject && (function (reason) {
-        self.handled = true;
-        return reject(reason);
-    }));
-};
-
-MyPromise.polyfill = function () {
-    if (typeof PromiseRejectionEvent === 'undefined') {
-        window.Promise = MyPromise;
-    }
-};
-MyPromise.polyfill();
-
-})();
+// This file was emptied because functionality failed in some instances in
+// Firefox and cause some other issue in IE Edge and other (because of async
+// function not returning MyPromise but original browser Promise)
+// => drawback: now there will be more error in console in Firefox and IE Edge
diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml
index 89360a014f77..f85c5b15eae5 100644
--- a/addons/web/views/webclient_templates.xml
+++ b/addons/web/views/webclient_templates.xml
@@ -45,7 +45,6 @@
     <!-- boot.js script needs to work -->
     <template id="_assets_common_minimal_js">
         <script type="text/javascript" src="/web/static/lib/es6-promise/es6-promise-polyfill.js"></script>
-        <script type="text/javascript" src="/web/static/lib/unhandled-rejection-polyfill/unhandled-rejection-polyfill.js"></script>
         <script type="text/javascript" src="/web/static/src/js/promise_extension.js"></script>
         <script type="text/javascript" src="/web/static/src/js/boot.js"></script>
     </template>
-- 
GitLab