Merge pull request #8581 from yurydelendik/rm-error

Removes error()
This commit is contained in:
Yury Delendik 2017-07-07 09:43:30 -05:00 committed by GitHub
commit 7b4887dd21
24 changed files with 318 additions and 260 deletions

View File

@ -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
@ -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;
@ -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;
@ -811,8 +812,7 @@ 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
@ -869,8 +869,7 @@ 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.');
@ -999,7 +998,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;
},
@ -1008,7 +1007,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)) {
@ -1182,7 +1181,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;
},
@ -1195,7 +1194,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];
@ -1209,7 +1208,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;
@ -1520,8 +1519,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]);

View File

@ -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';
@ -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) {
@ -403,7 +403,7 @@ var IdentityCMap = (function IdentityCMapClosure() {
},
get isIdentityCMap() {
error('should not access .isIdentityCMap');
throw new Error('should not access .isIdentityCMap');
},
};
@ -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);
@ -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;
@ -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.');
}
}
@ -770,7 +770,7 @@ var CMapFactory = (function CMapFactoryClosure() {
break;
}
}
error('Invalid bf range.');
throw new FormatError('Invalid bf range.');
}
function parseCidChar(cMap, lexer) {
@ -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) {

View File

@ -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';
@ -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 = {
@ -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.
@ -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
@ -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.
@ -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) {
@ -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;
@ -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 FormatError(`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.
@ -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}`);
}
}
@ -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;
@ -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) {
@ -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]);
@ -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) {
@ -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];
@ -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) {

View File

@ -14,8 +14,8 @@
*/
import {
assert, bytesToString, error, isInt, PasswordException, PasswordResponses,
stringToBytes, utf8StringToString, warn
assert, bytesToString, FormatError, isInt, PasswordException,
PasswordResponses, stringToBytes, utf8StringToString, warn
} from '../shared/util';
import { isDict, isName, Name } from './primitives';
import { DecryptStream } from './stream';
@ -1858,14 +1858,14 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
function CipherTransformFactory(dict, fileId, password) {
var filter = dict.get('Filter');
if (!isName(filter, 'Standard')) {
error('unknown encryption method');
throw new FormatError('unknown encryption method');
}
this.dict = dict;
var algorithm = dict.get('V');
if (!isInt(algorithm) ||
(algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
algorithm !== 5)) {
error('unsupported encryption algorithm');
throw new FormatError('unsupported encryption algorithm');
}
this.algorithm = algorithm;
var keyLength = dict.get('Length');
@ -1892,7 +1892,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
}
if (!isInt(keyLength) ||
keyLength < 40 || (keyLength % 8) !== 0) {
error('invalid key length');
throw new FormatError('invalid key length');
}
// prepare keys
@ -2023,7 +2023,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
return new AES256Cipher(key);
};
}
error('Unknown crypto method');
throw new FormatError('Unknown crypto method');
}
CipherTransformFactory.prototype = {

View File

@ -14,7 +14,7 @@
*/
import {
assert, error, info, isArray, isArrayBuffer, isNum, isSpace, isString,
assert, info, isArray, isArrayBuffer, isNum, isSpace, isString,
MissingDataException, OPS, shadow, stringToBytes, stringToPDFString, Util,
warn
} from '../shared/util';
@ -353,7 +353,7 @@ var PDFDocument = (function PDFDocumentClosure() {
} else if (isArrayBuffer(arg)) {
stream = new Stream(arg);
} else {
error('PDFDocument: Unknown argument type');
throw new Error('PDFDocument: Unknown argument type');
}
assert(stream.length > 0, 'stream must have data');

View File

@ -14,9 +14,9 @@
*/
import {
assert, CMapCompressionType, createPromiseCapability, error,
FONT_IDENTITY_MATRIX, getLookupTableFactory, IDENTITY_MATRIX, ImageKind, info,
isArray, isNum, isString, NativeImageDecoding, OPS, TextRenderingMode,
assert, CMapCompressionType, createPromiseCapability, FONT_IDENTITY_MATRIX,
FormatError, getLookupTableFactory, IDENTITY_MATRIX, ImageKind, info, isArray,
isNum, isString, NativeImageDecoding, OPS, TextRenderingMode,
UNSUPPORTED_FEATURES, Util, warn
} from '../shared/util';
import { CMapFactory, IdentityCMap } from './cmap';
@ -953,7 +953,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
info('Ignored XObject subtype PS');
continue;
} else {
error('Unhandled XObject subtype ' + type.name);
throw new FormatError(
`Unhandled XObject subtype ${type.name}`);
}
}
break;
@ -1791,14 +1792,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} else if (isName(data)) {
differences[index++] = data.name;
} else {
error('Invalid entry in \'Differences\' array: ' + data);
throw new FormatError(
`Invalid entry in 'Differences' array: ${data}`);
}
}
}
} else if (isName(encoding)) {
baseEncodingName = encoding.name;
} else {
error('Encoding is not a Name nor a Dict');
throw new FormatError('Encoding is not a Name nor a Dict');
}
// According to table 114 if the encoding is a named encoding it must be
// one of these predefined encodings.

View File

@ -13,7 +13,7 @@