diff --git a/src/core/annotation.js b/src/core/annotation.js index 4fca1e83b..7d807419b 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -15,8 +15,7 @@ import { AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag, - AnnotationType, isArray, isInt, OPS, stringToBytes, stringToPDFString, Util, - warn + AnnotationType, isArray, OPS, stringToBytes, stringToPDFString, Util, warn } from '../shared/util'; import { Catalog, FileSpec, ObjectLoader } from './obj'; import { Dict, isDict, isName, isRef, isStream } from './primitives'; @@ -212,7 +211,7 @@ class Annotation { * @see {@link shared/util.js} */ setFlags(flags) { - this.flags = (isInt(flags) && flags > 0) ? flags : 0; + this.flags = (Number.isInteger(flags) && flags > 0) ? flags : 0; } /** @@ -575,7 +574,7 @@ class WidgetAnnotation extends Annotation { this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty; data.fieldFlags = Util.getInheritableProperty(dict, 'Ff'); - if (!isInt(data.fieldFlags) || data.fieldFlags < 0) { + if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) { data.fieldFlags = 0; } @@ -666,14 +665,14 @@ class TextWidgetAnnotation extends WidgetAnnotation { // Determine the alignment of text in the field. let alignment = Util.getInheritableProperty(params.dict, 'Q'); - if (!isInt(alignment) || alignment < 0 || alignment > 2) { + if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) { alignment = null; } this.data.textAlignment = alignment; // Determine the maximum length of text in the field. let maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen'); - if (!isInt(maximumLength) || maximumLength < 0) { + if (!Number.isInteger(maximumLength) || maximumLength < 0) { maximumLength = null; } this.data.maxLen = maximumLength; diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index d670af4d1..0c754488f 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -14,7 +14,7 @@ */ import { - arrayByteLength, arraysToBytes, createPromiseCapability, isEmptyObj, isInt, + arrayByteLength, arraysToBytes, createPromiseCapability, isEmptyObj, MissingDataException } from '../shared/util'; @@ -518,7 +518,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() { } else { nextEmptyChunk = this.stream.nextEmptyChunk(endChunk); } - if (isInt(nextEmptyChunk)) { + if (Number.isInteger(nextEmptyChunk)) { this._requestChunks([nextEmptyChunk]); } } diff --git a/src/core/cmap.js b/src/core/cmap.js index b15ff9596..f6b6e8679 100644 --- a/src/core/cmap.js +++ b/src/core/cmap.js @@ -14,8 +14,7 @@ */ import { - CMapCompressionType, FormatError, isInt, isString, MissingDataException, Util, - warn + CMapCompressionType, FormatError, isString, MissingDataException, Util, warn } from '../shared/util'; import { isCmd, isEOF, isName, isStream } from './primitives'; import { Lexer } from './parser'; @@ -370,11 +369,11 @@ var IdentityCMap = (function IdentityCMapClosure() { }, lookup(code) { - return (isInt(code) && code <= 0xffff) ? code : undefined; + return (Number.isInteger(code) && code <= 0xffff) ? code : undefined; }, contains(code) { - return isInt(code) && code <= 0xffff; + return Number.isInteger(code) && code <= 0xffff; }, forEach(callback) { @@ -384,7 +383,7 @@ var IdentityCMap = (function IdentityCMapClosure() { }, charCodeOf(value) { - return (isInt(value) && value <= 0xffff) ? value : -1; + return (Number.isInteger(value) && value <= 0xffff) ? value : -1; }, getMap() { @@ -718,7 +717,7 @@ var CMapFactory = (function CMapFactoryClosure() { } function expectInt(obj) { - if (!isInt(obj)) { + if (!Number.isInteger(obj)) { throw new FormatError('Malformed CMap: expected int.'); } } @@ -757,8 +756,8 @@ var CMapFactory = (function CMapFactoryClosure() { expectString(obj); var high = strToInt(obj); obj = lexer.getObj(); - if (isInt(obj) || isString(obj)) { - var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj; + if (Number.isInteger(obj) || isString(obj)) { + var dstLow = Number.isInteger(obj) ? String.fromCharCode(obj) : obj; cMap.mapBfRange(low, high, dstLow); } else if (isCmd(obj, '[')) { obj = lexer.getObj(); @@ -839,7 +838,7 @@ var CMapFactory = (function CMapFactoryClosure() { function parseWMode(cMap, lexer) { var obj = lexer.getObj(); - if (isInt(obj)) { + if (Number.isInteger(obj)) { cMap.vertical = !!obj; } } diff --git a/src/core/crypto.js b/src/core/crypto.js index 687504f1f..e87c3e10e 100644 --- a/src/core/crypto.js +++ b/src/core/crypto.js @@ -14,7 +14,7 @@ */ import { - bytesToString, FormatError, isInt, PasswordException, PasswordResponses, + bytesToString, FormatError, PasswordException, PasswordResponses, stringToBytes, utf8StringToString, warn } from '../shared/util'; import { isDict, isName, Name } from './primitives'; @@ -1862,9 +1862,9 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() { } this.dict = dict; var algorithm = dict.get('V'); - if (!isInt(algorithm) || + if (!Number.isInteger(algorithm) || (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && - algorithm !== 5)) { + algorithm !== 5)) { throw new FormatError('unsupported encryption algorithm'); } this.algorithm = algorithm; @@ -1890,7 +1890,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() { } } } - if (!isInt(keyLength) || + if (!Number.isInteger(keyLength) || keyLength < 40 || (keyLength % 8) !== 0) { throw new FormatError('invalid key length'); } diff --git a/src/core/fonts.js b/src/core/fonts.js index 7f62283ea..65ba5ef37 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -15,8 +15,7 @@ import { bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info, isArray, - isInt, isNum, isSpace, MissingDataException, readUint32, shadow, string32, - warn + isNum, isSpace, MissingDataException, readUint32, shadow, string32, warn } from '../shared/util'; import { CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict, @@ -291,7 +290,8 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() { }, charCodeOf(v) { - return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1; + return (Number.isInteger(v) && + v >= this.firstChar && v <= this.lastChar) ? v : -1; }, amend(map) { diff --git a/src/core/obj.js b/src/core/obj.js index 841da2cc3..eecf42e7d 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -15,9 +15,8 @@ import { bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError, - info, InvalidPDFException, isArray, isBool, isInt, isString, - MissingDataException, shadow, stringToPDFString, stringToUTF8String, Util, - warn, XRefParseException + info, InvalidPDFException, isArray, isBool, isString, MissingDataException, + shadow, stringToPDFString, stringToUTF8String, Util, warn, XRefParseException } from '../shared/util'; import { Dict, isCmd, isDict, isName, isRef, isRefsEqual, isStream, Ref, RefSet, @@ -169,7 +168,7 @@ var Catalog = (function CatalogClosure() { }, get numPages() { var obj = this.toplevelPagesDict.get('Count'); - if (!isInt(obj)) { + if (!Number.isInteger(obj)) { throw new FormatError( 'page count in top level pages object is not an integer'); } @@ -286,7 +285,7 @@ var Catalog = (function CatalogClosure() { prefix = p ? stringToPDFString(p) : ''; var st = labelDict.get('St'); - if (st && !(isInt(st) && st >= 1)) { + if (st && !(Number.isInteger(st) && st >= 1)) { throw new FormatError('Invalid start in PageLabel dictionary.'); } currentIndex = st || 1; @@ -912,7 +911,7 @@ var XRef = (function XRefClosure() { var first = tableState.firstEntryNum; var count = tableState.entryCount; - if (!isInt(first) || !isInt(count)) { + if (!Number.isInteger(first) || !Number.isInteger(count)) { throw new FormatError( 'Invalid XRef table: wrong types in subsection header'); } @@ -935,7 +934,7 @@ var XRef = (function XRefClosure() { } // Validate entry obj - if (!isInt(entry.offset) || !isInt(entry.gen) || + if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) { throw new FormatError( `Invalid entry in XRef subsection: ${first}, ${count}`); @@ -1007,12 +1006,13 @@ var XRef = (function XRefClosure() { var first = entryRanges[0]; var n = entryRanges[1]; - if (!isInt(first) || !isInt(n)) { + if (!Number.isInteger(first) || !Number.isInteger(n)) { throw new FormatError( `Invalid XRef range fields: ${first}, ${n}`); } - if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || - !isInt(generationFieldWidth)) { + if (!Number.isInteger(typeFieldWidth) || + !Number.isInteger(offsetFieldWidth) || + !Number.isInteger(generationFieldWidth)) { throw new FormatError( `Invalid XRef entry fields length: ${first}, ${n}`); } @@ -1229,7 +1229,7 @@ var XRef = (function XRefClosure() { // Recursively get other XRefs 'XRefStm', if any obj = dict.get('XRefStm'); - if (isInt(obj)) { + if (Number.isInteger(obj)) { var pos = obj; // ignore previously loaded xref streams // (possible infinite recursion) @@ -1238,9 +1238,9 @@ var XRef = (function XRefClosure() { this.startXRefQueue.push(pos); } } - } else if (isInt(obj)) { + } else if (Number.isInteger(obj)) { // Parse in-stream XRef - if (!isInt(parser.getObj()) || + if (!Number.isInteger(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) { throw new FormatError('Invalid XRef stream'); @@ -1258,7 +1258,7 @@ var XRef = (function XRefClosure() { // Recursively get previous dictionary, if any obj = dict.get('Prev'); - if (isInt(obj)) { + if (Number.isInteger(obj)) { this.startXRefQueue.push(obj); } else if (isRef(obj)) { // The spec says Prev must not be a reference, i.e. "/Prev NNN" @@ -1386,7 +1386,7 @@ var XRef = (function XRefClosure() { } var first = stream.dict.get('First'); var n = stream.dict.get('N'); - if (!isInt(first) || !isInt(n)) { + if (!Number.isInteger(first) || !Number.isInteger(n)) { throw new FormatError( 'invalid first and n parameters for ObjStm stream'); } @@ -1396,13 +1396,13 @@ var XRef = (function XRefClosure() { // read the object numbers to populate cache for (i = 0; i < n; ++i) { num = parser.getObj(); - if (!isInt(num)) { + if (!Number.isInteger(num)) { throw new FormatError( `invalid object number in the ObjStm stream: ${num}`); } nums.push(num); var offset = parser.getObj(); - if (!isInt(offset)) { + if (!Number.isInteger(offset)) { throw new FormatError( `invalid object offset in the ObjStm stream: ${offset}`); } diff --git a/src/core/parser.js b/src/core/parser.js index 954bec8ba..2d3be78dc 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -18,8 +18,8 @@ import { JpegStream, JpxStream, LZWStream, NullStream, PredictorStream, RunLengthStream } from './stream'; import { - assert, FormatError, info, isArray, isInt, isNum, isString, - MissingDataException, StreamType, warn + assert, FormatError, info, isArray, isNum, isString, MissingDataException, + StreamType, warn } from '../shared/util'; import { Cmd, Dict, EOF, isCmd, isDict, isEOF, isName, Name, Ref @@ -121,9 +121,9 @@ var Parser = (function ParserClosure() { } } - if (isInt(buf1)) { // indirect reference or integer + if (Number.isInteger(buf1)) { // indirect reference or integer var num = buf1; - if (isInt(this.buf1) && isCmd(this.buf2, 'R')) { + if (Number.isInteger(this.buf1) && isCmd(this.buf2, 'R')) { var ref = new Ref(num, this.buf1); this.shift(); this.shift(); @@ -456,7 +456,7 @@ var Parser = (function ParserClosure() { // get length var length = dict.get('Length'); - if (!isInt(length)) { + if (!Number.isInteger(length)) { info('Bad ' + length + ' attribute in stream'); length = 0; } @@ -1069,7 +1069,7 @@ var Linearization = { create: function LinearizationCreate(stream) { function getInt(name, allowZeroValue) { var obj = linDict.get(name); - if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) { + if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) { return obj; } throw new Error('The "' + name + '" parameter in the linearization ' + @@ -1080,7 +1080,7 @@ var Linearization = { if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) { for (var index = 0; index < hintsLength; index++) { - if (!(isInt(item = hints[index]) && item > 0)) { + if (!(Number.isInteger(item = hints[index]) && item > 0)) { throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.'); } @@ -1095,7 +1095,8 @@ var Linearization = { var obj3 = parser.getObj(); var linDict = parser.getObj(); var obj, length; - if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && + if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && + isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) { return null; // No valid linearization dictionary found. } else if ((length = getInt('L')) !== stream.length) { diff --git a/src/core/stream.js b/src/core/stream.js index 5aa78c392..10e88ea90 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -14,7 +14,7 @@ */ import { - createObjectURL, FormatError, info, isArray, isInt, isSpace, shadow, Util + createObjectURL, FormatError, info, isArray, isSpace, shadow, Util } from '../shared/util'; import { Dict, isDict, isStream } from './primitives'; import { Jbig2Image } from './jbig2'; @@ -927,7 +927,7 @@ var JpegStream = (function JpegStreamClosure() { // Fetching the 'ColorTransform' entry, if it exists. if (isDict(this.params)) { var colorTransform = this.params.get('ColorTransform'); - if (isInt(colorTransform)) { + if (Number.isInteger(colorTransform)) { jpegImage.colorTransform = colorTransform; } } diff --git a/src/display/api.js b/src/display/api.js index 3f4b5101f..ddd764d5f 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -15,11 +15,11 @@ /* globals requirejs, __non_webpack_require__ */ import { - assert, createPromiseCapability, deprecated, getVerbosityLevel, - info, InvalidPDFException, isArrayBuffer, isInt, isSameOrigin, - loadJpegStream, MessageHandler, MissingPDFException, NativeImageDecoding, - PageViewport, PasswordException, StatTimer, stringToBytes, - UnexpectedResponseException, UnknownErrorException, Util, warn + assert, createPromiseCapability, deprecated, getVerbosityLevel, info, + InvalidPDFException, isArrayBuffer, isSameOrigin, loadJpegStream, + MessageHandler, MissingPDFException, NativeImageDecoding, PageViewport, + PasswordException, StatTimer, stringToBytes, UnexpectedResponseException, + UnknownErrorException, Util, warn } from '../shared/util'; import { DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting, @@ -1986,7 +1986,8 @@ var WorkerTransport = (function WorkerTransportClosure() { }, getPage: function WorkerTransport_getPage(pageNumber, capability) { - if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) { + if (!Number.isInteger(pageNumber) || + pageNumber <= 0 || pageNumber > this.numPages) { return Promise.reject(new Error('Invalid page request')); } diff --git a/src/display/network_utils.js b/src/display/network_utils.js index 5328b0c36..94e6b2fc9 100644 --- a/src/display/network_utils.js +++ b/src/display/network_utils.js @@ -13,7 +13,8 @@ * limitations under the License. */ -import { assert, isInt, MissingPDFException, UnexpectedResponseException +import { + assert, MissingPDFException, UnexpectedResponseException } from '../shared/util'; function validateRangeRequestCapabilities({ getResponseHeader, isHttp, @@ -35,17 +36,15 @@ function validateRangeRequestCapabilities({ getResponseHeader, isHttp, return returnValues; } - let length = getResponseHeader('Content-Length'); - length = parseInt(length, 10); - if (!isInt(length)) { + let length = parseInt(getResponseHeader('Content-Length'), 10); + if (!Number.isInteger(length)) { return returnValues; } returnValues.suggestedLength = length; if (length <= 2 * rangeChunkSize) { - // The file size is smaller than the size of two chunks, so it does - // not make any sense to abort the request and retry with a range - // request. + // The file size is smaller than the size of two chunks, so it does not + // make any sense to abort the request and retry with a range request. return returnValues; } diff --git a/src/shared/util.js b/src/shared/util.js index 15b3f8ffc..adf109ed7 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -817,7 +817,7 @@ var Util = (function UtilClosure() { * @return {string} The resulting Roman number. */ Util.toRoman = function Util_toRoman(number, lowerCase) { - assert(isInt(number) && number > 0, + assert(Number.isInteger(number) && number > 0, 'The number should be a positive integer.'); var pos, romanBuf = []; // Thousands @@ -1075,10 +1075,6 @@ function isBool(v) { return typeof v === 'boolean'; } -function isInt(v) { - return typeof v === 'number' && ((v | 0) === v); -} - function isNum(v) { return typeof v === 'number'; } @@ -1703,7 +1699,6 @@ export { isArrayBuffer, isBool, isEmptyObj, - isInt, isNum, isString, isSpace, diff --git a/test/unit/fonts_spec.js b/test/unit/fonts_spec.js index c5e6e858e..483921a37 100644 --- a/test/unit/fonts_spec.js +++ b/test/unit/fonts_spec.js @@ -16,7 +16,6 @@ import { PRIVATE_USE_OFFSET_END, PRIVATE_USE_OFFSET_START, ProblematicCharRanges } from '../../src/core/fonts'; -import { isInt } from '../../src/shared/util'; /** * Used to validate the entries in `ProblematicCharRanges`, and to ensure that @@ -41,7 +40,7 @@ var checkProblematicCharRanges = function checkProblematicCharRanges() { lower: ProblematicCharRanges[i], upper: ProblematicCharRanges[i + 1], }; - if (!isInt(limits.lower) || !isInt(limits.upper)) { + if (!Number.isInteger(limits.lower) || !Number.isInteger(limits.upper)) { throw new Error('Range endpoints must be integers: ' + printRange(limits)); }