Skip to content

Commit

Permalink
Removes error()
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Jun 28, 2017
1 parent d6a6f39 commit 72232e8
Show file tree
Hide file tree
Showing 23 changed files with 300 additions and 249 deletions.
30 changes: 15 additions & 15 deletions src/core/cff_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import {
assert, bytesToString, error, info, isArray, stringToBytes, Util, warn
assert, bytesToString, FormatError, info, isArray, stringToBytes, Util, warn
} from '../shared/util';
import {
ExpertCharset, ExpertSubsetCharset, ISOAdobeCharset
Expand Down Expand Up @@ -291,8 +291,9 @@ var CFFParser = (function CFFParserClosure() {
++offset;
}
if (offset >= bytesLength) {
error('Invalid CFF header');
} else if (offset !== 0) {
throw new FormatError('Invalid CFF header');
}
if (offset !== 0) {
info('cff data is shifted');
bytes = bytes.subarray(offset);
this.bytes = bytes;
Expand Down Expand Up @@ -750,7 +751,7 @@ var CFFParser = (function CFFParserClosure() {
}
break;
default:
error('Unknown charset format');
throw new FormatError('Unknown charset format');
}
// Raw won't be needed if we actually compile the charset.
var end = pos;
Expand Down Expand Up @@ -811,8 +812,8 @@ var CFFParser = (function CFFParserClosure() {
break;

default:
error('Unknown encoding format: ' + format + ' in CFF');
break;
throw new FormatError(
`Unknown encoding format: ${format} in CFF`);
}
var dataEnd = pos;
if (format & 0x80) { // hasSupplement
Expand Down Expand Up @@ -869,8 +870,8 @@ var CFFParser = (function CFFParserClosure() {
}
break;
default:
error('parseFDSelect: Unknown format "' + format + '".');
break;
throw new FormatError(
`parseFDSelect: Unknown format "${format}".`);
}
assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');

Expand Down Expand Up @@ -999,7 +1000,7 @@ var CFFDict = (function CFFDictClosure() {
},
setByName: function CFFDict_setByName(name, value) {
if (!(name in this.nameToKeyMap)) {
error('Invalid dictionary name "' + name + '"');
throw new FormatError(`Invalid dictionary name "${name}"`);
}
this.values[this.nameToKeyMap[name]] = value;
},
Expand All @@ -1008,7 +1009,7 @@ var CFFDict = (function CFFDictClosure() {
},
getByName: function CFFDict_getByName(name) {
if (!(name in this.nameToKeyMap)) {
error('Invalid dictionary name "' + name + '"');
throw new FormatError(`Invalid dictionary name ${name}"`);
}
var key = this.nameToKeyMap[name];
if (!(key in this.values)) {
Expand Down Expand Up @@ -1182,7 +1183,7 @@ var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
},
track: function CFFOffsetTracker_track(key, location) {
if (key in this.offsets) {
error('Already tracking location of ' + key);
throw new FormatError(`Already tracking location of ${key}`);
}
this.offsets[key] = location;
},
Expand All @@ -1195,7 +1196,7 @@ var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
values,
output) {
if (!(key in this.offsets)) {
error('Not tracking location of ' + key);
throw new FormatError(`Not tracking location of ${key}`);
}
var data = output.data;
var dataOffset = this.offsets[key];
Expand All @@ -1209,7 +1210,7 @@ var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
// It's easy to screw up offsets so perform this sanity check.
if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
error('writing to an offset that is not empty');
throw new FormatError('writing to an offset that is not empty');
}
var value = values[i];
data[offset0] = 0x1d;
Expand Down Expand Up @@ -1520,8 +1521,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
}
break;
default:
error('Unknown data type of ' + type);
break;
throw new FormatError(`Unknown data type of ${type}`);
}
}
out = out.concat(dict.opcodes[key]);
Expand Down
26 changes: 13 additions & 13 deletions src/core/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

import {
assert, CMapCompressionType, error, isInt, isString, MissingDataException,
Util, warn
assert, CMapCompressionType, FormatError, isInt, isString,
MissingDataException, Util, warn
} from '../shared/util';
import { isCmd, isEOF, isName, isStream } from './primitives';
import { Lexer } from './parser';
Expand Down Expand Up @@ -354,19 +354,19 @@ var IdentityCMap = (function IdentityCMapClosure() {
addCodespaceRange: CMap.prototype.addCodespaceRange,

mapCidRange(low, high, dstLow) {
error('should not call mapCidRange');
throw new Error('should not call mapCidRange');
},

mapBfRange(low, high, dstLow) {
error('should not call mapBfRange');
throw new Error('should not call mapBfRange');
},

mapBfRangeToArray(low, high, array) {
error('should not call mapBfRangeToArray');
throw new Error('should not call mapBfRangeToArray');
},

mapOne(src, dst) {
error('should not call mapCidOne');
throw new Error('should not call mapCidOne');
},

lookup(code) {
Expand Down Expand Up @@ -403,7 +403,7 @@ var IdentityCMap = (function IdentityCMapClosure() {
},

get isIdentityCMap() {
error('should not access .isIdentityCMap');
throw new Error('should not access .isIdentityCMap');
},
};

Expand Down Expand Up @@ -472,7 +472,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
do {
var b = this.readByte();
if (b < 0) {
error('unexpected EOF in bcmap');
throw new FormatError('unexpected EOF in bcmap');
}
last = !(b & 0x80);
n = (n << 7) | (b & 0x7F);
Expand All @@ -494,7 +494,7 @@ var BinaryCMapReader = (function BinaryCMapReaderClosure() {
do {
var b = this.readByte();
if (b < 0) {
error('unexpected EOF in bcmap');
throw new FormatError('unexpected EOF in bcmap');
}
last = !(b & 0x80);
stack[sp++] = b & 0x7F;
Expand Down Expand Up @@ -711,13 +711,13 @@ var CMapFactory = (function CMapFactoryClosure() {

function expectString(obj) {
if (!isString(obj)) {
error('Malformed CMap: expected string.');
throw new FormatError('Malformed CMap: expected string.');
}
}

function expectInt(obj) {
if (!isInt(obj)) {
error('Malformed CMap: expected int.');
throw new FormatError('Malformed CMap: expected int.');
}
}

Expand Down Expand Up @@ -770,7 +770,7 @@ var CMapFactory = (function CMapFactoryClosure() {
break;
}
}
error('Invalid bf range.');
throw new FormatError('Invalid bf range.');
}

function parseCidChar(cMap, lexer) {
Expand Down Expand Up @@ -832,7 +832,7 @@ var CMapFactory = (function CMapFactoryClosure() {
var high = strToInt(obj);
cMap.addCodespaceRange(obj.length, low, high);
}
error('Invalid codespace range.');
throw new FormatError('Invalid codespace range.');
}

function parseWMode(cMap, lexer) {
Expand Down
48 changes: 26 additions & 22 deletions src/core/colorspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* limitations under the License.
*/

import { error, info, isArray, isString, shadow, warn } from '../shared/util';
import {
FormatError, info, isArray, isString, shadow, warn
} from '../shared/util';
import { isDict, isName, isStream } from './primitives';
import { PDFFunction } from './function';

Expand Down Expand Up @@ -55,7 +57,7 @@ var ColorSpace = (function ColorSpaceClosure() {

// Constructor should define this.numComps, this.defaultColor, this.name
function ColorSpace() {
error('should not call ColorSpace constructor');
throw new Error('should not call ColorSpace constructor');
}

ColorSpace.prototype = {
Expand All @@ -75,7 +77,7 @@ var ColorSpace = (function ColorSpaceClosure() {
*/
getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
dest, destOffset) {
error('Should not call ColorSpace.getRgbItem');
throw new Error('Should not call ColorSpace.getRgbItem');
},
/**
* Converts the specified number of the color values to the RGB colors.
Expand All @@ -89,7 +91,7 @@ var ColorSpace = (function ColorSpaceClosure() {
getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
dest, destOffset, bits,
alpha01) {
error('Should not call ColorSpace.getRgbBuffer');
throw new Error('Should not call ColorSpace.getRgbBuffer');
},
/**
* Determines the number of bytes required to store the result of the
Expand All @@ -98,7 +100,7 @@ var ColorSpace = (function ColorSpaceClosure() {
*/
getOutputLength: function ColorSpace_getOutputLength(inputLength,
alpha01) {
error('Should not call ColorSpace.getOutputLength');
throw new Error('Should not call ColorSpace.getOutputLength');
},
/**
* Returns true if source data will be equal the result/output data.
Expand Down Expand Up @@ -254,9 +256,8 @@ var ColorSpace = (function ColorSpaceClosure() {
var range = IR[3];
return new LabCS(whitePoint, blackPoint, range);
default:
error('Unknown name ' + name);
throw new FormatError(`Unknown colorspace name: ${name}`);
}
return null;
};

ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
Expand Down Expand Up @@ -285,9 +286,10 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'Pattern':
return ['PatternCS', null];
default:
error('unrecognized colorspace ' + cs.name);
throw new FormatError(`unrecognized colorspace ${cs.name}`);
}
} else if (isArray(cs)) {
}
if (isArray(cs)) {
var mode = xref.fetchIfRef(cs[0]).name;
var numComps, params, alt, whitePoint, blackPoint, gamma;

Expand Down Expand Up @@ -366,12 +368,10 @@ var ColorSpace = (function ColorSpaceClosure() {
var range = params.getArray('Range');
return ['LabCS', whitePoint, blackPoint, range];
default:
error('unimplemented color space object "' + mode + '"');
throw new Error(`unimplemented color space object "${mode}"`);
}
} else {
error('unrecognized color space object: "' + cs + '"');
}
return null;
throw new FormatError(`unrecognized color space object: "${cs}"`);
};
/**
* Checks if a decode map matches the default decode map for a color space.
Expand Down Expand Up @@ -528,7 +528,7 @@ var IndexedCS = (function IndexedCSClosure() {
} else if (lookup instanceof Uint8Array || lookup instanceof Array) {
this.lookup = lookup;
} else {
error('Unrecognized lookup table: ' + lookup);
throw new FormatError(`Unrecognized lookup table: ${lookup}`);
}
}

Expand Down Expand Up @@ -753,7 +753,8 @@ var CalGrayCS = (function CalGrayCSClosure() {
this.defaultColor = new Float32Array(this.numComps);

if (!whitePoint) {
error('WhitePoint missing - required for color space CalGray');
throw new FormatError(
'WhitePoint missing - required for color space CalGray');
}
blackPoint = blackPoint || [0, 0, 0];
gamma = gamma || 1;
Expand All @@ -771,8 +772,8 @@ var CalGrayCS = (function CalGrayCSClosure() {

// Validate variables as per spec.
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
error('Invalid WhitePoint components for ' + this.name +
', no fallback available');
throw new FormatError('Invalid WhitePoint components for ' + this.name +
', no fallback available');
}

if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
Expand Down Expand Up @@ -876,7 +877,8 @@ var CalRGBCS = (function CalRGBCSClosure() {
this.defaultColor = new Float32Array(this.numComps);

if (!whitePoint) {
error('WhitePoint missing - required for color space CalRGB');
throw new FormatError(
'WhitePoint missing - required for color space CalRGB');
}
blackPoint = blackPoint || new Float32Array(3);
gamma = gamma || new Float32Array([1, 1, 1]);
Expand Down Expand Up @@ -909,8 +911,8 @@ var CalRGBCS = (function CalRGBCSClosure() {

// Validate variables as per spec.
if (XW < 0 || ZW < 0 || YW !== 1) {
error('Invalid WhitePoint components for ' + this.name +
', no fallback available');
throw new FormatError('Invalid WhitePoint components for ' + this.name +
', no fallback available');
}

if (XB < 0 || YB < 0 || ZB < 0) {
Expand Down Expand Up @@ -1152,7 +1154,8 @@ var LabCS = (function LabCSClosure() {
this.defaultColor = new Float32Array(this.numComps);

if (!whitePoint) {
error('WhitePoint missing - required for color space Lab');
throw new FormatError(
'WhitePoint missing - required for color space Lab');
}
blackPoint = blackPoint || [0, 0, 0];
range = range || [-100, 100, -100, 100];
Expand All @@ -1174,7 +1177,8 @@ var LabCS = (function LabCSClosure() {

// Validate vars as per spec
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
error('Invalid WhitePoint components, no fallback available');
throw new FormatError(
'Invalid WhitePoint components, no fallback available');
}

if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
Expand Down
Loading

0 comments on commit 72232e8

Please sign in to comment.