diff --git a/src/core/cmap.js b/src/core/cmap.js index 3f992bfb7..1c0e0b15e 100644 --- a/src/core/cmap.js +++ b/src/core/cmap.js @@ -14,7 +14,8 @@ */ import { - CMapCompressionType, FormatError, isString, MissingDataException, Util, warn + CMapCompressionType, FormatError, isString, MissingDataException, + unreachable, Util, warn } from '../shared/util'; import { isCmd, isEOF, isName, isStream } from './primitives'; import { Lexer } from './parser'; @@ -353,19 +354,19 @@ var IdentityCMap = (function IdentityCMapClosure() { addCodespaceRange: CMap.prototype.addCodespaceRange, mapCidRange(low, high, dstLow) { - throw new Error('should not call mapCidRange'); + unreachable('should not call mapCidRange'); }, mapBfRange(low, high, dstLow) { - throw new Error('should not call mapBfRange'); + unreachable('should not call mapBfRange'); }, mapBfRangeToArray(low, high, array) { - throw new Error('should not call mapBfRangeToArray'); + unreachable('should not call mapBfRangeToArray'); }, mapOne(src, dst) { - throw new Error('should not call mapCidOne'); + unreachable('should not call mapCidOne'); }, lookup(code) { @@ -402,7 +403,7 @@ var IdentityCMap = (function IdentityCMapClosure() { }, get isIdentityCMap() { - throw new Error('should not access .isIdentityCMap'); + unreachable('should not access .isIdentityCMap'); }, }; diff --git a/src/core/colorspace.js b/src/core/colorspace.js index ca173b913..f92aaba5d 100644 --- a/src/core/colorspace.js +++ b/src/core/colorspace.js @@ -13,7 +13,9 @@ * 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'; var ColorSpace = (function ColorSpaceClosure() { @@ -54,7 +56,7 @@ var ColorSpace = (function ColorSpaceClosure() { // Constructor should define this.numComps, this.defaultColor, this.name function ColorSpace() { - throw new Error('should not call ColorSpace constructor'); + unreachable('should not call ColorSpace constructor'); } ColorSpace.prototype = { @@ -74,7 +76,7 @@ var ColorSpace = (function ColorSpaceClosure() { */ getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, 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. @@ -88,7 +90,7 @@ var ColorSpace = (function ColorSpaceClosure() { getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, 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 @@ -97,7 +99,7 @@ var ColorSpace = (function ColorSpaceClosure() { */ getOutputLength: function ColorSpace_getOutputLength(inputLength, 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. diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index 2673a61ba..15d12b836 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -13,7 +13,9 @@ * 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 { getGlyphsUnicode } from './glyphlist'; import { StandardEncoding } from './encodings'; @@ -628,7 +630,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { }, compileGlyphImpl() { - throw new Error('Children classes should implement this.'); + unreachable('Children classes should implement this.'); }, hasBuiltPath(unicode) { diff --git a/src/core/fonts.js b/src/core/fonts.js index 97f387bcf..ac1938486 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -15,7 +15,7 @@ import { bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info, isNum, - isSpace, MissingDataException, readUint32, shadow, string32, warn + isSpace, MissingDataException, readUint32, shadow, string32, unreachable, warn } from '../shared/util'; import { CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict, @@ -295,7 +295,7 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() { }, amend(map) { - throw new Error('Should not call amend()'); + unreachable('Should not call amend()'); }, }; diff --git a/src/core/function.js b/src/core/function.js index 5ad151206..00c4f1b07 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -14,7 +14,7 @@ */ import { - FormatError, info, isBool, isEvalSupported, shadow + FormatError, info, isBool, isEvalSupported, shadow, unreachable } from '../shared/util'; import { isDict, isStream } from './primitives'; import { PostScriptLexer, PostScriptParser } from './ps_parser'; @@ -822,7 +822,7 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() { this.type = type; } AstNode.prototype.visit = function (visitor) { - throw new Error('abstract method'); + unreachable('abstract method'); }; function AstArgument(index, min, max) { diff --git a/src/core/obj.js b/src/core/obj.js index 622602991..6af60f1f3 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -16,7 +16,8 @@ import { bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError, info, InvalidPDFException, isBool, isString, MissingDataException, shadow, - stringToPDFString, stringToUTF8String, Util, warn, XRefParseException + stringToPDFString, stringToUTF8String, unreachable, Util, warn, + XRefParseException } from '../shared/util'; import { Dict, isCmd, isDict, isName, isRef, isRefsEqual, isStream, Ref, RefSet, @@ -1474,7 +1475,7 @@ var XRef = (function XRefClosure() { */ var NameOrNumberTree = (function NameOrNumberTreeClosure() { function NameOrNumberTree(root, xref) { - throw new Error('Cannot initialize NameOrNumberTree.'); + unreachable('Cannot initialize NameOrNumberTree.'); } NameOrNumberTree.prototype = { diff --git a/src/core/pattern.js b/src/core/pattern.js index a8df287b7..236c58fc4 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -34,14 +34,14 @@ var ShadingType = { var Pattern = (function PatternClosure() { // Constructor should define this.getPattern function Pattern() { - throw new Error('should not call Pattern constructor'); + unreachable('should not call Pattern constructor'); } Pattern.prototype = { // Input: current Canvas context // Output: the appropriate fillStyle or strokeStyle getPattern: function Pattern_getPattern(ctx) { - throw new Error(`Should not call Pattern.getStyle: ${ctx}`); + unreachable(`Should not call Pattern.getStyle: ${ctx}`); }, }; diff --git a/src/core/pdf_manager.js b/src/core/pdf_manager.js index 8cf881616..9ed6be87f 100644 --- a/src/core/pdf_manager.js +++ b/src/core/pdf_manager.js @@ -15,7 +15,7 @@ import { createPromiseCapability, createValidAbsoluteUrl, MissingDataException, - NotImplementedException, shadow, Util, warn + NotImplementedException, shadow, unreachable, Util, warn } from '../shared/util'; import { ChunkedStreamManager } from './chunked_stream'; import { PDFDocument } from './document'; @@ -23,7 +23,7 @@ import { Stream } from './stream'; var BasePdfManager = (function BasePdfManagerClosure() { function BasePdfManager() { - throw new Error('Cannot initialize BaseManagerManager'); + unreachable('Cannot initialize BaseManagerManager'); } BasePdfManager.prototype = { diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 073c9cfa5..8c3212fa4 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -18,7 +18,8 @@ import { getFilenameFromUrl, LinkTarget } from './dom_utils'; import { - AnnotationBorderStyleType, AnnotationType, stringToPDFString, Util, warn + AnnotationBorderStyleType, AnnotationType, stringToPDFString, unreachable, + Util, warn } from '../shared/util'; /** @@ -261,7 +262,7 @@ class AnnotationElement { * @memberof AnnotationElement */ render() { - throw new Error('Abstract method `AnnotationElement.render` called'); + unreachable('Abstract method `AnnotationElement.render` called'); } } diff --git a/src/display/api.js b/src/display/api.js index a3fa08ce1..785745015 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -18,7 +18,8 @@ import { assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException, isArrayBuffer, isSameOrigin, loadJpegStream, MessageHandler, MissingPDFException, NativeImageDecoding, PageViewport, PasswordException, - stringToBytes, UnexpectedResponseException, UnknownErrorException, Util, warn + stringToBytes, UnexpectedResponseException, UnknownErrorException, + unreachable, Util, warn } from '../shared/util'; import { DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting, @@ -475,7 +476,7 @@ var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() { requestDataRange: function PDFDataRangeTransport_requestDataRange(begin, end) { - throw new Error('Abstract method PDFDataRangeTransport.requestDataRange'); + unreachable('Abstract method PDFDataRangeTransport.requestDataRange'); }, abort: function PDFDataRangeTransport_abort() { diff --git a/src/display/canvas.js b/src/display/canvas.js index 6467f23d1..108c961f4 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -15,7 +15,7 @@ import { FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, info, isLittleEndian, isNum, - OPS, shadow, TextRenderingMode, Util, warn + OPS, shadow, TextRenderingMode, unreachable, Util, warn } from '../shared/util'; import { getShadingPatternFromIR, TilingPattern } from './pattern_helper'; @@ -1733,10 +1733,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { // Images beginInlineImage: function CanvasGraphics_beginInlineImage() { - throw new Error('Should not call beginInlineImage'); + unreachable('Should not call beginInlineImage'); }, beginImageData: function CanvasGraphics_beginImageData() { - throw new Error('Should not call beginImageData'); + unreachable('Should not call beginImageData'); }, paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index 45ab29c06..894addde7 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -14,7 +14,8 @@ */ import { - assert, CMapCompressionType, removeNullCharacters, stringToBytes, warn + assert, CMapCompressionType, removeNullCharacters, stringToBytes, + unreachable, warn } from '../shared/util'; import globalScope from '../shared/global_scope'; @@ -527,7 +528,7 @@ class StatTimer { */ class DummyStatTimer { constructor() { - throw new Error('Cannot initialize DummyStatTimer.'); + unreachable('Cannot initialize DummyStatTimer.'); } static reset() {}