diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-07-12 10:42:41 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-07-12 10:42:41 +0200 |
commit | 7c9d845d9b8009fd00a3b2bc628ac8978ab6a202 (patch) | |
tree | 8744b7974878136bfef5c42f8b12fdb7e6872535 /modules/luci-base/htdocs/luci-static | |
parent | d01cdd98bb3d122eaa423e07c5bd066b6347b405 (diff) |
luci-base: luci.js: add Promise.finally polyfill
Fixes: #2854
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/luci.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 6659bc51b6..259679f137 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -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 */ |