Skip to content
Snippets Groups Projects
Commit 06273584 authored by Nicolas Lempereur's avatar Nicolas Lempereur
Browse files

[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

closes odoo/odoo#40154

X-original-commit: 5ca38da6
Signed-off-by: default avatarNicolas Lempereur (nle) <nle@odoo.com>
parent a1839fb3
No related branches found
No related tags found
No related merge requests found
MIT License
Copyright (c) 2017 ustccjw
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
// based on https://github.com/ustccjw/unhandled-rejection-polyfill
(function () {
"use strict";
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();
})();
......@@ -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>
......
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