]> git.parisson.com Git - pdf.js.git/commitdiff
Change throws to errors.
authorKalervo Kujala <kkujala@com>
Tue, 24 Jan 2012 20:04:59 +0000 (22:04 +0200)
committerKalervo Kujala <kkujala@com>
Tue, 24 Jan 2012 20:10:16 +0000 (22:10 +0200)
src/canvas.js
src/core.js
src/jpx.js
src/obj.js
src/stream.js
src/util.js
src/worker.js

index 5ef9008610a2b0b12c3978a0b9d516e97476bd05..d0b0064f6b1d98ce6cecf8113266dbd613dbd086 100644 (file)
@@ -548,7 +548,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
       var fontObj = this.objs.get(fontRefName).fontObj;
 
       if (!fontObj) {
-        throw 'Can\'t find font for ' + fontRefName;
+        error('Can\'t find font for ' + fontRefName);
       }
 
       var name = fontObj.loadedName || 'sans-serif';
@@ -866,7 +866,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
       } else if (IR[0] == 'RadialAxial' || IR[0] == 'Dummy') {
         var pattern = Pattern.shadingFromIR(this.ctx, IR);
       } else {
-        throw 'Unkown IR type';
+        error('Unkown IR type ' + IR[0]);
       }
       return pattern;
     },
index 7a9f3ee03094d12bb12c64af2bd946e7ecf7502f..df38c086f687db3b1e44ca06c2e82b026fcc5768 100644 (file)
@@ -410,14 +410,14 @@ var Page = (function PageClosure() {
             if (callback)
               callback(e);
             else
-              throw e;
+              error(e);
           }
         }.bind(this),
         function pageDisplayReadPromiseError(reason) {
           if (callback)
             callback(reason);
           else
-            throw reason;
+            error(reason);
         }
       );
     }
@@ -620,7 +620,7 @@ var PDFDoc = (function PDFDocClosure() {
     if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
       var workerSrc = PDFJS.workerSrc;
       if (typeof workerSrc === 'undefined') {
-        throw 'No PDFJS.workerSrc specified';
+        error('No PDFJS.workerSrc specified');
       }
 
       try {
@@ -716,7 +716,7 @@ var PDFDoc = (function PDFDocClosure() {
             });
             break;
           default:
-            throw 'Got unkown object type ' + type;
+            error('Got unkown object type ' + type);
         }
       }, this);
 
