1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Remove the isNum helper function

The call-sites are replaced by direct `typeof`-checks instead, which removes unnecessary function calls. Note that in the `src/`-folder we already had more `typeof`-cases than `isNum`-calls.

These changes were *mostly* done using regular expression search-and-replace, with two exceptions:
 - In `Font._charToGlyph` we no longer unconditionally update the `width`, since that seems completely unnecessary.
 - In `PDFDocument.documentInfo`, when parsing custom entries, we now do the `typeof`-check once.
This commit is contained in:
Jonas Jenwald 2022-02-22 11:55:34 +01:00
parent edd024c9e7
commit 05edd91bdb
10 changed files with 30 additions and 51 deletions

View file

@ -20,8 +20,6 @@ import {
InvalidPDFException,
isArrayBuffer,
isArrayEqual,
isBool,
isNum,
isString,
OPS,
PageActionEventType,
@ -177,7 +175,7 @@ class Page {
get userUnit() {
let obj = this.pageDict.get("UserUnit");
if (!isNum(obj) || obj <= 0) {
if (typeof obj !== "number" || obj <= 0) {
obj = DEFAULT_USER_UNIT;
}
return shadow(this, "userUnit", obj);
@ -1193,10 +1191,15 @@ class PDFDocument {
// For custom values, only accept white-listed types to prevent
// errors that would occur when trying to send non-serializable
// objects to the main-thread (for example `Dict` or `Stream`).
const customType = typeof value;
let customValue;
if (isString(value)) {
if (customType === "string") {
customValue = stringToPDFString(value);
} else if (value instanceof Name || isNum(value) || isBool(value)) {
} else if (
value instanceof Name ||
customType === "number" ||
customType === "boolean"
) {
customValue = value;
} else {
info(`Unsupported value in document info for (custom) "${key}".`);