From 8686baede54c992133a53f15e933cca878f5ae99 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 3 Sep 2017 12:50:16 +0200 Subject: [PATCH] Replace `value === (value | 0)` checks with `Number.isInteger(value)` in the `src/` folder Rather than doing what (at first) may seem like a fairly obscure comparison, using `Number.isInteger` will clearly indicate the intent of the code. --- src/core/annotation.js | 6 +++--- src/core/function.js | 5 +++-- src/core/type1_parser.js | 2 +- src/display/svg.js | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 7bda3ec03..840c5a9a4 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -450,7 +450,7 @@ class AnnotationBorderStyle { * @param {integer} width - The width */ setWidth(width) { - if (width === (width | 0)) { + if (Number.isInteger(width)) { this.width = width; } } @@ -537,7 +537,7 @@ class AnnotationBorderStyle { * @param {integer} radius - The horizontal corner radius */ setHorizontalCornerRadius(radius) { - if (radius === (radius | 0)) { + if (Number.isInteger(radius)) { this.horizontalCornerRadius = radius; } } @@ -550,7 +550,7 @@ class AnnotationBorderStyle { * @param {integer} radius - The vertical corner radius */ setVerticalCornerRadius(radius) { - if (radius === (radius | 0)) { + if (Number.isInteger(radius)) { this.verticalCornerRadius = radius; } } diff --git a/src/core/function.js b/src/core/function.js index 53208f0b8..86f5b424e 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -1032,7 +1032,7 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() { return null; } n = num1.number; - if (n < 0 || (n | 0) !== n || stack.length < n) { + if (n < 0 || !Number.isInteger(n) || stack.length < n) { return null; } ast1 = stack[stack.length - n - 1]; @@ -1082,7 +1082,8 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() { } j = num2.number; n = num1.number; - if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) { + if (n <= 0 || !Number.isInteger(n) || !Number.isInteger(j) || + stack.length < n) { // ... and integers return null; } diff --git a/src/core/type1_parser.js b/src/core/type1_parser.js index 509cd5343..d8b0da896 100644 --- a/src/core/type1_parser.js +++ b/src/core/type1_parser.js @@ -324,7 +324,7 @@ var Type1CharString = (function Type1CharStringClosure() { var start = stackLength - howManyArgs; for (var i = start; i < stackLength; i++) { var value = this.stack[i]; - if (value === (value | 0)) { // int + if (Number.isInteger(value)) { this.output.push(28, (value >> 8) & 0xff, value & 0xff); } else { // fixed point value = (65536 * value) | 0; diff --git a/src/display/svg.js b/src/display/svg.js index 1ce15e383..29ffbcaeb 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -359,7 +359,7 @@ SVGGraphics = (function SVGGraphicsClosure() { * @returns {string} */ function pf(value) { - if (value === (value | 0)) { // integer number + if (Number.isInteger(value)) { return value.toString(); } var s = value.toFixed(10);