Remove the isBool helper function

The call-sites are replaced by direct `typeof`-checks instead, which removes unnecessary function calls.
This commit is contained in:
Jonas Jenwald 2022-02-23 12:25:13 +01:00
parent 82f1ee1755
commit 3704283f5b
4 changed files with 6 additions and 30 deletions

View File

@ -25,7 +25,6 @@ import {
DocumentActionEventType, DocumentActionEventType,
FormatError, FormatError,
info, info,
isBool,
isString, isString,
objectSize, objectSize,
PermissionFlag, PermissionFlag,
@ -221,7 +220,7 @@ class Catalog {
continue; continue;
} }
const value = obj.get(key); const value = obj.get(key);
if (!isBool(value)) { if (typeof value !== "boolean") {
continue; continue;
} }
markInfo[key] = value; markInfo[key] = value;
@ -1521,7 +1520,7 @@ class Catalog {
} }
// The 'NewWindow' property, equal to `LinkTarget.BLANK`. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
const newWindow = action.get("NewWindow"); const newWindow = action.get("NewWindow");
if (isBool(newWindow)) { if (typeof newWindow === "boolean") {
resultObj.newWindow = newWindow; resultObj.newWindow = newWindow;
} }
break; break;

View File

@ -17,7 +17,6 @@ import { Dict, Ref } from "./primitives.js";
import { import {
FormatError, FormatError,
info, info,
isBool,
IsEvalSupportedCached, IsEvalSupportedCached,
shadow, shadow,
unreachable, unreachable,
@ -627,7 +626,7 @@ class PostScriptEvaluator {
case "and": case "and":
b = stack.pop(); b = stack.pop();
a = stack.pop(); a = stack.pop();
if (isBool(a) && isBool(b)) { if (typeof a === "boolean" && typeof b === "boolean") {
stack.push(a && b); stack.push(a && b);
} else { } else {
stack.push(a & b); stack.push(a & b);
@ -751,7 +750,7 @@ class PostScriptEvaluator {
break; break;
case "not": case "not":
a = stack.pop(); a = stack.pop();
if (isBool(a)) { if (typeof a === "boolean") {
stack.push(!a); stack.push(!a);
} else { } else {
stack.push(~a); stack.push(~a);
@ -760,7 +759,7 @@ class PostScriptEvaluator {
case "or": case "or":
b = stack.pop(); b = stack.pop();
a = stack.pop(); a = stack.pop();
if (isBool(a) && isBool(b)) { if (typeof a === "boolean" && typeof b === "boolean") {
stack.push(a || b); stack.push(a || b);
} else { } else {
stack.push(a | b); stack.push(a | b);
@ -802,7 +801,7 @@ class PostScriptEvaluator {
case "xor": case "xor":
b = stack.pop(); b = stack.pop();
a = stack.pop(); a = stack.pop();
if (isBool(a) && isBool(b)) { if (typeof a === "boolean" && typeof b === "boolean") {
stack.push(a !== b); stack.push(a !== b);
} else { } else {
stack.push(a ^ b); stack.push(a ^ b);

View File

@ -1030,10 +1030,6 @@ function utf8StringToString(str) {
return unescape(encodeURIComponent(str)); return unescape(encodeURIComponent(str));
} }
function isBool(v) {
return typeof v === "boolean";
}
function isString(v) { function isString(v) {
return typeof v === "string"; return typeof v === "string";
} }
@ -1139,7 +1135,6 @@ export {
isArrayBuffer, isArrayBuffer,
isArrayEqual, isArrayEqual,
isAscii, isAscii,
isBool,
IsEvalSupportedCached, IsEvalSupportedCached,
IsLittleEndianCached, IsLittleEndianCached,
isSameOrigin, isSameOrigin,

View File

@ -21,7 +21,6 @@ import {
getModificationDate, getModificationDate,
isArrayBuffer, isArrayBuffer,
isAscii, isAscii,
isBool,
isSameOrigin, isSameOrigin,
isString, isString,
string32, string32,
@ -74,22 +73,6 @@ describe("util", function () {
}); });
}); });
describe("isBool", function () {
it("handles boolean values", function () {
expect(isBool(true)).toEqual(true);
expect(isBool(false)).toEqual(true);
});
it("handles non-boolean values", function () {
expect(isBool("true")).toEqual(false);
expect(isBool("false")).toEqual(false);
expect(isBool(1)).toEqual(false);
expect(isBool(0)).toEqual(false);
expect(isBool(null)).toEqual(false);
expect(isBool(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);