luci-base: luci.js: add Promise.finally polyfill

Fixes: #2854
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-07-12 10:42:41 +02:00
parent d01cdd98bb
commit 7c9d845d9b

View file

@ -23,6 +23,20 @@
});
}
/* Promise.finally polyfill */
if (typeof Promise.prototype.finally !== 'function') {
Promise.prototype.finally = function(fn) {
var onFinally = function(cb) {
return Promise.resolve(fn.call(this)).then(cb);
};
return this.then(
function(result) { return onFinally.call(this, function() { return result }) },
function(reason) { return onFinally.call(this, function() { return Promise.reject(reason) }) }
);
};
}
/*
* Class declaration and inheritance helper
*/