Replaced occurence of throw new Error with unreachable where applicable

This commit is contained in:
Naveen Jain 2017-12-13 19:21:45 +05:30
parent b327633ad6
commit 1135674647
12 changed files with 41 additions and 32 deletions

View File

@ -14,7 +14,8 @@
*/ */
import { import {
CMapCompressionType, FormatError, isString, MissingDataException, Util, warn CMapCompressionType, FormatError, isString, MissingDataException,
unreachable, Util, warn
} from '../shared/util'; } from '../shared/util';
import { isCmd, isEOF, isName, isStream } from './primitives'; import { isCmd, isEOF, isName, isStream } from './primitives';
import { Lexer } from './parser'; import { Lexer } from './parser';
@ -353,19 +354,19 @@ var IdentityCMap = (function IdentityCMapClosure() {
addCodespaceRange: CMap.prototype.addCodespaceRange, addCodespaceRange: CMap.prototype.addCodespaceRange,
mapCidRange(low, high, dstLow) { mapCidRange(low, high, dstLow) {
throw new Error('should not call mapCidRange'); unreachable('should not call mapCidRange');
}, },
mapBfRange(low, high, dstLow) { mapBfRange(low, high, dstLow) {
throw new Error('should not call mapBfRange'); unreachable('should not call mapBfRange');
}, },
mapBfRangeToArray(low, high, array) { mapBfRangeToArray(low, high, array) {
throw new Error('should not call mapBfRangeToArray'); unreachable('should not call mapBfRangeToArray');
}, },
mapOne(src, dst) { mapOne(src, dst) {
throw new Error('should not call mapCidOne'); unreachable('should not call mapCidOne');
}, },
lookup(code) { lookup(code) {
@ -402,7 +403,7 @@ var IdentityCMap = (function IdentityCMapClosure() {
}, },
get isIdentityCMap() { get isIdentityCMap() {
throw new Error('should not access .isIdentityCMap'); unreachable('should not access .isIdentityCMap');
}, },
}; };

View File

@ -13,7 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { FormatError, info, isString, shadow, warn } from '../shared/util'; import {
FormatError, info, isString, shadow, unreachable, warn
} from '../shared/util';
import { isDict, isName, isStream } from './primitives'; import { isDict, isName, isStream } from './primitives';
var ColorSpace = (function ColorSpaceClosure() { var ColorSpace = (function ColorSpaceClosure() {
@ -54,7 +56,7 @@ var ColorSpace = (function ColorSpaceClosure() {
// Constructor should define this.numComps, this.defaultColor, this.name // Constructor should define this.numComps, this.defaultColor, this.name
function ColorSpace() { function ColorSpace() {
throw new Error('should not call ColorSpace constructor'); unreachable('should not call ColorSpace constructor');
} }
ColorSpace.prototype = { ColorSpace.prototype = {
@ -74,7 +76,7 @@ var ColorSpace = (function ColorSpaceClosure() {
*/ */
getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
dest, destOffset) { dest, destOffset) {
throw new Error('Should not call ColorSpace.getRgbItem'); unreachable('Should not call ColorSpace.getRgbItem');
}, },
/** /**
* Converts the specified number of the color values to the RGB colors. * Converts the specified number of the color values to the RGB colors.
@ -88,7 +90,7 @@ var ColorSpace = (function ColorSpaceClosure() {
getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
dest, destOffset, bits, dest, destOffset, bits,
alpha01) { alpha01) {
throw new Error('Should not call ColorSpace.getRgbBuffer'); unreachable('Should not call ColorSpace.getRgbBuffer');
}, },
/** /**
* Determines the number of bytes required to store the result of the * Determines the number of bytes required to store the result of the
@ -97,7 +99,7 @@ var ColorSpace = (function ColorSpaceClosure() {
*/ */
getOutputLength: function ColorSpace_getOutputLength(inputLength, getOutputLength: function ColorSpace_getOutputLength(inputLength,
alpha01) { alpha01) {
throw new Error('Should not call ColorSpace.getOutputLength'); unreachable('Should not call ColorSpace.getOutputLength');
}, },
/** /**
* Returns true if source data will be equal the result/output data. * Returns true if source data will be equal the result/output data.

View File

@ -13,7 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { bytesToString, FormatError, Util } from '../shared/util'; import {
bytesToString, FormatError, unreachable, Util
} from '../shared/util';
import { CFFParser } from './cff_parser'; import { CFFParser } from './cff_parser';
import { getGlyphsUnicode } from './glyphlist'; import { getGlyphsUnicode } from './glyphlist';
import { StandardEncoding } from './encodings'; import { StandardEncoding } from './encodings';
@ -628,7 +630,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}, },
compileGlyphImpl() { compileGlyphImpl() {
throw new Error('Children classes should implement this.'); unreachable('Children classes should implement this.');
}, },
hasBuiltPath(unicode) { hasBuiltPath(unicode) {

View File

@ -15,7 +15,7 @@
import { import {
bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info, isNum, bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info, isNum,
isSpace, MissingDataException, readUint32, shadow, string32, warn isSpace, MissingDataException, readUint32, shadow, string32, unreachable, warn
} from '../shared/util'; } from '../shared/util';
import { import {
CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict, CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict,
@ -295,7 +295,7 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
}, },
amend(map) { amend(map) {
throw new Error('Should not call amend()'); unreachable('Should not call amend()');
}, },
}; };

View File

@ -14,7 +14,7 @@
*/ */
import { import {
FormatError, info, isBool, isEvalSupported, shadow FormatError, info, isBool, isEvalSupported, shadow, unreachable
} from '../shared/util'; } from '../shared/util';
import { isDict, isStream } from './primitives'; import { isDict, isStream } from './primitives';
import { PostScriptLexer, PostScriptParser } from './ps_parser'; import { PostScriptLexer, PostScriptParser } from './ps_parser';
@ -822,7 +822,7 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() {
this.type = type; this.type = type;
} }
AstNode.prototype.visit = function (visitor) { AstNode.prototype.visit = function (visitor) {
throw new Error('abstract method'); unreachable('abstract method');
}; };
function AstArgument(index, min, max) { function AstArgument(index, min, max) {

View File

@ -16,7 +16,8 @@
import { import {
bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError, bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError,
info, InvalidPDFException, isBool, isString, MissingDataException, shadow, info, InvalidPDFException, isBool, isString, MissingDataException, shadow,
stringToPDFString, stringToUTF8String, Util, warn, XRefParseException stringToPDFString, stringToUTF8String, unreachable, Util, warn,
XRefParseException
} from '../shared/util'; } from '../shared/util';
import { import {
Dict, isCmd, isDict, isName, isRef, isRefsEqual, isStream, Ref, RefSet, Dict, isCmd, isDict, isName, isRef, isRefsEqual, isStream, Ref, RefSet,
@ -1474,7 +1475,7 @@ var XRef = (function XRefClosure() {
*/ */
var NameOrNumberTree = (function NameOrNumberTreeClosure() { var NameOrNumberTree = (function NameOrNumberTreeClosure() {
function NameOrNumberTree(root, xref) { function NameOrNumberTree(root, xref) {
throw new Error('Cannot initialize NameOrNumberTree.'); unreachable('Cannot initialize NameOrNumberTree.');
} }
NameOrNumberTree.prototype = { NameOrNumberTree.prototype = {

View File

@ -34,14 +34,14 @@ var ShadingType = {
var Pattern = (function PatternClosure() { var Pattern = (function PatternClosure() {
// Constructor should define this.getPattern // Constructor should define this.getPattern
function Pattern() { function Pattern() {
throw new Error('should not call Pattern constructor'); unreachable('should not call Pattern constructor');
} }
Pattern.prototype = { Pattern.prototype = {
// Input: current Canvas context // Input: current Canvas context
// Output: the appropriate fillStyle or strokeStyle // Output: the appropriate fillStyle or strokeStyle
getPattern: function Pattern_getPattern(ctx) { getPattern: function Pattern_getPattern(ctx) {
throw new Error(`Should not call Pattern.getStyle: ${ctx}`); unreachable(`Should not call Pattern.getStyle: ${ctx}`);
}, },
}; };

View File

@ -15,7 +15,7 @@
import { import {
createPromiseCapability, createValidAbsoluteUrl, MissingDataException, createPromiseCapability, createValidAbsoluteUrl, MissingDataException,
NotImplementedException, shadow, Util, warn NotImplementedException, shadow, unreachable, Util, warn
} from '../shared/util'; } from '../shared/util';
import { ChunkedStreamManager } from './chunked_stream'; import { ChunkedStreamManager } from './chunked_stream';
import { PDFDocument } from './document'; import { PDFDocument } from './document';
@ -23,7 +23,7 @@ import { Stream } from './stream';
var BasePdfManager = (function BasePdfManagerClosure() { var BasePdfManager = (function BasePdfManagerClosure() {
function BasePdfManager() { function BasePdfManager() {
throw new Error('Cannot initialize BaseManagerManager'); unreachable('Cannot initialize BaseManagerManager');
} }
BasePdfManager.prototype = { BasePdfManager.prototype = {

View File

@ -18,7 +18,8 @@ import {
getFilenameFromUrl, LinkTarget getFilenameFromUrl, LinkTarget
} from './dom_utils'; } from './dom_utils';
import { import {
AnnotationBorderStyleType, AnnotationType, stringToPDFString, Util, warn AnnotationBorderStyleType, AnnotationType, stringToPDFString, unreachable,
Util, warn
} from '../shared/util'; } from '../shared/util';
/** /**
@ -261,7 +262,7 @@ class AnnotationElement {
* @memberof AnnotationElement * @memberof AnnotationElement
*/ */
render() { render() {
throw new Error('Abstract method `AnnotationElement.render` called'); unreachable('Abstract method `AnnotationElement.render` called');
} }
} }

View File

@ -18,7 +18,8 @@ import {
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException, assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
isArrayBuffer, isSameOrigin, loadJpegStream, MessageHandler, isArrayBuffer, isSameOrigin, loadJpegStream, MessageHandler,
MissingPDFException, NativeImageDecoding, PageViewport, PasswordException, MissingPDFException, NativeImageDecoding, PageViewport, PasswordException,
stringToBytes, UnexpectedResponseException, UnknownErrorException, Util, warn stringToBytes, UnexpectedResponseException, UnknownErrorException,
unreachable, Util, warn
} from '../shared/util'; } from '../shared/util';
import { import {
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting, DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
@ -475,7 +476,7 @@ var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
requestDataRange: requestDataRange:
function PDFDataRangeTransport_requestDataRange(begin, end) { function PDFDataRangeTransport_requestDataRange(begin, end) {
throw new Error('Abstract method PDFDataRangeTransport.requestDataRange'); unreachable('Abstract method PDFDataRangeTransport.requestDataRange');
}, },
abort: function PDFDataRangeTransport_abort() { abort: function PDFDataRangeTransport_abort() {

View File

@ -15,7 +15,7 @@
import { import {
FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, info, isLittleEndian, isNum, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, info, isLittleEndian, isNum,
OPS, shadow, TextRenderingMode, Util, warn OPS, shadow, TextRenderingMode, unreachable, Util, warn
} from '../shared/util'; } from '../shared/util';
import { getShadingPatternFromIR, TilingPattern } from './pattern_helper'; import { getShadingPatternFromIR, TilingPattern } from './pattern_helper';
@ -1733,10 +1733,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// Images // Images
beginInlineImage: function CanvasGraphics_beginInlineImage() { beginInlineImage: function CanvasGraphics_beginInlineImage() {
throw new Error('Should not call beginInlineImage'); unreachable('Should not call beginInlineImage');
}, },
beginImageData: function CanvasGraphics_beginImageData() { beginImageData: function CanvasGraphics_beginImageData() {
throw new Error('Should not call beginImageData'); unreachable('Should not call beginImageData');
}, },
paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,

View File

@ -14,7 +14,8 @@
*/ */
import { import {
assert, CMapCompressionType, removeNullCharacters, stringToBytes, warn assert, CMapCompressionType, removeNullCharacters, stringToBytes,
unreachable, warn
} from '../shared/util'; } from '../shared/util';
import globalScope from '../shared/global_scope'; import globalScope from '../shared/global_scope';
@ -527,7 +528,7 @@ class StatTimer {
*/ */
class DummyStatTimer { class DummyStatTimer {
constructor() { constructor() {
throw new Error('Cannot initialize DummyStatTimer.'); unreachable('Cannot initialize DummyStatTimer.');
} }
static reset() {} static reset() {}