@@ -737,7 +737,7 @@ var PDFDoc = (function PDFDocClosure() {
         if (page.displayReadyPromise)
           page.displayReadyPromise.reject(data.error);
         else
-          throw data.error;
+          error(data.error);
       }, this);
 
       messageHandler.on('jpeg_decode', function(data, promise) {
index 61a8f44871919a6b5507b5b8ff4fa4d278521014..c212c6fd062bc3cd22b2725e659635cf83b1f111 100644 (file)
@@ -1052,7 +1052,7 @@ var JpxImage = (function JpxImageClosure() {
         }
         r = 0;
       }
-      throw 'Out of packets';
+      error('Out of packets');
     };
   }
   function ResolutionLayerComponentPositionIterator(context) {
@@ -1091,7 +1091,7 @@ var JpxImage = (function JpxImageClosure() {
         }
         l = 0;
       }
-      throw 'Out of packets';
+      error('Out of packets');
     };
   }
   function buildPackets(context) {
@@ -1187,7 +1187,7 @@ var JpxImage = (function JpxImageClosure() {
           new ResolutionLayerComponentPositionIterator(context);
         break;
       default:
-        throw 'Unsupported progression order';
+        error('Unsupported progression order ' + progressionOrder);
     }
   }
   function parseTilePackets(context, data, offset, dataLength) {
@@ -1589,7 +1589,7 @@ var JpxImage = (function JpxImageClosure() {
         if (lbox == 0)
           lbox = length - position + headerSize;
         if (lbox < headerSize)
-          throw 'Invalid box field size';
+          error('Invalid box field size');
         var dataLength = lbox - headerSize;
         var jumpDataLength = true;
         switch (tbox) {
@@ -1675,7 +1675,7 @@ var JpxImage = (function JpxImageClosure() {
                 scalarExpounded = true;
                 break;
               default:
-                throw 'Invalid SQcd value';
+                error('Invalid SQcd value ' + sqcd);
             }
             qcd.noQuantization = spqcdSize == 8;
             qcd.scalarExpounded = scalarExpounded;
@@ -1728,7 +1728,7 @@ var JpxImage = (function JpxImageClosure() {
                 scalarExpounded = true;
                 break;
               default:
-                throw 'Invalid SQcd value';
+                error('Invalid SQcd value ' + sqcd);
             }
             qcc.noQuantization = spqcdSize == 8;
             qcc.scalarExpounded = scalarExpounded;
@@ -1795,7 +1795,7 @@ var JpxImage = (function JpxImageClosure() {
                 cod.terminationOnEachCodingPass ||
                 cod.verticalyStripe || cod.predictableTermination ||
                 cod.segmentationSymbolUsed)
-              throw 'Unsupported COD options: ' + uneval(cod);
+              error('Unsupported COD options: ' + uneval(cod));
 
             if (context.mainHeader)
               context.COD = cod;
@@ -1840,7 +1840,7 @@ var JpxImage = (function JpxImageClosure() {
             // skipping content
             break;
           default:
-            throw 'Unknown codestream code: ' + code.toString(16);
+            error('Unknown codestream code: ' + code.toString(16));
         }
         position += length;
       }
index ef79325469baf56ac58193edfffe9c58aff30ec9..5b87fec13d8c7539d66e24c651e92449616d27e0 100644 (file)
@@ -574,7 +574,7 @@ var XRef = (function XRefClosure() {
       var stream, parser;
       if (e.uncompressed) {
         if (e.gen != gen)
-          throw ('inconsistent generation in XRef');
+          error('inconsistent generation in XRef');
         stream = this.stream.makeSubStream(e.offset);
         parser = new Parser(new Lexer(stream), true, this);
         var obj1 = parser.getObj();
@@ -703,7 +703,7 @@ var PDFObjects = (function PDFObjectsClosure() {
       // If there isn't an object yet or the object isn't resolved, then the
       // data isn't ready yet!
       if (!obj || !obj.isResolved) {
-        throw 'Requesting object that isn\'t resolved yet ' + objId;
+        error('Requesting object that isn\'t resolved yet ' + objId);
         return null;
       } else {
         return obj.data;
index 610a54d38fe2c99bcbb034627f259883be49e423..c7b7c83e666d4ad9041dff324e9ef18f86c534de 100644 (file)
@@ -821,15 +821,19 @@ var JpegStream = (function JpegStreamClosure() {
   JpegStream.prototype.ensureBuffer = function jpegStreamEnsureBuffer(req) {
     if (this.bufferLength)
       return;
-    var jpegImage = new JpegImage();
-    if (this.colorTransform != -1)
-      jpegImage.colorTransform = this.colorTransform;
-    jpegImage.parse(this.bytes);
-    var width = jpegImage.width;
-    var height = jpegImage.height;
-    var data = jpegImage.getData(width, height);
-    this.buffer = data;
-    this.bufferLength = data.length;
+    try {
+      var jpegImage = new JpegImage();
+      if (this.colorTransform != -1)
+        jpegImage.colorTransform = this.colorTransform;
+      jpegImage.parse(this.bytes);
+      var width = jpegImage.width;
+      var height = jpegImage.height;
+      var data = jpegImage.getData(width, height);
+      this.buffer = data;
+      this.bufferLength = data.length;
+    } catch (e) {
+      error(e);
+    }
   };
   JpegStream.prototype.getIR = function jpegStreamGetIR() {
     return bytesToString(this.bytes);
index 99b422296bba454b0a472b5065c48aa0f0e1ad7e..759908e9e2de6f68dba2afe112fafd5394538ec5 100644 (file)
@@ -255,8 +255,8 @@ var Promise = (function PromiseClosure() {
         return;
       }
       if (this._data !== EMPTY_PROMISE) {
-        throw 'Promise ' + this.name +
-                                ': Cannot set the data of a promise twice';
+        error('Promise ' + this.name +
+              ': Cannot set the data of a promise twice');
       }
       this._data = value;
       this.hasData = true;
@@ -268,7 +268,7 @@ var Promise = (function PromiseClosure() {
 
     get data() {
       if (this._data === EMPTY_PROMISE) {
-        throw 'Promise ' + this.name + ': Cannot get data that isn\'t set';
+        error('Promise ' + this.name + ': Cannot get data that isn\'t set');
       }
       return this._data;
     },
@@ -283,10 +283,10 @@ var Promise = (function PromiseClosure() {
 
     resolve: function promiseResolve(data) {
       if (this.isResolved) {
-        throw 'A Promise can be resolved only once ' + this.name;
+        error('A Promise can be resolved only once ' + this.name);
       }
       if (this.isRejected) {
-        throw 'The Promise was already rejected ' + this.name;
+        error('The Promise was already rejected ' + this.name);
       }
 
       this.isResolved = true;
@@ -300,10 +300,10 @@ var Promise = (function PromiseClosure() {
 
     reject: function proimseReject(reason) {
       if (this.isRejected) {
-        throw 'A Promise can be rejected only once ' + this.name;
+        error('A Promise can be rejected only once ' + this.name);
       }
       if (this.isResolved) {
-        throw 'The Promise was already resolved ' + this.name;
+        error('The Promise was already resolved ' + this.name);
       }
 
       this.isRejected = true;
@@ -317,7 +317,7 @@ var Promise = (function PromiseClosure() {
 
     then: function promiseThen(callback, errback) {
       if (!callback) {
-        throw 'Requiring callback' + this.name;
+        error('Requiring callback' + this.name);
       }
 
       // If the promise is already resolved, call the callback directly.
index 4d9dd1bb637a96c68398ca0015689eae9a63df5a..f9777d7df576a48447d976ce1bd969bf3b9af981 100644 (file)
@@ -26,7 +26,7 @@ function MessageHandler(name, comObj) {
         delete callbacks[callbackId];
         callback(data.data);
       } else {
-        throw 'Cannot resolve callback ' + callbackId;
+        error('Cannot resolve callback ' + callbackId);
       }
     } else if (data.action in ah) {
       var action = ah[data.action];
@@ -44,7 +44,7 @@ function MessageHandler(name, comObj) {
         action[0].call(action[1], data.data);
       }
     } else {
-      throw 'Unkown action from worker: ' + data.action;
+      error('Unkown action from worker: ' + data.action);
     }
   };
 }
@@ -53,7 +53,7 @@ MessageHandler.prototype = {
   on: function messageHandlerOn(actionName, handler, scope) {
     var ah = this.actionHandler;
     if (ah[actionName]) {
-      throw 'There is already an actionName called "' + actionName + '"';
+      error('There is already an actionName called "' + actionName + '"');
     }
     ah[actionName] = [handler, scope];
   },
@@ -217,7 +217,7 @@ var workerConsole = {
   timeEnd: function timeEnd(name) {
     var time = consoleTimer[name];
     if (time == null) {
-      throw 'Unkown timer name ' + name;
+      error('Unkown timer name ' + name);
     }
     this.log('Timer:', name, Date.now() - time);
   }