Browse Source

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.
Jonas Jenwald 8 years ago
parent
commit
8686baede5
  1. 6
      src/core/annotation.js
  2. 5
      src/core/function.js
  3. 2
      src/core/type1_parser.js
  4. 2
      src/display/svg.js

6
src/core/annotation.js

@ -450,7 +450,7 @@ class AnnotationBorderStyle {
* @param {integer} width - The width * @param {integer} width - The width
*/ */
setWidth(width) { setWidth(width) {
if (width === (width | 0)) { if (Number.isInteger(width)) {
this.width = width; this.width = width;
} }
} }
@ -537,7 +537,7 @@ class AnnotationBorderStyle {
* @param {integer} radius - The horizontal corner radius * @param {integer} radius - The horizontal corner radius
*/ */
setHorizontalCornerRadius(radius) { setHorizontalCornerRadius(radius) {
if (radius === (radius | 0)) { if (Number.isInteger(radius)) {
this.horizontalCornerRadius = radius; this.horizontalCornerRadius = radius;
} }
} }
@ -550,7 +550,7 @@ class AnnotationBorderStyle {
* @param {integer} radius - The vertical corner radius * @param {integer} radius - The vertical corner radius
*/ */
setVerticalCornerRadius(radius) { setVerticalCornerRadius(radius) {
if (radius === (radius | 0)) { if (Number.isInteger(radius)) {
this.verticalCornerRadius = radius; this.verticalCornerRadius = radius;
} }
} }

5
src/core/function.js

@ -1032,7 +1032,7 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() {
return null; return null;
} }
n = num1.number; n = num1.number;
if (n < 0 || (n | 0) !== n || stack.length < n) { if (n < 0 || !Number.isInteger(n) || stack.length < n) {
return null; return null;
} }
ast1 = stack[stack.length - n - 1]; ast1 = stack[stack.length - n - 1];
@ -1082,7 +1082,8 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() {
} }
j = num2.number; j = num2.number;
n = num1.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 // ... and integers
return null; return null;
} }

2
src/core/type1_parser.js

@ -324,7 +324,7 @@ var Type1CharString = (function Type1CharStringClosure() {
var start = stackLength - howManyArgs; var start = stackLength - howManyArgs;
for (var i = start; i < stackLength; i++) { for (var i = start; i < stackLength; i++) {
var value = this.stack[i]; var value = this.stack[i];
if (value === (value | 0)) { // int if (Number.isInteger(value)) {
this.output.push(28, (value >> 8) & 0xff, value & 0xff); this.output.push(28, (value >> 8) & 0xff, value & 0xff);
} else { // fixed point } else { // fixed point
value = (65536 * value) | 0; value = (65536 * value) | 0;

2
src/display/svg.js

@ -359,7 +359,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
* @returns {string} * @returns {string}
*/ */
function pf(value) { function pf(value) {
if (value === (value | 0)) { // integer number if (Number.isInteger(value)) {
return value.toString(); return value.toString();
} }
var s = value.toFixed(10); var s = value.toFixed(10);

Loading…
Cancel
Save