Merge pull request #8864 from Snuffleupagus/rm-isArray

Replace the `isArray` helper function with the native `Array.isArray` function
This commit is contained in:
Tim van der Meij 2017-09-01 23:08:44 +02:00 committed by GitHub
commit 336d26dd13
17 changed files with 77 additions and 87 deletions

View File

@ -15,7 +15,7 @@
import { import {
AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag, AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag,
AnnotationType, isArray, OPS, stringToBytes, stringToPDFString, Util, warn AnnotationType, OPS, stringToBytes, stringToPDFString, Util, warn
} from '../shared/util'; } from '../shared/util';
import { Catalog, FileSpec, ObjectLoader } from './obj'; import { Catalog, FileSpec, ObjectLoader } from './obj';
import { Dict, isDict, isName, isRef, isStream } from './primitives'; import { Dict, isDict, isName, isRef, isStream } from './primitives';
@ -236,7 +236,7 @@ class Annotation {
* @param {Array} rectangle - The rectangle array with exactly four entries * @param {Array} rectangle - The rectangle array with exactly four entries
*/ */
setRectangle(rectangle) { setRectangle(rectangle) {
if (isArray(rectangle) && rectangle.length === 4) { if (Array.isArray(rectangle) && rectangle.length === 4) {
this.rectangle = Util.normalizeRect(rectangle); this.rectangle = Util.normalizeRect(rectangle);
} else { } else {
this.rectangle = [0, 0, 0, 0]; this.rectangle = [0, 0, 0, 0];
@ -254,7 +254,7 @@ class Annotation {
*/ */
setColor(color) { setColor(color) {
let rgbColor = new Uint8Array(3); // Black in RGB color space (default) let rgbColor = new Uint8Array(3); // Black in RGB color space (default)
if (!isArray(color)) { if (!Array.isArray(color)) {
this.color = rgbColor; this.color = rgbColor;
return; return;
} }
@ -308,7 +308,7 @@ class Annotation {
} }
} else if (borderStyle.has('Border')) { } else if (borderStyle.has('Border')) {
let array = borderStyle.getArray('Border'); let array = borderStyle.getArray('Border');
if (isArray(array) && array.length >= 3) { if (Array.isArray(array) && array.length >= 3) {
this.borderStyle.setHorizontalCornerRadius(array[0]); this.borderStyle.setHorizontalCornerRadius(array[0]);
this.borderStyle.setVerticalCornerRadius(array[1]); this.borderStyle.setVerticalCornerRadius(array[1]);
this.borderStyle.setWidth(array[2]); this.borderStyle.setWidth(array[2]);
@ -504,7 +504,7 @@ class AnnotationBorderStyle {
// We validate the dash array, but we do not use it because CSS does not // We validate the dash array, but we do not use it because CSS does not
// allow us to change spacing of dashes. For more information, visit // allow us to change spacing of dashes. For more information, visit
// http://www.w3.org/TR/css3-background/#the-border-style. // http://www.w3.org/TR/css3-background/#the-border-style.
if (isArray(dashArray) && dashArray.length > 0) { if (Array.isArray(dashArray) && dashArray.length > 0) {
// According to the PDF specification: the elements in `dashArray` // According to the PDF specification: the elements in `dashArray`
// shall be numbers that are nonnegative and not all equal to zero. // shall be numbers that are nonnegative and not all equal to zero.
let isValid = true; let isValid = true;
@ -775,11 +775,11 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
this.data.options = []; this.data.options = [];
let options = Util.getInheritableProperty(params.dict, 'Opt'); let options = Util.getInheritableProperty(params.dict, 'Opt');
if (isArray(options)) { if (Array.isArray(options)) {
let xref = params.xref; let xref = params.xref;
for (let i = 0, ii = options.length; i < ii; i++) { for (let i = 0, ii = options.length; i < ii; i++) {
let option = xref.fetchIfRef(options[i]); let option = xref.fetchIfRef(options[i]);
let isOptionArray = isArray(option); let isOptionArray = Array.isArray(option);
this.data.options[i] = { this.data.options[i] = {
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option, exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
@ -791,7 +791,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
// Determine the field value. In this case, it may be a string or an // Determine the field value. In this case, it may be a string or an
// array of strings. For convenience in the display layer, convert the // array of strings. For convenience in the display layer, convert the
// string to an array of one string as well. // string to an array of one string as well.
if (!isArray(this.data.fieldValue)) { if (!Array.isArray(this.data.fieldValue)) {
this.data.fieldValue = [this.data.fieldValue]; this.data.fieldValue = [this.data.fieldValue];
} }

View File

@ -14,7 +14,7 @@
*/ */
import { import {
bytesToString, FormatError, info, isArray, stringToBytes, Util, warn bytesToString, FormatError, info, stringToBytes, Util, warn
} from '../shared/util'; } from '../shared/util';
import { import {
ExpertCharset, ExpertSubsetCharset, ISOAdobeCharset ExpertCharset, ExpertSubsetCharset, ISOAdobeCharset
@ -676,7 +676,7 @@ var CFFParser = (function CFFParserClosure() {
} }
var privateOffset = parentDict.getByName('Private'); var privateOffset = parentDict.getByName('Private');
// make sure the params are formatted correctly // make sure the params are formatted correctly
if (!isArray(privateOffset) || privateOffset.length !== 2) { if (!Array.isArray(privateOffset) || privateOffset.length !== 2) {
parentDict.removeByName('Private'); parentDict.removeByName('Private');
return; return;
} }
@ -1037,12 +1037,13 @@ var CFFDict = (function CFFDictClosure() {
}; };
for (var i = 0, ii = layout.length; i < ii; ++i) { for (var i = 0, ii = layout.length; i < ii; ++i) {
var entry = layout[i]; var entry = layout[i];
var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0]; var key = Array.isArray(entry[0]) ?
(entry[0][0] << 8) + entry[0][1] : entry[0];
tables.keyToNameMap[key] = entry[1]; tables.keyToNameMap[key] = entry[1];
tables.nameToKeyMap[entry[1]] = key; tables.nameToKeyMap[entry[1]] = key;
tables.types[key] = entry[2]; tables.types[key] = entry[2];
tables.defaults[key] = entry[3]; tables.defaults[key] = entry[3];
tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]]; tables.opcodes[key] = Array.isArray(entry[0]) ? entry[0] : [entry[0]];
tables.order.push(key); tables.order.push(key);
} }
return tables; return tables;
@ -1487,10 +1488,10 @@ var CFFCompiler = (function CFFCompilerClosure() {
} }
var values = dict.values[key]; var values = dict.values[key];
var types = dict.types[key]; var types = dict.types[key];
if (!isArray(types)) { if (!Array.isArray(types)) {
types = [types]; types = [types];
} }
if (!isArray(values)) { if (!Array.isArray(values)) {
values = [values]; values = [values];
} }

View File

@ -13,9 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { FormatError, info, isString, shadow, warn } from '../shared/util';
FormatError, info, isArray, isString, shadow, warn
} from '../shared/util';
import { isDict, isName, isStream } from './primitives'; import { isDict, isName, isStream } from './primitives';
import { PDFFunction } from './function'; import { PDFFunction } from './function';
@ -211,7 +209,7 @@ var ColorSpace = (function ColorSpaceClosure() {
}; };
ColorSpace.fromIR = function ColorSpace_fromIR(IR) { ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
var name = isArray(IR) ? IR[0] : IR; var name = Array.isArray(IR) ? IR[0] : IR;
var whitePoint, blackPoint, gamma; var whitePoint, blackPoint, gamma;
switch (name) { switch (name) {
@ -289,7 +287,7 @@ var ColorSpace = (function ColorSpaceClosure() {
throw new FormatError(`unrecognized colorspace ${cs.name}`); throw new FormatError(`unrecognized colorspace ${cs.name}`);
} }
} }
if (isArray(cs)) { if (Array.isArray(cs)) {
var mode = xref.fetchIfRef(cs[0]).name; var mode = xref.fetchIfRef(cs[0]).name;
var numComps, params, alt, whitePoint, blackPoint, gamma; var numComps, params, alt, whitePoint, blackPoint, gamma;
@ -357,7 +355,7 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'Separation': case 'Separation':
case 'DeviceN': case 'DeviceN':
var name = xref.fetchIfRef(cs[1]); var name = xref.fetchIfRef(cs[1]);
numComps = isArray(name) ? name.length : 1; numComps = Array.isArray(name) ? name.length : 1;
alt = ColorSpace.parseToIR(cs[2], xref, res); alt = ColorSpace.parseToIR(cs[2], xref, res);
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
return ['AlternateCS', numComps, alt, tintFnIR]; return ['AlternateCS', numComps, alt, tintFnIR];
@ -383,7 +381,7 @@ var ColorSpace = (function ColorSpaceClosure() {
* @param {Number} n Number of components the color space has. * @param {Number} n Number of components the color space has.
*/ */
ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) { ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
if (!isArray(decode)) { if (!Array.isArray(decode)) {
return true; return true;
} }

View File

@ -16,8 +16,8 @@
import { Catalog, ObjectLoader, XRef } from './obj'; import { Catalog, ObjectLoader, XRef } from './obj';
import { Dict, isDict, isName, isStream } from './primitives'; import { Dict, isDict, isName, isStream } from './primitives';
import { import {
info, isArray, isArrayBuffer, isNum, isSpace, isString, MissingDataException, info, isArrayBuffer, isNum, isSpace, isString, MissingDataException, OPS,
OPS, shadow, stringToBytes, stringToPDFString, Util, warn shadow, stringToBytes, stringToPDFString, Util, warn
} from '../shared/util'; } from '../shared/util';
import { NullStream, Stream, StreamsSequenceStream } from './stream'; import { NullStream, Stream, StreamsSequenceStream } from './stream';
import { OperatorList, PartialEvaluator } from './evaluator'; import { OperatorList, PartialEvaluator } from './evaluator';
@ -107,7 +107,7 @@ var Page = (function PageClosure() {
get mediaBox() { get mediaBox() {
var mediaBox = this.getInheritedPageProp('MediaBox', true); var mediaBox = this.getInheritedPageProp('MediaBox', true);
// Reset invalid media box to letter size. // Reset invalid media box to letter size.
if (!isArray(mediaBox) || mediaBox.length !== 4) { if (!Array.isArray(mediaBox) || mediaBox.length !== 4) {
return shadow(this, 'mediaBox', LETTER_SIZE_MEDIABOX); return shadow(this, 'mediaBox', LETTER_SIZE_MEDIABOX);
} }
return shadow(this, 'mediaBox', mediaBox); return shadow(this, 'mediaBox', mediaBox);
@ -116,7 +116,7 @@ var Page = (function PageClosure() {
get cropBox() { get cropBox() {
var cropBox = this.getInheritedPageProp('CropBox', true); var cropBox = this.getInheritedPageProp('CropBox', true);
// Reset invalid crop box to media box. // Reset invalid crop box to media box.
if (!isArray(cropBox) || cropBox.length !== 4) { if (!Array.isArray(cropBox) || cropBox.length !== 4) {
return shadow(this, 'cropBox', this.mediaBox); return shadow(this, 'cropBox', this.mediaBox);
} }
return shadow(this, 'cropBox', cropBox); return shadow(this, 'cropBox', cropBox);
@ -161,7 +161,7 @@ var Page = (function PageClosure() {
getContentStream: function Page_getContentStream() { getContentStream: function Page_getContentStream() {
var content = this.content; var content = this.content;
var stream; var stream;
if (isArray(content)) { if (Array.isArray(content)) {
// fetching items // fetching items
var xref = this.xref; var xref = this.xref;
var i, n = content.length; var i, n = content.length;
@ -413,7 +413,7 @@ var PDFDocument = (function PDFDocumentClosure() {
if (this.acroForm) { if (this.acroForm) {
this.xfa = this.acroForm.get('XFA'); this.xfa = this.acroForm.get('XFA');
var fields = this.acroForm.get('Fields'); var fields = this.acroForm.get('Fields');
if ((!fields || !isArray(fields) || fields.length === 0) && if ((!fields || !Array.isArray(fields) || fields.length === 0) &&
!this.xfa) { !this.xfa) {
// no fields and no XFA -- not a form (?) // no fields and no XFA -- not a form (?)
this.acroForm = null; this.acroForm = null;
@ -576,7 +576,7 @@ var PDFDocument = (function PDFDocumentClosure() {
var xref = this.xref, hash, fileID = ''; var xref = this.xref, hash, fileID = '';
var idArray = xref.trailer.get('ID'); var idArray = xref.trailer.get('ID');
if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && if (Array.isArray(idArray) && idArray[0] && isString(idArray[0]) &&
idArray[0] !== EMPTY_FINGERPRINT) { idArray[0] !== EMPTY_FINGERPRINT) {
hash = stringToBytes(idArray[0]); hash = stringToBytes(idArray[0]);
} else { } else {

View File

@ -16,8 +16,8 @@
import { import {
AbortException, assert, CMapCompressionType, createPromiseCapability, AbortException, assert, CMapCompressionType, createPromiseCapability,
FONT_IDENTITY_MATRIX, FormatError, getLookupTableFactory, IDENTITY_MATRIX, FONT_IDENTITY_MATRIX, FormatError, getLookupTableFactory, IDENTITY_MATRIX,
ImageKind, info, isArray, isNum, isString, NativeImageDecoding, OPS, ImageKind, info, isNum, isString, NativeImageDecoding, OPS, TextRenderingMode,
TextRenderingMode, UNSUPPORTED_FEATURES, Util, warn UNSUPPORTED_FEATURES, Util, warn
} from '../shared/util'; } from '../shared/util';
import { CMapFactory, IdentityCMap } from './cmap'; import { CMapFactory, IdentityCMap } from './cmap';
import { DecodeStream, JpegStream, Stream } from './stream'; import { DecodeStream, JpegStream, Stream } from './stream';
@ -1663,7 +1663,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var xObjStateManager = new StateManager(currentState); var xObjStateManager = new StateManager(currentState);
var matrix = xobj.dict.getArray('Matrix'); var matrix = xobj.dict.getArray('Matrix');
if (isArray(matrix) && matrix.length === 6) { if (Array.isArray(matrix) && matrix.length === 6) {
xObjStateManager.transform(matrix); xObjStateManager.transform(matrix);
} }
@ -2089,7 +2089,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
for (i = 0, ii = widths.length; i < ii; i++) { for (i = 0, ii = widths.length; i < ii; i++) {
start = xref.fetchIfRef(widths[i++]); start = xref.fetchIfRef(widths[i++]);
code = xref.fetchIfRef(widths[i]); code = xref.fetchIfRef(widths[i]);
if (isArray(code)) { if (Array.isArray(code)) {
for (j = 0, jj = code.length; j < jj; j++) { for (j = 0, jj = code.length; j < jj; j++) {
glyphsWidths[start++] = xref.fetchIfRef(code[j]); glyphsWidths[start++] = xref.fetchIfRef(code[j]);
} }
@ -2110,7 +2110,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
for (i = 0, ii = vmetrics.length; i < ii; i++) { for (i = 0, ii = vmetrics.length; i < ii; i++) {
start = xref.fetchIfRef(vmetrics[i++]); start = xref.fetchIfRef(vmetrics[i++]);
code = xref.fetchIfRef(vmetrics[i]); code = xref.fetchIfRef(vmetrics[i]);
if (isArray(code)) { if (Array.isArray(code)) {
for (j = 0, jj = code.length; j < jj; j++) { for (j = 0, jj = code.length; j < jj; j++) {
glyphsVMetrics[start++] = [ glyphsVMetrics[start++] = [
xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]),
@ -2258,7 +2258,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (!df) { if (!df) {
throw new FormatError('Descendant fonts are not specified'); throw new FormatError('Descendant fonts are not specified');
} }
dict = (isArray(df) ? this.xref.fetchIfRef(df[0]) : df); dict = (Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df);
type = dict.get('Subtype'); type = dict.get('Subtype');
if (!isName(type)) { if (!isName(type)) {
@ -2283,7 +2283,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
hash.update(entry.name); hash.update(entry.name);
} else if (isRef(entry)) { } else if (isRef(entry)) {
hash.update(entry.toString()); hash.update(entry.toString());
} else if (isArray(entry)) { } else if (Array.isArray(entry)) {
// 'Differences' array (fixes bug1157493.pdf). // 'Differences' array (fixes bug1157493.pdf).
var diffLength = entry.length, diffBuf = new Array(diffLength); var diffLength = entry.length, diffBuf = new Array(diffLength);

View File

@ -14,8 +14,8 @@
*/ */
import { import {
bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info, isArray, bytesToString, FONT_IDENTITY_MATRIX, FontType, FormatError, info, isNum,
isNum, isSpace, MissingDataException, readUint32, shadow, string32, warn isSpace, MissingDataException, readUint32, shadow, string32, warn
} from '../shared/util'; } from '../shared/util';
import { import {
CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict, CFF, CFFCharset, CFFCompiler, CFFHeader, CFFIndex, CFFParser, CFFPrivateDict,
@ -3250,7 +3250,7 @@ var Type1Font = (function Type1FontClosure() {
continue; continue;
} }
var value = properties.privateData[field]; var value = properties.privateData[field];
if (isArray(value)) { if (Array.isArray(value)) {
// All of the private dictionary array data in CFF must be stored as // All of the private dictionary array data in CFF must be stored as
// "delta-encoded" numbers. // "delta-encoded" numbers.
for (var j = value.length - 1; j > 0; j--) { for (var j = value.length - 1; j > 0; j--) {

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { FormatError, info, isArray, isBool } from '../shared/util'; import { FormatError, info, isBool } 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';
@ -96,7 +96,7 @@ var PDFFunction = (function PDFFunctionClosure() {
}, },
parseArray: function PDFFunction_parseArray(xref, fnObj) { parseArray: function PDFFunction_parseArray(xref, fnObj) {
if (!isArray(fnObj)) { if (!Array.isArray(fnObj)) {
// not an array -- parsing as regular function // not an array -- parsing as regular function
return this.parse(xref, fnObj); return this.parse(xref, fnObj);
} }
@ -262,7 +262,7 @@ var PDFFunction = (function PDFFunctionClosure() {
var c1 = dict.getArray('C1') || [1]; var c1 = dict.getArray('C1') || [1];
var n = dict.get('N'); var n = dict.get('N');
if (!isArray(c0) || !isArray(c1)) { if (!Array.isArray(c0) || !Array.isArray(c1)) {
throw new FormatError( throw new FormatError(
'Illegal dictionary for interpolated function'); 'Illegal dictionary for interpolated function');
} }

View File

@ -13,9 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { assert, FormatError, ImageKind, info, warn } from '../shared/util';
assert, FormatError, ImageKind, info, isArray, warn
} from '../shared/util';
import { DecodeStream, JpegStream } from './stream'; import { DecodeStream, JpegStream } from './stream';
import { isStream, Name } from './primitives'; import { isStream, Name } from './primitives';
import { ColorSpace } from './colorspace'; import { ColorSpace } from './colorspace';
@ -199,7 +197,7 @@ var PDFImage = (function PDFImageClosure() {
if (mask) { if (mask) {
if (isStream(mask)) { if (isStream(mask)) {
maskPromise = handleImageData(mask, nativeDecoder); maskPromise = handleImageData(mask, nativeDecoder);
} else if (isArray(mask)) { } else if (Array.isArray(mask)) {
maskPromise = Promise.resolve(mask); maskPromise = Promise.resolve(mask);
} else { } else {
warn('Unsupported mask format.'); warn('Unsupported mask format.');
@ -408,7 +406,7 @@ var PDFImage = (function PDFImageClosure() {
alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
width, height); width, height);
} }
} else if (isArray(mask)) { } else if (Array.isArray(mask)) {
// Color key mask: if any of the components are outside the range // Color key mask: if any of the components are outside the range
// then they should be painted. // then they should be painted.
alphaBuf = new Uint8Array(width * height); alphaBuf = new Uint8Array(width * height);

View File

@ -15,8 +15,8 @@
import { import {
bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError, bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError,
info, InvalidPDFException, isArray, isBool, isString, MissingDataException, info, InvalidPDFException, isBool, isString, MissingDataException, shadow,
shadow, stringToPDFString, stringToUTF8String, Util, warn, XRefParseException stringToPDFString, stringToUTF8String, 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,
@ -136,7 +136,7 @@ var Catalog = (function CatalogClosure() {
var color = outlineDict.getArray('C'), rgbColor = blackColor; var color = outlineDict.getArray('C'), rgbColor = blackColor;
// We only need to parse the color when it's valid, and non-default. // We only need to parse the color when it's valid, and non-default.
if (isArray(color) && color.length === 3 && if (Array.isArray(color) && color.length === 3 &&
(color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) { (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0); rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
} }
@ -507,7 +507,7 @@ var Catalog = (function CatalogClosure() {
} }
var kids = currentNode.get('Kids'); var kids = currentNode.get('Kids');
if (!isArray(kids)) { if (!Array.isArray(kids)) {
capability.reject(new FormatError( capability.reject(new FormatError(
'page dictionary kids object is not an array')); 'page dictionary kids object is not an array'));
return; return;
@ -707,7 +707,7 @@ var Catalog = (function CatalogClosure() {
let baseUrl = url.split('#')[0]; let baseUrl = url.split('#')[0];
if (isString(remoteDest)) { if (isString(remoteDest)) {
url = baseUrl + '#' + remoteDest; url = baseUrl + '#' + remoteDest;
} else if (isArray(remoteDest)) { } else if (Array.isArray(remoteDest)) {
url = baseUrl + '#' + JSON.stringify(remoteDest); url = baseUrl + '#' + JSON.stringify(remoteDest);
} }
} }
@ -778,7 +778,7 @@ var Catalog = (function CatalogClosure() {
if (isName(dest)) { if (isName(dest)) {
dest = dest.name; dest = dest.name;
} }
if (isString(dest) || isArray(dest)) { if (isString(dest) || Array.isArray(dest)) {
resultObj.dest = dest; resultObj.dest = dest;
} }
} }
@ -1501,7 +1501,7 @@ var NameOrNumberTree = (function NameOrNumberTreeClosure() {
continue; continue;
} }
var entries = obj.get(this._type); var entries = obj.get(this._type);
if (isArray(entries)) { if (Array.isArray(entries)) {
for (i = 0, n = entries.length; i < n; i += 2) { for (i = 0, n = entries.length; i < n; i += 2) {
dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]); dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
} }
@ -1530,7 +1530,7 @@ var NameOrNumberTree = (function NameOrNumberTreeClosure() {
} }
var kids = kidsOrEntries.get('Kids'); var kids = kidsOrEntries.get('Kids');
if (!isArray(kids)) { if (!Array.isArray(kids)) {
return null; return null;
} }
@ -1558,7 +1558,7 @@ var NameOrNumberTree = (function NameOrNumberTreeClosure() {
// If we get here, then we have found the right entry. Now go through the // If we get here, then we have found the right entry. Now go through the
// entries in the dictionary until we find the key we're looking for. // entries in the dictionary until we find the key we're looking for.
var entries = kidsOrEntries.get(this._type); var entries = kidsOrEntries.get(this._type);
if (isArray(entries)) { if (Array.isArray(entries)) {
// Perform a binary search to reduce the lookup time. // Perform a binary search to reduce the lookup time.
l = 0; l = 0;
r = entries.length - 2; r = entries.length - 2;
@ -1709,7 +1709,8 @@ var FileSpec = (function FileSpecClosure() {
*/ */
let ObjectLoader = (function() { let ObjectLoader = (function() {
function mayHaveChildren(value) { function mayHaveChildren(value) {
return isRef(value) || isDict(value) || isArray(value) || isStream(value); return isRef(value) || isDict(value) || Array.isArray(value) ||
isStream(value);
} }
function addChildren(node, nodesToVisit) { function addChildren(node, nodesToVisit) {
@ -1722,7 +1723,7 @@ let ObjectLoader = (function() {
nodesToVisit.push(rawValue); nodesToVisit.push(rawValue);
} }
} }
} else if (isArray(node)) { } else if (Array.isArray(node)) {
for (let i = 0, ii = node.length; i < ii; i++) { for (let i = 0, ii = node.length; i < ii; i++) {
let value = node[i]; let value = node[i];
if (mayHaveChildren(value)) { if (mayHaveChildren(value)) {

View File

@ -18,8 +18,8 @@ import {
JpegStream, JpxStream, LZWStream, NullStream, PredictorStream, RunLengthStream JpegStream, JpxStream, LZWStream, NullStream, PredictorStream, RunLengthStream
} from './stream'; } from './stream';
import { import {
assert, FormatError, info, isArray, isNum, isString, MissingDataException, assert, FormatError, info, isNum, isString, MissingDataException, StreamType,
StreamType, warn warn
} from '../shared/util'; } from '../shared/util';
import { import {
Cmd, Dict, EOF, isCmd, isDict, isEOF, isName, Name, Ref Cmd, Dict, EOF, isCmd, isDict, isEOF, isName, Name, Ref
@ -384,7 +384,7 @@ var Parser = (function ParserClosure() {
var filter = dict.get('Filter', 'F'), filterName; var filter = dict.get('Filter', 'F'), filterName;
if (isName(filter)) { if (isName(filter)) {
filterName = filter.name; filterName = filter.name;
} else if (isArray(filter)) { } else if (Array.isArray(filter)) {
var filterZero = this.xref.fetchIfRef(filter[0]); var filterZero = this.xref.fetchIfRef(filter[0]);
if (isName(filterZero)) { if (isName(filterZero)) {
filterName = filterZero.name; filterName = filterZero.name;
@ -527,14 +527,14 @@ var Parser = (function ParserClosure() {
var filter = dict.get('Filter', 'F'); var filter = dict.get('Filter', 'F');
var params = dict.get('DecodeParms', 'DP'); var params = dict.get('DecodeParms', 'DP');
if (isName(filter)) { if (isName(filter)) {
if (isArray(params)) { if (Array.isArray(params)) {
params = this.xref.fetchIfRef(params[0]); params = this.xref.fetchIfRef(params[0]);
} }
return this.makeFilter(stream, filter.name, length, params); return this.makeFilter(stream, filter.name, length, params);
} }
var maybeLength = length; var maybeLength = length;
if (isArray(filter)) { if (Array.isArray(filter)) {
var filterArray = filter; var filterArray = filter;
var paramsArray = params; var paramsArray = params;
for (var i = 0, ii = filterArray.length; i < ii; ++i) { for (var i = 0, ii = filterArray.length; i < ii; ++i) {
@ -544,7 +544,7 @@ var Parser = (function ParserClosure() {
} }
params = null; params = null;
if (isArray(paramsArray) && (i in paramsArray)) { if (Array.isArray(paramsArray) && (i in paramsArray)) {
params = this.xref.fetchIfRef(paramsArray[i]); params = this.xref.fetchIfRef(paramsArray[i]);
} }
stream = this.makeFilter(stream, filter.name, maybeLength, params); stream = this.makeFilter(stream, filter.name, maybeLength, params);
@ -1077,7 +1077,7 @@ var Linearization = {
} }
function getHints() { function getHints() {
var hints = linDict.get('H'), hintsLength, item; var hints = linDict.get('H'), hintsLength, item;
if (isArray(hints) && if (Array.isArray(hints) &&
((hintsLength = hints.length) === 2 || hintsLength === 4)) { ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
for (var index = 0; index < hintsLength; index++) { for (var index = 0; index < hintsLength; index++) {
if (!(Number.isInteger(item = hints[index]) && item > 0)) { if (!(Number.isInteger(item = hints[index]) && item > 0)) {

View File

@ -14,8 +14,6 @@
*/ */
/* uses XRef */ /* uses XRef */
import { isArray } from '../shared/util';
var EOF = {}; var EOF = {};
var Name = (function NameClosure() { var Name = (function NameClosure() {
@ -117,7 +115,7 @@ var Dict = (function DictClosure() {
getArray: function Dict_getArray(key1, key2, key3) { getArray: function Dict_getArray(key1, key2, key3) {
var value = this.get(key1, key2, key3); var value = this.get(key1, key2, key3);
var xref = this.xref, suppressEncryption = this.suppressEncryption; var xref = this.xref, suppressEncryption = this.suppressEncryption;
if (!isArray(value) || !xref) { if (!Array.isArray(value) || !xref) {
return value; return value;
} }
value = value.slice(); // Ensure that we don't modify the Dict data. value = value.slice(); // Ensure that we don't modify the Dict data.

View File

@ -14,7 +14,7 @@
*/ */
import { import {
createObjectURL, FormatError, info, isArray, isSpace, shadow, Util createObjectURL, FormatError, info, isSpace, shadow, Util
} from '../shared/util'; } from '../shared/util';
import { Dict, isDict, isStream } from './primitives'; import { Dict, isDict, isStream } from './primitives';
import { Jbig2Image } from './jbig2'; import { Jbig2Image } from './jbig2';
@ -907,7 +907,7 @@ var JpegStream = (function JpegStreamClosure() {
// Checking if values need to be transformed before conversion. // Checking if values need to be transformed before conversion.
var decodeArr = this.dict.getArray('Decode', 'D'); var decodeArr = this.dict.getArray('Decode', 'D');
if (this.forceRGB && isArray(decodeArr)) { if (this.forceRGB && Array.isArray(decodeArr)) {
var bitsPerComponent = this.dict.get('BitsPerComponent') || 8; var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
var decodeArrLength = decodeArr.length; var decodeArrLength = decodeArr.length;
var transform = new Int32Array(decodeArrLength); var transform = new Int32Array(decodeArrLength);

View File

@ -14,8 +14,8 @@
*/ */
import { import {
FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, info, isArray, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, info, isLittleEndian, isNum,
isLittleEndian, isNum, OPS, shadow, TextRenderingMode, Util, warn OPS, shadow, TextRenderingMode, Util, warn
} from '../shared/util'; } from '../shared/util';
import { getShadingPatternFromIR, TilingPattern } from './pattern_helper'; import { getShadingPatternFromIR, TilingPattern } from './pattern_helper';
import { WebGLUtils } from './webgl'; import { WebGLUtils } from './webgl';
@ -1727,13 +1727,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.save(); this.save();
this.baseTransformStack.push(this.baseTransform); this.baseTransformStack.push(this.baseTransform);
if (isArray(matrix) && matrix.length === 6) { if (Array.isArray(matrix) && matrix.length === 6) {
this.transform.apply(this, matrix); this.transform.apply(this, matrix);
} }
this.baseTransform = this.ctx.mozCurrentTransform; this.baseTransform = this.ctx.mozCurrentTransform;
if (isArray(bbox) && bbox.length === 4) { if (Array.isArray(bbox) && bbox.length === 4) {
var width = bbox[2] - bbox[0]; var width = bbox[2] - bbox[0];
var height = bbox[3] - bbox[1]; var height = bbox[3] - bbox[1];
this.ctx.rect(bbox[0], bbox[1], width, height); this.ctx.rect(bbox[0], bbox[1], width, height);
@ -1896,7 +1896,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
resetCtxToDefault(this.ctx); resetCtxToDefault(this.ctx);
this.current = new CanvasExtraState(); this.current = new CanvasExtraState();
if (isArray(rect) && rect.length === 4) { if (Array.isArray(rect) && rect.length === 4) {
var width = rect[2] - rect[0]; var width = rect[2] - rect[0];
var height = rect[3] - rect[1]; var height = rect[3] - rect[1];
this.ctx.rect(rect[0], rect[1], width, height); this.ctx.rect(rect[0], rect[1], width, height);

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { FormatError, info, isArray, Util } from '../shared/util'; import { FormatError, info, Util } from '../shared/util';
import { WebGLUtils } from './webgl'; import { WebGLUtils } from './webgl';
var ShadingIRs = {}; var ShadingIRs = {};
@ -391,7 +391,7 @@ var TilingPattern = (function TilingPatternClosure() {
}, },
clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) { clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
if (isArray(bbox) && bbox.length === 4) { if (Array.isArray(bbox) && bbox.length === 4) {
var bboxWidth = x1 - x0; var bboxWidth = x1 - x0;
var bboxHeight = y1 - y0; var bboxHeight = y1 - y0;
graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight); graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);

View File

@ -15,8 +15,8 @@
/* globals __non_webpack_require__ */ /* globals __non_webpack_require__ */
import { import {
createObjectURL, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, isArray, createObjectURL, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, isNodeJS,
isNodeJS, isNum, OPS, Util, warn isNum, OPS, Util, warn
} from '../shared/util'; } from '../shared/util';
var SVGGraphics = function() { var SVGGraphics = function() {
@ -1199,12 +1199,12 @@ SVGGraphics = (function SVGGraphicsClosure() {
paintFormXObjectBegin: paintFormXObjectBegin:
function SVGGraphics_paintFormXObjectBegin(matrix, bbox) { function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
if (isArray(matrix) && matrix.length === 6) { if (Array.isArray(matrix) && matrix.length === 6) {
this.transform(matrix[0], matrix[1], matrix[2], this.transform(matrix[0], matrix[1], matrix[2],
matrix[3], matrix[4], matrix[5]); matrix[3], matrix[4], matrix[5]);
} }
if (isArray(bbox) && bbox.length === 4) { if (Array.isArray(bbox) && bbox.length === 4) {
var width = bbox[2] - bbox[0]; var width = bbox[2] - bbox[0];
var height = bbox[3] - bbox[1]; var height = bbox[3] - bbox[1];

View File

@ -1083,10 +1083,6 @@ function isString(v) {
return typeof v === 'string'; return typeof v === 'string';
} }
function isArray(v) {
return v instanceof Array;
}
function isArrayBuffer(v) { function isArrayBuffer(v) {
return typeof v === 'object' && v !== null && v.byteLength !== undefined; return typeof v === 'object' && v !== null && v.byteLength !== undefined;
} }
@ -1695,7 +1691,6 @@ export {
getLookupTableFactory, getLookupTableFactory,
getVerbosityLevel, getVerbosityLevel,
info, info,
isArray,
isArrayBuffer, isArrayBuffer,
isBool, isBool,
isEmptyObj, isEmptyObj,

View File

@ -17,7 +17,6 @@ import {
PostScriptCompiler, PostScriptEvaluator PostScriptCompiler, PostScriptEvaluator
} from '../../src/core/function'; } from '../../src/core/function';
import { PostScriptLexer, PostScriptParser } from '../../src/core/ps_parser'; import { PostScriptLexer, PostScriptParser } from '../../src/core/ps_parser';
import { isArray } from '../../src/shared/util';
import { StringStream } from '../../src/core/stream'; import { StringStream } from '../../src/core/stream';
describe('function', function() { describe('function', function() {
@ -36,7 +35,7 @@ describe('function', function() {
result.pass = true; result.pass = true;
for (var i = 0; i < expected.length; i++) { for (var i = 0; i < expected.length; i++) {
var a = actual[i], b = expected[i]; var a = actual[i], b = expected[i];
if (isArray(b)) { if (Array.isArray(b)) {
if (a.length !== b.length) { if (a.length !== b.length) {
result.pass = false; result.pass = false;
break; break;