Merge pull request #1122 from kkujala/refactor

Change throws to errors.
This commit is contained in:
notmasteryet 2012-01-30 18:35:35 -08:00
commit 2047fba8cb
7 changed files with 43 additions and 38 deletions

View File

@ -548,7 +548,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var fontObj = this.objs.get(fontRefName).fontObj; var fontObj = this.objs.get(fontRefName).fontObj;
if (!fontObj) { if (!fontObj) {
throw 'Can\'t find font for ' + fontRefName; error('Can\'t find font for ' + fontRefName);
} }
var name = fontObj.loadedName || 'sans-serif'; var name = fontObj.loadedName || 'sans-serif';
@ -866,7 +866,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
} else if (IR[0] == 'RadialAxial' || IR[0] == 'Dummy') { } else if (IR[0] == 'RadialAxial' || IR[0] == 'Dummy') {
var pattern = Pattern.shadingFromIR(this.ctx, IR); var pattern = Pattern.shadingFromIR(this.ctx, IR);
} else { } else {
throw 'Unkown IR type'; error('Unkown IR type ' + IR[0]);
} }
return pattern; return pattern;
}, },

View File

@ -410,14 +410,14 @@ var Page = (function PageClosure() {
if (callback) if (callback)
callback(e); callback(e);
else else
throw e; error(e);
} }
}.bind(this), }.bind(this),
function pageDisplayReadPromiseError(reason) { function pageDisplayReadPromiseError(reason) {
if (callback) if (callback)
callback(reason); callback(reason);
else else
throw reason; error(reason);
} }
); );
} }
@ -620,7 +620,7 @@ var PDFDoc = (function PDFDocClosure() {
if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') { if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
var workerSrc = PDFJS.workerSrc; var workerSrc = PDFJS.workerSrc;
if (typeof workerSrc === 'undefined') { if (typeof workerSrc === 'undefined') {
throw 'No PDFJS.workerSrc specified'; error('No PDFJS.workerSrc specified');
} }
try { try {
@ -716,7 +716,7 @@ var PDFDoc = (function PDFDocClosure() {
}); });
break; break;
default: default:
throw 'Got unkown object type ' + type; error('Got unkown object type ' + type);
} }
}, this); }, this);
@ -737,7 +737,7 @@ var PDFDoc = (function PDFDocClosure() {
if (page.displayReadyPromise) if (page.displayReadyPromise)
page.displayReadyPromise.reject(data.error); page.displayReadyPromise.reject(data.error);
else else
throw data.error; error(data.error);
}, this); }, this);
messageHandler.on('jpeg_decode', function(data, promise) { messageHandler.on('jpeg_decode', function(data, promise) {

View File

@ -1052,7 +1052,7 @@ var JpxImage = (function JpxImageClosure() {
} }
r = 0; r = 0;
} }
throw 'Out of packets'; error('JPX error: Out of packets');
}; };
} }
function ResolutionLayerComponentPositionIterator(context) { function ResolutionLayerComponentPositionIterator(context) {
@ -1091,7 +1091,7 @@ var JpxImage = (function JpxImageClosure() {
} }
l = 0; l = 0;
} }
throw 'Out of packets'; error('JPX error: Out of packets');
}; };
} }
function buildPackets(context) { function buildPackets(context) {
@ -1187,7 +1187,7 @@ var JpxImage = (function JpxImageClosure() {
new ResolutionLayerComponentPositionIterator(context); new ResolutionLayerComponentPositionIterator(context);
break; break;
default: default:
throw 'Unsupported progression order'; error('JPX error: Unsupported progression order ' + progressionOrder);
} }
} }
function parseTilePackets(context, data, offset, dataLength) { function parseTilePackets(context, data, offset, dataLength) {
@ -1589,7 +1589,7 @@ var JpxImage = (function JpxImageClosure() {
if (lbox == 0) if (lbox == 0)
lbox = length - position + headerSize; lbox = length - position + headerSize;
if (lbox < headerSize) if (lbox < headerSize)
throw 'Invalid box field size'; error('JPX error: Invalid box field size');
var dataLength = lbox - headerSize; var dataLength = lbox - headerSize;
var jumpDataLength = true; var jumpDataLength = true;
switch (tbox) { switch (tbox) {
@ -1675,7 +1675,7 @@ var JpxImage = (function JpxImageClosure() {
scalarExpounded = true; scalarExpounded = true;
break; break;
default: default:
throw 'Invalid SQcd value'; error('JPX error: Invalid SQcd value ' + sqcd);
} }
qcd.noQuantization = spqcdSize == 8; qcd.noQuantization = spqcdSize == 8;
qcd.scalarExpounded = scalarExpounded; qcd.scalarExpounded = scalarExpounded;
@ -1728,7 +1728,7 @@ var JpxImage = (function JpxImageClosure() {
scalarExpounded = true; scalarExpounded = true;
break; break;
default: default:
throw 'Invalid SQcd value'; error('JPX error: Invalid SQcd value ' + sqcd);
} }
qcc.noQuantization = spqcdSize == 8; qcc.noQuantization = spqcdSize == 8;
qcc.scalarExpounded = scalarExpounded; qcc.scalarExpounded = scalarExpounded;
@ -1795,7 +1795,7 @@ var JpxImage = (function JpxImageClosure() {
cod.terminationOnEachCodingPass || cod.terminationOnEachCodingPass ||
cod.verticalyStripe || cod.predictableTermination || cod.verticalyStripe || cod.predictableTermination ||
cod.segmentationSymbolUsed) cod.segmentationSymbolUsed)
throw 'Unsupported COD options: ' + uneval(cod); error('JPX error: Unsupported COD options: ' + uneval(cod));
if (context.mainHeader) if (context.mainHeader)
context.COD = cod; context.COD = cod;
@ -1840,7 +1840,7 @@ var JpxImage = (function JpxImageClosure() {
// skipping content // skipping content
break; break;
default: default:
throw 'Unknown codestream code: ' + code.toString(16); error('JPX error: Unknown codestream code: ' + code.toString(16));
} }
position += length; position += length;
} }

View File

@ -574,7 +574,7 @@ var XRef = (function XRefClosure() {
var stream, parser; var stream, parser;
if (e.uncompressed) { if (e.uncompressed) {
if (e.gen != gen) if (e.gen != gen)
throw ('inconsistent generation in XRef'); error('inconsistent generation in XRef');
stream = this.stream.makeSubStream(e.offset); stream = this.stream.makeSubStream(e.offset);
parser = new Parser(new Lexer(stream), true, this); parser = new Parser(new Lexer(stream), true, this);
var obj1 = parser.getObj(); 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 // If there isn't an object yet or the object isn't resolved, then the
// data isn't ready yet! // data isn't ready yet!
if (!obj || !obj.isResolved) { if (!obj || !obj.isResolved) {
throw 'Requesting object that isn\'t resolved yet ' + objId; error('Requesting object that isn\'t resolved yet ' + objId);
return null; return null;
} else { } else {
return obj.data; return obj.data;

View File

@ -821,15 +821,19 @@ var JpegStream = (function JpegStreamClosure() {
JpegStream.prototype.ensureBuffer = function jpegStreamEnsureBuffer(req) { JpegStream.prototype.ensureBuffer = function jpegStreamEnsureBuffer(req) {
if (this.bufferLength) if (this.bufferLength)
return; return;
var jpegImage = new JpegImage(); try {
if (this.colorTransform != -1) var jpegImage = new JpegImage();
jpegImage.colorTransform = this.colorTransform; if (this.colorTransform != -1)
jpegImage.parse(this.bytes); jpegImage.colorTransform = this.colorTransform;
var width = jpegImage.width; jpegImage.parse(this.bytes);
var height = jpegImage.height; var width = jpegImage.width;
var data = jpegImage.getData(width, height); var height = jpegImage.height;
this.buffer = data; var data = jpegImage.getData(width, height);
this.bufferLength = data.length; this.buffer = data;
this.bufferLength = data.length;
} catch (e) {
error('JPEG error: ' + e);
}
}; };
JpegStream.prototype.getIR = function jpegStreamGetIR() { JpegStream.prototype.getIR = function jpegStreamGetIR() {
return bytesToString(this.bytes); return bytesToString(this.bytes);

View File

@ -255,8 +255,8 @@ var Promise = (function PromiseClosure() {
return; return;
} }
if (this._data !== EMPTY_PROMISE) { if (this._data !== EMPTY_PROMISE) {
throw 'Promise ' + this.name + error('Promise ' + this.name +
': Cannot set the data of a promise twice'; ': Cannot set the data of a promise twice');
} }
this._data = value; this._data = value;
this.hasData = true; this.hasData = true;
@ -268,7 +268,7 @@ var Promise = (function PromiseClosure() {
get data() { get data() {
if (this._data === EMPTY_PROMISE) { 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; return this._data;
}, },
@ -283,10 +283,10 @@ var Promise = (function PromiseClosure() {
resolve: function promiseResolve(data) { resolve: function promiseResolve(data) {
if (this.isResolved) { 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) { if (this.isRejected) {
throw 'The Promise was already rejected ' + this.name; error('The Promise was already rejected ' + this.name);
} }
this.isResolved = true; this.isResolved = true;
@ -300,10 +300,10 @@ var Promise = (function PromiseClosure() {
reject: function proimseReject(reason) { reject: function proimseReject(reason) {
if (this.isRejected) { 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) { if (this.isResolved) {
throw 'The Promise was already resolved ' + this.name; error('The Promise was already resolved ' + this.name);
} }
this.isRejected = true; this.isRejected = true;
@ -317,7 +317,7 @@ var Promise = (function PromiseClosure() {
then: function promiseThen(callback, errback) { then: function promiseThen(callback, errback) {
if (!callback) { if (!callback) {
throw 'Requiring callback' + this.name; error('Requiring callback' + this.name);
} }
// If the promise is already resolved, call the callback directly. // If the promise is already resolved, call the callback directly.

View File

@ -26,7 +26,7 @@ function MessageHandler(name, comObj) {
delete callbacks[callbackId]; delete callbacks[callbackId];
callback(data.data); callback(data.data);
} else { } else {
throw 'Cannot resolve callback ' + callbackId; error('Cannot resolve callback ' + callbackId);
} }
} else if (data.action in ah) { } else if (data.action in ah) {
var action = ah[data.action]; var action = ah[data.action];
@ -44,7 +44,7 @@ function MessageHandler(name, comObj) {
action[0].call(action[1], data.data); action[0].call(action[1], data.data);
} }
} else { } 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) { on: function messageHandlerOn(actionName, handler, scope) {
var ah = this.actionHandler; var ah = this.actionHandler;
if (ah[actionName]) { if (ah[actionName]) {
throw 'There is already an actionName called "' + actionName + '"'; error('There is already an actionName called "' + actionName + '"');
} }
ah[actionName] = [handler, scope]; ah[actionName] = [handler, scope];
}, },
@ -208,6 +208,7 @@ var workerConsole = {
action: 'console_error', action: 'console_error',
data: args data: args
}); });
throw 'pdf.js execution error';
}, },
time: function time(name) { time: function time(name) {
@ -217,7 +218,7 @@ var workerConsole = {
timeEnd: function timeEnd(name) { timeEnd: function timeEnd(name) {
var time = consoleTimer[name]; var time = consoleTimer[name];
if (time == null) { if (time == null) {
throw 'Unkown timer name ' + name; error('Unkown timer name ' + name);
} }
this.log('Timer:', name, Date.now() - time); this.log('Timer:', name, Date.now() - time);
} }