From 517d92a1213c46224f1cc66ad49b6a7b5bf8ef5f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 15 Jun 2020 13:18:43 +0200 Subject: [PATCH] Simplify the "is integer" checks in `CFFCompiler.encodeNumber` The `isNaN` check is obviously redundant, since `NaN` is the only value that isn't equal to itself; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN#Examples The `parseFloat`/`parseInt` comparison would make sense if the `value` ever contains a String, which however is never actually the case. Besides looking through the code, I've also run the entire test-suite locally with `assert(typeof value === "number", "encodeNumber");` added at the top of the method and there were no failures. Hence we can simplify the "is integer" check a bit in the `CFFCompiler.encodeNumber` method. --- src/core/cff_parser.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/cff_parser.js b/src/core/cff_parser.js index cf1f1c4bb..f8c48b612 100644 --- a/src/core/cff_parser.js +++ b/src/core/cff_parser.js @@ -1483,8 +1483,7 @@ var CFFCompiler = (function CFFCompilerClosure() { return output.data; }, encodeNumber: function CFFCompiler_encodeNumber(value) { - if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { - // isInt + if (Number.isInteger(value)) { return this.encodeInteger(value); } return this.encodeFloat(value);