luci-base: luci.js: add Promise.finally polyfill
authorJo-Philipp Wich <jo@mein.io>
Fri, 12 Jul 2019 08:42:41 +0000 (10:42 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 12 Jul 2019 08:42:41 +0000 (10:42 +0200)
Fixes: #2854
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 6659bc51b67b4428245ed449d7d876ad1e7e5b1c..259679f137ee452a3f6ce8ddf123004cc974b008 100644 (file)
                });
        }
 
+       /* 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
         */