Permalink
Browse files

Change throws to errors.

  • Loading branch information...
1 parent 67769f3 commit 66e3441e0eccc2bea2d608fd02f1c4795f1c02f6 @kkujala committed Jan 24, 2012
Showing with 42 additions and 38 deletions.
  1. +2 −2 src/canvas.js
  2. +5 −5 src/core.js
  3. +8 −8 src/jpx.js
  4. +2 −2 src/obj.js
  5. +13 −9 src/stream.js
  6. +8 −8 src/util.js
  7. +4 −4 src/worker.js
View
4 src/canvas.js
@@ -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;
},
View
10 src/core.js
@@ -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) {
View
16 src/jpx.js
@@ -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;
}
View
4 src/obj.js
@@ -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;
View
22 src/stream.js
@@ -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);
View
16 src/util.js
@@ -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.
View
8 src/worker.js
@@ -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);
}

0 comments on commit 66e3441

Please sign in to comment.