[Pkg-javascript-commits] [pdf.js] 170/210: Added Promise.catch Fixed Promise so it rejects on uncaught exception Catch possible rejection on ViewHistory.setMultiple

David Prévot taffit at moszumanska.debian.org
Thu Jun 5 14:21:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch upstream
in repository pdf.js.

commit 37c3641fadd93a6c77f3a07b88ee8082b5d73c06
Author: Samuel Chantaraud <s.chantaraud at gmail.com>
Date:   Thu May 22 13:53:19 2014 -0400

    Added Promise.catch
    Fixed Promise so it rejects on uncaught exception
    Catch possible rejection on ViewHistory.setMultiple
---
 src/shared/util.js  | 17 +++++++++++++++--
 web/view_history.js |  4 ++--
 web/viewer.js       |  2 ++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/shared/util.js b/src/shared/util.js
index 1c3f21c..77d8d46 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -1011,7 +1011,7 @@ PDFJS.createPromiseCapability = createPromiseCapability;
 
 /**
  * Polyfill for Promises:
- * The following promise implementation tries to generally implment the
+ * The following promise implementation tries to generally implement the
  * Promise/A+ spec. Some notable differences from other promise libaries are:
  * - There currently isn't a seperate deferred and promise object.
  * - Unhandled rejections eventually show an error if they aren't handled.
@@ -1057,6 +1057,11 @@ PDFJS.createPromiseCapability = createPromiseCapability;
         });
       };
     }
+    if (typeof globalScope.Promise.prototype.catch !== 'function') {
+      globalScope.Promise.prototype.catch = function (onReject) {
+        return globalScope.Promise.prototype.then(undefined, onReject);
+      };
+    }
     return;
   }
 //#if !MOZCENTRAL
@@ -1180,7 +1185,11 @@ PDFJS.createPromiseCapability = createPromiseCapability;
   function Promise(resolver) {
     this._status = STATUS_PENDING;
     this._handlers = [];
-    resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
+    try {
+      resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
+    } catch (e) {
+      this._reject(e);
+    }
   }
   /**
    * Builds a promise that is resolved when all the passed in promises are
@@ -1307,6 +1316,10 @@ PDFJS.createPromiseCapability = createPromiseCapability;
       });
       HandlerManager.scheduleHandlers(this);
       return nextPromise;
+    },
+    
+    catch: function Promise_catch(onReject) {
+      return this.then(undefined, onReject);
     }
   };
 
diff --git a/web/view_history.js b/web/view_history.js
index c1992f2..6f2cce4 100644
--- a/web/view_history.js
+++ b/web/view_history.js
@@ -101,7 +101,7 @@ var ViewHistory = (function ViewHistoryClosure() {
         return;
       }
       this.file[name] = val;
-      this._writeToStorage();
+      return this._writeToStorage();
     },
 
     setMultiple: function ViewHistory_setMultiple(properties) {
@@ -111,7 +111,7 @@ var ViewHistory = (function ViewHistoryClosure() {
       for (var name in properties) {
         this.file[name] = properties[name];
       }
-      this._writeToStorage();
+      return this._writeToStorage();
     },
 
     get: function ViewHistory_get(name, defaultValue) {
diff --git a/web/viewer.js b/web/viewer.js
index b9fad00..6d92ad0 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1983,6 +1983,8 @@ function updateViewarea() {
       'zoom': normalizedScaleValue,
       'scrollLeft': intLeft,
       'scrollTop': intTop
+    }).catch(function() {
+      // unable to write to storage
     });
   });
   var href = PDFView.getAnchorUrl(pdfOpenParams);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list