Skip to content

Commit fcfda60

Browse files
committed
Remove the isBool 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 `isBool`-calls.
1 parent 82f1ee1 commit fcfda60

File tree

4 files changed

+6
-30
lines changed

4 files changed

+6
-30
lines changed

src/core/catalog.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
DocumentActionEventType,
2626
FormatError,
2727
info,
28-
isBool,
2928
isString,
3029
objectSize,
3130
PermissionFlag,
@@ -221,7 +220,7 @@ class Catalog {
221220
continue;
222221
}
223222
const value = obj.get(key);
224-
if (!isBool(value)) {
223+
if (typeof value !== "boolean") {
225224
continue;
226225
}
227226
markInfo[key] = value;
@@ -1521,7 +1520,7 @@ class Catalog {
15211520
}
15221521
// The 'NewWindow' property, equal to `LinkTarget.BLANK`.
15231522
const newWindow = action.get("NewWindow");
1524-
if (isBool(newWindow)) {
1523+
if (typeof newWindow === "boolean") {
15251524
resultObj.newWindow = newWindow;
15261525
}
15271526
break;

src/core/function.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { Dict, Ref } from "./primitives.js";
1717
import {
1818
FormatError,
1919
info,
20-
isBool,
2120
IsEvalSupportedCached,
2221
shadow,
2322
unreachable,
@@ -627,7 +626,7 @@ class PostScriptEvaluator {
627626
case "and":
628627
b = stack.pop();
629628
a = stack.pop();
630-
if (isBool(a) && isBool(b)) {
629+
if (typeof a === "boolean" && typeof b === "boolean") {
631630
stack.push(a && b);
632631
} else {
633632
stack.push(a & b);
@@ -751,7 +750,7 @@ class PostScriptEvaluator {
751750
break;
752751
case "not":
753752
a = stack.pop();
754-
if (isBool(a)) {
753+
if (typeof a === "boolean") {
755754
stack.push(!a);
756755
} else {
757756
stack.push(~a);
@@ -760,7 +759,7 @@ class PostScriptEvaluator {
760759
case "or":
761760
b = stack.pop();
762761
a = stack.pop();
763-
if (isBool(a) && isBool(b)) {
762+
if (typeof a === "boolean" && typeof b === "boolean") {
764763
stack.push(a || b);
765764
} else {
766765
stack.push(a | b);
@@ -802,7 +801,7 @@ class PostScriptEvaluator {
802801
case "xor":
803802
b = stack.pop();
804803
a = stack.pop();
805-
if (isBool(a) && isBool(b)) {
804+
if (typeof a === "boolean" && typeof b === "boolean") {
806805
stack.push(a !== b);
807806
} else {
808807
stack.push(a ^ b);

src/shared/util.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,10 +1030,6 @@ function utf8StringToString(str) {
10301030
return unescape(encodeURIComponent(str));
10311031
}
10321032

1033-
function isBool(v) {
1034-
return typeof v === "boolean";
1035-
}
1036-
10371033
function isString(v) {
10381034
return typeof v === "string";
10391035
}
@@ -1139,7 +1135,6 @@ export {
11391135
isArrayBuffer,
11401136
isArrayEqual,
11411137
isAscii,
1142-
isBool,
11431138
IsEvalSupportedCached,
11441139
IsLittleEndianCached,
11451140
isSameOrigin,

test/unit/util_spec.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
getModificationDate,
2222
isArrayBuffer,
2323
isAscii,
24-
isBool,
2524
isSameOrigin,
2625
isString,
2726
string32,
@@ -74,22 +73,6 @@ describe("util", function () {
7473
});
7574
});
7675

77-
describe("isBool", function () {
78-
it("handles boolean values", function () {
79-
expect(isBool(true)).toEqual(true);
80-
expect(isBool(false)).toEqual(true);
81-
});
82-
83-
it("handles non-boolean values", function () {
84-
expect(isBool("true")).toEqual(false);
85-
expect(isBool("false")).toEqual(false);
86-
expect(isBool(1)).toEqual(false);
87-
expect(isBool(0)).toEqual(false);
88-
expect(isBool(null)).toEqual(false);
89-
expect(isBool(undefined)).toEqual(false);
90-
});
91-
});
92-
9376
describe("isString", function () {
9477
it("handles string values", function () {
9578
expect(isString("foo")).toEqual(true);

0 commit comments

Comments
 (0)