Merge pull request #14596 from Snuffleupagus/rm-isNum
Remove the `isNum` helper function
This commit is contained in:
commit
b2f6844ce3
@ -26,7 +26,6 @@ import {
|
|||||||
FormatError,
|
FormatError,
|
||||||
info,
|
info,
|
||||||
isBool,
|
isBool,
|
||||||
isNum,
|
|
||||||
isString,
|
isString,
|
||||||
objectSize,
|
objectSize,
|
||||||
PermissionFlag,
|
PermissionFlag,
|
||||||
@ -381,7 +380,7 @@ class Catalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let flags = encrypt.get("P");
|
let flags = encrypt.get("P");
|
||||||
if (!isNum(flags)) {
|
if (typeof flags !== "number") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1475,7 +1474,7 @@ class Catalog {
|
|||||||
switch (actionName) {
|
switch (actionName) {
|
||||||
case "ResetForm":
|
case "ResetForm":
|
||||||
const flags = action.get("Flags");
|
const flags = action.get("Flags");
|
||||||
const include = ((isNum(flags) ? flags : 0) & 1) === 0;
|
const include = ((typeof flags === "number" ? flags : 0) & 1) === 0;
|
||||||
const fields = [];
|
const fields = [];
|
||||||
const refs = [];
|
const refs = [];
|
||||||
for (const obj of action.get("Fields") || []) {
|
for (const obj of action.get("Fields") || []) {
|
||||||
|
@ -20,8 +20,6 @@ import {
|
|||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
isArrayBuffer,
|
isArrayBuffer,
|
||||||
isArrayEqual,
|
isArrayEqual,
|
||||||
isBool,
|
|
||||||
isNum,
|
|
||||||
isString,
|
isString,
|
||||||
OPS,
|
OPS,
|
||||||
PageActionEventType,
|
PageActionEventType,
|
||||||
@ -177,7 +175,7 @@ class Page {
|
|||||||
|
|
||||||
get userUnit() {
|
get userUnit() {
|
||||||
let obj = this.pageDict.get("UserUnit");
|
let obj = this.pageDict.get("UserUnit");
|
||||||
if (!isNum(obj) || obj <= 0) {
|
if (typeof obj !== "number" || obj <= 0) {
|
||||||
obj = DEFAULT_USER_UNIT;
|
obj = DEFAULT_USER_UNIT;
|
||||||
}
|
}
|
||||||
return shadow(this, "userUnit", obj);
|
return shadow(this, "userUnit", obj);
|
||||||
@ -1193,10 +1191,15 @@ class PDFDocument {
|
|||||||
// For custom values, only accept white-listed types to prevent
|
// For custom values, only accept white-listed types to prevent
|
||||||
// errors that would occur when trying to send non-serializable
|
// errors that would occur when trying to send non-serializable
|
||||||
// objects to the main-thread (for example `Dict` or `Stream`).
|
// objects to the main-thread (for example `Dict` or `Stream`).
|
||||||
|
const customType = typeof value;
|
||||||
let customValue;
|
let customValue;
|
||||||
if (isString(value)) {
|
if (customType === "string") {
|
||||||
customValue = stringToPDFString(value);
|
customValue = stringToPDFString(value);
|
||||||
} else if (value instanceof Name || isNum(value) || isBool(value)) {
|
} else if (
|
||||||
|
value instanceof Name ||
|
||||||
|
customType === "number" ||
|
||||||
|
customType === "boolean"
|
||||||
|
) {
|
||||||
customValue = value;
|
customValue = value;
|
||||||
} else {
|
} else {
|
||||||
info(`Unsupported value in document info for (custom) "${key}".`);
|
info(`Unsupported value in document info for (custom) "${key}".`);
|
||||||
|
@ -24,7 +24,6 @@ import {
|
|||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
info,
|
info,
|
||||||
isArrayEqual,
|
isArrayEqual,
|
||||||
isNum,
|
|
||||||
isString,
|
isString,
|
||||||
OPS,
|
OPS,
|
||||||
shadow,
|
shadow,
|
||||||
@ -572,7 +571,7 @@ class PartialEvaluator {
|
|||||||
const w = dict.get("W", "Width");
|
const w = dict.get("W", "Width");
|
||||||
const h = dict.get("H", "Height");
|
const h = dict.get("H", "Height");
|
||||||
|
|
||||||
if (!(w && isNum(w)) || !(h && isNum(h))) {
|
if (!(w && typeof w === "number") || !(h && typeof h === "number")) {
|
||||||
warn("Image dimensions are missing, or not numbers.");
|
warn("Image dimensions are missing, or not numbers.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1790,7 +1789,7 @@ class PartialEvaluator {
|
|||||||
combinedGlyphs,
|
combinedGlyphs,
|
||||||
self.handleText(arrItem, state)
|
self.handleText(arrItem, state)
|
||||||
);
|
);
|
||||||
} else if (isNum(arrItem)) {
|
} else if (typeof arrItem === "number") {
|
||||||
combinedGlyphs.push(arrItem);
|
combinedGlyphs.push(arrItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3224,7 +3223,7 @@ class PartialEvaluator {
|
|||||||
let index = 0;
|
let index = 0;
|
||||||
for (let j = 0, jj = diffEncoding.length; j < jj; j++) {
|
for (let j = 0, jj = diffEncoding.length; j < jj; j++) {
|
||||||
const data = xref.fetchIfRef(diffEncoding[j]);
|
const data = xref.fetchIfRef(diffEncoding[j]);
|
||||||
if (isNum(data)) {
|
if (typeof data === "number") {
|
||||||
index = data;
|
index = data;
|
||||||
} else if (data instanceof Name) {
|
} else if (data instanceof Name) {
|
||||||
differences[index++] = data.name;
|
differences[index++] = data.name;
|
||||||
@ -3703,7 +3702,7 @@ class PartialEvaluator {
|
|||||||
}
|
}
|
||||||
const glyphWidths = Metrics[lookupName];
|
const glyphWidths = Metrics[lookupName];
|
||||||
|
|
||||||
if (isNum(glyphWidths)) {
|
if (typeof glyphWidths === "number") {
|
||||||
defaultWidth = glyphWidths;
|
defaultWidth = glyphWidths;
|
||||||
monospace = true;
|
monospace = true;
|
||||||
} else {
|
} else {
|
||||||
@ -3790,7 +3789,10 @@ class PartialEvaluator {
|
|||||||
const diffEntry = entry[j];
|
const diffEntry = entry[j];
|
||||||
if (diffEntry instanceof Name) {
|
if (diffEntry instanceof Name) {
|
||||||
diffBuf[j] = diffEntry.name;
|
diffBuf[j] = diffEntry.name;
|
||||||
} else if (isNum(diffEntry) || diffEntry instanceof Ref) {
|
} else if (
|
||||||
|
typeof diffEntry === "number" ||
|
||||||
|
diffEntry instanceof Ref
|
||||||
|
) {
|
||||||
diffBuf[j] = diffEntry.toString();
|
diffBuf[j] = diffEntry.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3820,7 +3822,7 @@ class PartialEvaluator {
|
|||||||
if (Array.isArray(widths)) {
|
if (Array.isArray(widths)) {
|
||||||
const widthsBuf = [];
|
const widthsBuf = [];
|
||||||
for (const entry of widths) {
|
for (const entry of widths) {
|
||||||
if (isNum(entry) || entry instanceof Ref) {
|
if (typeof entry === "number" || entry instanceof Ref) {
|
||||||
widthsBuf.push(entry.toString());
|
widthsBuf.push(entry.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3834,12 +3836,12 @@ class PartialEvaluator {
|
|||||||
if (Array.isArray(compositeWidths)) {
|
if (Array.isArray(compositeWidths)) {
|
||||||
const widthsBuf = [];
|
const widthsBuf = [];
|
||||||
for (const entry of compositeWidths) {
|
for (const entry of compositeWidths) {
|
||||||
if (isNum(entry) || entry instanceof Ref) {
|
if (typeof entry === "number" || entry instanceof Ref) {
|
||||||
widthsBuf.push(entry.toString());
|
widthsBuf.push(entry.toString());
|
||||||
} else if (Array.isArray(entry)) {
|
} else if (Array.isArray(entry)) {
|
||||||
const subWidthsBuf = [];
|
const subWidthsBuf = [];
|
||||||
for (const element of entry) {
|
for (const element of entry) {
|
||||||
if (isNum(element) || element instanceof Ref) {
|
if (typeof element === "number" || element instanceof Ref) {
|
||||||
subWidthsBuf.push(element.toString());
|
subWidthsBuf.push(element.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import {
|
|||||||
FontType,
|
FontType,
|
||||||
FormatError,
|
FormatError,
|
||||||
info,
|
info,
|
||||||
isNum,
|
|
||||||
shadow,
|
shadow,
|
||||||
string32,
|
string32,
|
||||||
warn,
|
warn,
|
||||||
@ -3184,7 +3183,9 @@ class Font {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
width = this.widths[widthCode];
|
width = this.widths[widthCode];
|
||||||
width = isNum(width) ? width : this.defaultWidth;
|
if (typeof width !== "number") {
|
||||||
|
width = this.defaultWidth;
|
||||||
|
}
|
||||||
const vmetric = this.vmetrics && this.vmetrics[widthCode];
|
const vmetric = this.vmetrics && this.vmetrics[widthCode];
|
||||||
|
|
||||||
let unicode = this.toUnicode.get(charcode) || charcode;
|
let unicode = this.toUnicode.get(charcode) || charcode;
|
||||||
|
@ -18,7 +18,6 @@ import {
|
|||||||
bytesToString,
|
bytesToString,
|
||||||
FormatError,
|
FormatError,
|
||||||
info,
|
info,
|
||||||
isNum,
|
|
||||||
StreamType,
|
StreamType,
|
||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
@ -1393,7 +1392,7 @@ class Linearization {
|
|||||||
Number.isInteger(obj2) &&
|
Number.isInteger(obj2) &&
|
||||||
isCmd(obj3, "obj") &&
|
isCmd(obj3, "obj") &&
|
||||||
linDict instanceof Dict &&
|
linDict instanceof Dict &&
|
||||||
isNum((obj = linDict.get("Linearized"))) &&
|
typeof (obj = linDict.get("Linearized")) === "number" &&
|
||||||
obj > 0
|
obj > 0
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
@ -19,7 +19,6 @@ import {
|
|||||||
ImageKind,
|
ImageKind,
|
||||||
info,
|
info,
|
||||||
IsLittleEndianCached,
|
IsLittleEndianCached,
|
||||||
isNum,
|
|
||||||
OPS,
|
OPS,
|
||||||
shadow,
|
shadow,
|
||||||
TextRenderingMode,
|
TextRenderingMode,
|
||||||
@ -2210,7 +2209,7 @@ class CanvasGraphics {
|
|||||||
i;
|
i;
|
||||||
for (i = 0; i < glyphsLength; ++i) {
|
for (i = 0; i < glyphsLength; ++i) {
|
||||||
const glyph = glyphs[i];
|
const glyph = glyphs[i];
|
||||||
if (isNum(glyph)) {
|
if (typeof glyph === "number") {
|
||||||
x += (spacingDir * glyph * fontSize) / 1000;
|
x += (spacingDir * glyph * fontSize) / 1000;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2336,7 +2335,7 @@ class CanvasGraphics {
|
|||||||
|
|
||||||
for (i = 0; i < glyphsLength; ++i) {
|
for (i = 0; i < glyphsLength; ++i) {
|
||||||
glyph = glyphs[i];
|
glyph = glyphs[i];
|
||||||
if (isNum(glyph)) {
|
if (typeof glyph === "number") {
|
||||||
spacingLength = (spacingDir * glyph * fontSize) / 1000;
|
spacingLength = (spacingDir * glyph * fontSize) / 1000;
|
||||||
this.ctx.translate(spacingLength, 0);
|
this.ctx.translate(spacingLength, 0);
|
||||||
current.x += spacingLength * textHScale;
|
current.x += spacingLength * textHScale;
|
||||||
|
@ -18,7 +18,6 @@ import {
|
|||||||
FONT_IDENTITY_MATRIX,
|
FONT_IDENTITY_MATRIX,
|
||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
ImageKind,
|
ImageKind,
|
||||||
isNum,
|
|
||||||
OPS,
|
OPS,
|
||||||
TextRenderingMode,
|
TextRenderingMode,
|
||||||
unreachable,
|
unreachable,
|
||||||
@ -837,7 +836,7 @@ if (
|
|||||||
// Word break
|
// Word break
|
||||||
x += fontDirection * wordSpacing;
|
x += fontDirection * wordSpacing;
|
||||||
continue;
|
continue;
|
||||||
} else if (isNum(glyph)) {
|
} else if (typeof glyph === "number") {
|
||||||
x += (spacingDir * glyph * fontSize) / 1000;
|
x += (spacingDir * glyph * fontSize) / 1000;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals CFFDictDataMap, CFFDictPrivateDataMap, CFFEncodingMap, CFFStrings,
|
/* globals CFFDictDataMap, CFFDictPrivateDataMap, CFFEncodingMap, CFFStrings,
|
||||||
Components, Dict, dump, FormatError, isNum, netscape, Stream */
|
Components, Dict, dump, FormatError, netscape, Stream */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ var Type2Parser = function type2Parser(aFilePath) {
|
|||||||
var count = decoded.length;
|
var count = decoded.length;
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var token = decoded[i];
|
var token = decoded[i];
|
||||||
if (isNum(token)) {
|
if (typeof token === "number") {
|
||||||
stack.push(token);
|
stack.push(token);
|
||||||
} else {
|
} else {
|
||||||
switch (token.operand) {
|
switch (token.operand) {
|
||||||
|
@ -1034,10 +1034,6 @@ function isBool(v) {
|
|||||||
return typeof v === "boolean";
|
return typeof v === "boolean";
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNum(v) {
|
|
||||||
return typeof v === "number";
|
|
||||||
}
|
|
||||||
|
|
||||||
function isString(v) {
|
function isString(v) {
|
||||||
return typeof v === "string";
|
return typeof v === "string";
|
||||||
}
|
}
|
||||||
@ -1146,7 +1142,6 @@ export {
|
|||||||
isBool,
|
isBool,
|
||||||
IsEvalSupportedCached,
|
IsEvalSupportedCached,
|
||||||
IsLittleEndianCached,
|
IsLittleEndianCached,
|
||||||
isNum,
|
|
||||||
isSameOrigin,
|
isSameOrigin,
|
||||||
isString,
|
isString,
|
||||||
MissingPDFException,
|
MissingPDFException,
|
||||||
|
@ -22,7 +22,6 @@ import {
|
|||||||
isArrayBuffer,
|
isArrayBuffer,
|
||||||
isAscii,
|
isAscii,
|
||||||
isBool,
|
isBool,
|
||||||
isNum,
|
|
||||||
isSameOrigin,
|
isSameOrigin,
|
||||||
isString,
|
isString,
|
||||||
string32,
|
string32,
|
||||||
@ -91,23 +90,6 @@ describe("util", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isNum", function () {
|
|
||||||
it("handles numeric values", function () {
|
|
||||||
expect(isNum(1)).toEqual(true);
|
|
||||||
expect(isNum(0)).toEqual(true);
|
|
||||||
expect(isNum(-1)).toEqual(true);
|
|
||||||
expect(isNum(1000000000000000000)).toEqual(true);
|
|
||||||
expect(isNum(12.34)).toEqual(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("handles non-numeric values", function () {
|
|
||||||
expect(isNum("true")).toEqual(false);
|
|
||||||
expect(isNum(true)).toEqual(false);
|
|
||||||
expect(isNum(null)).toEqual(false);
|
|
||||||
expect(isNum(undefined)).toEqual(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("isString", function () {
|
describe("isString", function () {
|
||||||
it("handles string values", function () {
|
it("handles string values", function () {
|
||||||
expect(isString("foo")).toEqual(true);
|
expect(isString("foo")).toEqual(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user