Commit Graph

13923 Commits

Author SHA1 Message Date
Jonas Jenwald
96d2a2f795 Enable the ESLint no-var rule in the external/ folder
These changes were done automatically, by using the `gulp lint --fix` command.
2021-03-14 11:43:25 +01:00
Tim van der Meij
24ff738e7b
Enable the no-var linting rule for src/core/pattern.js
This is mostly done using `gulp lint --fix` with a few manual changes in
the following diff:

```diff
diff --git a/src/core/pattern.js b/src/core/pattern.js
index 365491ed3..eedd8b686 100644
--- a/src/core/pattern.js
+++ b/src/core/pattern.js
@@ -105,7 +105,7 @@ const Pattern = (function PatternClosure() {
   return Pattern;
 })();

-var Shadings = {};
+const Shadings = {};

 // A small number to offset the first/last color stops so we can insert ones to
 // support extend. Number.MIN_VALUE is too small and breaks the extend.
@@ -597,16 +597,15 @@ Shadings.Mesh = (function MeshClosure() {
       if (!(0 <= f && f <= 3)) {
         throw new FormatError("Unknown type6 flag");
       }
-      var i, ii;
       const pi = coords.length;
-      for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
         coords.push(reader.readCoordinate());
       }
       const ci = colors.length;
-      for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
         colors.push(reader.readComponents());
       }
-      var tmp1, tmp2, tmp3, tmp4;
+      let tmp1, tmp2, tmp3, tmp4;
       switch (f) {
         // prettier-ignore
         case 0:
@@ -729,16 +728,15 @@ Shadings.Mesh = (function MeshClosure() {
       if (!(0 <= f && f <= 3)) {
         throw new FormatError("Unknown type7 flag");
       }
-      var i, ii;
       const pi = coords.length;
-      for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
         coords.push(reader.readCoordinate());
       }
       const ci = colors.length;
-      for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
         colors.push(reader.readComponents());
       }
-      var tmp1, tmp2, tmp3, tmp4;
+      let tmp1, tmp2, tmp3, tmp4;
       switch (f) {
         // prettier-ignore
         case 0:
@@ -897,7 +895,7 @@ Shadings.Mesh = (function MeshClosure() {
         decodeType4Shading(this, reader);
         break;
       case ShadingType.LATTICE_FORM_MESH:
-        var verticesPerRow = dict.get("VerticesPerRow") | 0;
+        const verticesPerRow = dict.get("VerticesPerRow") | 0;
         if (verticesPerRow < 2) {
           throw new FormatError("Invalid VerticesPerRow");
         }
```
2021-03-14 11:43:05 +01:00
Tim van der Meij
67b866b9ed
Merge pull request #13095 from Snuffleupagus/eslint-cmapscompress
Enable linting of the `external/cmapscompress/` folder
2021-03-14 11:40:50 +01:00
Tim van der Meij
cc59c81fe6
Merge pull request #13096 from Snuffleupagus/eslint-no-var-stats
Enable the ESLint `no-var` rule in the `test/stats/` folder
2021-03-14 11:34:06 +01:00
Tim van der Meij
0ad9265555
Merge pull request #13097 from Snuffleupagus/eslint-no-var-add_test
Enable the ESLint `no-var` rule in `test/add_test.js`
2021-03-14 11:31:55 +01:00
Jonas Jenwald
7ec2bd0f01 Enable the ESLint no-var rule in test/add_test.js
These changes were done automatically, by using the `gulp lint --fix` command.
2021-03-14 10:25:51 +01:00
Jonas Jenwald
473f0aeeb2 Enable the ESLint no-var rule in the test/stats/ folder
Note that the majority of these changes were done automatically, by using the `gulp lint --fix` command, and the manual changes were limited to the following diff:

```diff
diff --git a/test/stats/statcmp.js b/test/stats/statcmp.js
index 7c4dbf1d3..22d535a5a 100644
--- a/test/stats/statcmp.js
+++ b/test/stats/statcmp.js
@@ -1,13 +1,7 @@
 "use strict";

 const fs = require("fs");
-
-try {
-  var ttest = require("ttest");
-} catch (e) {
-  console.log('\nttest is not installed -- to intall, run "npm install ttest"');
-  console.log("Continuing without significance test...\n");
-}
+const ttest = require("ttest");

 const VALID_GROUP_BYS = ["browser", "pdf", "page", "round", "stat"];

@@ -134,9 +128,7 @@ function stat(baseline, current) {
   if (ttest) {
     labels.push("Result(P<.05)");
   }
-  let i,
-    row,
-    rows = [];
+  const rows = [];
   // collect rows and measure column widths
   const width = labels.map(function (s) {
     return s.length;
@@ -146,7 +138,7 @@ function stat(baseline, current) {
     const key = keys[k];
     const baselineMean = mean(baselineGroup[key]);
     const currentMean = mean(currentGroup[key]);
-    row = key.split(",");
+    const row = key.split(",");
     row.push(
       "" + baselineGroup[key].length,
       "" + Math.round(baselineMean),
@@ -165,7 +157,7 @@ function stat(baseline, current) {
         row.push("");
       }
     }
-    for (i = 0; i < row.length; i++) {
+    for (let i = 0; i < row.length; i++) {
       width[i] = Math.max(width[i], row[i].length);
     }
     rows.push(row);
@@ -181,8 +173,8 @@ function stat(baseline, current) {
   console.log("-- Grouped By " + options.groupBy.join(", ") + " --");
   const groupCount = options.groupBy.length;
   for (let r = 0; r < rows.length; r++) {
-    row = rows[r];
-    for (i = 0; i < row.length; i++) {
+    const row = rows[r];
+    for (let i = 0; i < row.length; i++) {
       row[i] = pad(row[i], width[i], i < groupCount ? "right" : "left");
     }
     console.log(row.join(" | "));
@@ -208,5 +200,5 @@ function main() {
   stat(baseline, current);
 }

-var options = parseOptions();
+const options = parseOptions();
 main();
```
2021-03-14 10:15:45 +01:00
Jonas Jenwald
98e658ddf0 Enable linting of the external/cmapscompress/ folder
Given that this our "own" code, there's no good reason as far as I'm concerned to not lint it.
2021-03-13 19:32:58 +01:00
Jonas Jenwald
b9f4d89254 Fix *most* linting/formatting issues in the external/cmapscompress/ folder
These changes were done automatically, by using the `gulp lint --fix` command, in preparation for the next patch.
2021-03-13 19:24:23 +01:00
Tim van der Meij
c86f44f423
Merge pull request #13093 from Snuffleupagus/eslint-no-var-builder
Enable the ESLint `no-var` rule in the `external/builder/` folder
2021-03-13 18:52:18 +01:00
Jonas Jenwald
f0f307a4b5 Enable the ESLint no-var rule in the external/builder/ folder
As part of testing this, I've diffed the output of `gulp mozcentral` with/without this patch and the *only* difference is the incremented `version`/`build` numbers.
2021-03-13 17:50:13 +01:00
Jonas Jenwald
06494ccdac Replace *most* cases of var with let/const in the external/builder/ folder
These changes were done automatically, by using the `gulp lint --fix` command, in preparation for the next patch.
2021-03-13 17:47:58 +01:00
Tim van der Meij
fb78604383
Merge pull request #13091 from Snuffleupagus/eslint-no-var
Enable the ESLint `no-var` rule globally
2021-03-13 17:39:53 +01:00
Tim van der Meij
6b97958511
Merge pull request #13092 from Snuffleupagus/eslint-no-var-importL10n
Enable the ESLint `no-var` rule in the `importL10n/` folder
2021-03-13 17:34:05 +01:00
Jonas Jenwald
2ffa428d78 Enable the ESLint no-var rule in the importL10n/ folder 2021-03-13 17:23:41 +01:00
Jonas Jenwald
5b5061afa8 Enable the ESLint no-var rule globally
A significant portion of the code-base has now been converted to use `let`/`const`, rather than `var`, hence it should be possible to simply enable the ESLint `no-var` rule globally.
This way we can ensure that new code won't accidentally use `var`, and it also removes the need to manually enable the rule in various folders.

Obviously it makes sense to continue the efforts to replace `var`, but that should probably happen on a file and/or folder basis.

Please note that this patch excludes the following code:
 - The `extensions/` folder, since that seemed easiest for now (and I don't know exactly what the support situation is for the Chromium-extension).

 - The entire `external/` folder is ignored, since most of it's currently excluded from linting.
   For the code that isn't imported from elsewhere (and should be ignored), we should probably (at some point) bring the code up to the same linting/formatting standard as the rest of the code-base.

 - Various files in the `test/` folder are ignored, as necessary, since the way that a lot of this code is loaded will require some care (or perhaps larger re-factoring) when removing `var` usage.
2021-03-13 16:12:53 +01:00
Jonas Jenwald
412f01aeaf Dispatch a "Doc/WillClose" event, when scripting is enabled, when closing the document
This event is mentioned in the specification, see https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_api_reference.pdf#G5.1963176, and it's also listed as a valid type in fb87704b38/src/shared/util.js (L164-L170)

Since we're already dispatching a "PageClose" event in this case, it seems reasonable to *also* dispatch a "Doc/WillClose" event as well.
2021-03-13 13:21:05 +01:00
Tim van der Meij
17c0bf0473
Merge pull request #13084 from Snuffleupagus/type1-class
Enable the ESLint `no-var` rule in a few font-parsing files, and convert `src/core/type1_parser.js` to use "standard" classes
2021-03-13 13:15:53 +01:00
Tim van der Meij
1abdcbaab5
Merge pull request #13087 from Snuffleupagus/eslint-examples-no-var
Enable the ESLint `no-var` rule in the `examples/` folder
2021-03-13 13:04:00 +01:00
Tim van der Meij
ba567321da
Merge pull request #13079 from Snuffleupagus/issue-13075
Ensure that `getDocument` handles Node.js `Buffer`s more gracefully (issue 13075)
2021-03-13 12:58:29 +01:00
Tim van der Meij
6ae81255bc
Merge pull request #13090 from Snuffleupagus/eslint-no-var-gulpfile
Enable the ESLint `no-var` rule in `gulpfile.js`
2021-03-13 12:55:34 +01:00
Jonas Jenwald
22e0ed51c6 Remove unnecessary /* eslint no-var: error */ lines in the test/unit/ folder (PR 12528 follow-up)
These lines are no longer needed, since the ESLint `no-var` rule has been enabled in the entire folder.
2021-03-13 11:50:11 +01:00
Jonas Jenwald
f58fee0956 Enable the ESLint no-var rule in gulpfile.js
Given that `let`/`const` is already used here and there in this file, converting the rest of the `var` occurrences shouldn't be a problem.

Note that the majority of these changes were done automatically, by using the `gulp lint --fix` command, and the manual changes were limited to the following diff:

```diff
diff --git a/gulpfile.js b/gulpfile.js
index e2360c8ec..905420c33 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -676,8 +676,8 @@ gulp.task("default_preferences-pre", function () {
       ],
     }).code;
   }
-  var babel = require("@babel/core");
-  var ctx = {
+  const babel = require("@babel/core");
+  const ctx = {
     rootPath: __dirname,
     saveComments: false,
     defines: builder.merge(DEFINES, {
@@ -690,7 +690,7 @@ gulp.task("default_preferences-pre", function () {
       "pdfjs-lib": "../pdf",
     },
   };
-  var preprocessor2 = require("./external/builder/preprocessor2.js");
+  const preprocessor2 = require("./external/builder/preprocessor2.js");
   return merge([
     gulp.src(["web/{app_options,viewer_compatibility}.js"], {
       base: ".",
@@ -1418,14 +1418,14 @@ function buildLib(defines, dir) {
     });
     return licenseHeaderLibre + content;
   }
-  var babel = require("@babel/core");
+  const babel = require("@babel/core");
   const versionInfo = getVersionJSON();
-  var bundleDefines = builder.merge(defines, {
+  const bundleDefines = builder.merge(defines, {
     BUNDLE_VERSION: versionInfo.version,
     BUNDLE_BUILD: versionInfo.commit,
     TESTING: process.env.TESTING === "true",
   });
-  var ctx = {
+  const ctx = {
     rootPath: __dirname,
     saveComments: false,
     defines: bundleDefines,
@@ -1433,10 +1433,10 @@ function buildLib(defines, dir) {
       "pdfjs-lib": "../pdf",
     },
   };
-  var licenseHeaderLibre = fs
+  const licenseHeaderLibre = fs
     .readFileSync("./src/license_header_libre.js")
     .toString();
-  var preprocessor2 = require("./external/builder/preprocessor2.js");
+  const preprocessor2 = require("./external/builder/preprocessor2.js");
   return merge([
     gulp.src(
       [
```
2021-03-13 11:47:06 +01:00
Jonas Jenwald
50681d71c8 Ensure that getDocument handles Node.js Buffers more gracefully (issue 13075)
While the JSDocs have never advertised `getDocument` as supporting Node.js `Buffer`s, that apparently doesn't stop users from passing such data structures to `getDocument`.
In theory the existing `instanceof Uint8Array` check ought to have caught Node.js `Buffer`s, however for reasons that I don't even pretend to understand that check actually passes. Hence this patch which, *only* in Node.js environments, will special-case `Buffer`s to hopefully provide a slightly better out-of-the-box behaviour in Node.js environments[1].

---
[1] Although I'm not sure that we necessarily want to advertise this in the JSDocs, given the specialized use-case.
2021-03-13 10:52:38 +01:00
Tim van der Meij
61318c42aa
Merge pull request #13085 from Snuffleupagus/driver-rasterize-errors
Ensure that *all* errors are handled in `rasterizeTextLayer`/`rasterizeAnnotationLayer`
2021-03-12 21:16:16 +01:00
Tim van der Meij
be4a41960a
Merge pull request #13081 from Snuffleupagus/objectFromMap
Replace the `objectFromEntries` helper function with an `objectFromMap` one instead, and simplify the data lookup in the AnnotationStorage.getValue method
2021-03-12 21:12:03 +01:00
Tim van der Meij
6af9b6449e
Merge pull request #13074 from Snuffleupagus/scripting-refactor-destroy
Re-factor the `PDFScriptingManager._destroyScripting` method (PR 13042 follow-up)
2021-03-12 21:08:05 +01:00
Jonas Jenwald
d144d01afe Simplify the animationStarted handling in the mobile-viewer/ example
(This is something that I happened to notice while working on the previous patch.)

The code in the `examples/mobile-viewer/viewer.js` file is essentially copied from an older version of the default viewer, hence we can slightly simplify the `animationStarted` handling here.
2021-03-12 17:52:58 +01:00
Jonas Jenwald
5c712f2131 Enable the ESLint no-var rule in the examples/ folder
Updating the examples to use `let`/`const` should be fine, given that they are available in all browsers/platforms that the PDF.js library now supports; please note the following compatibility information:

 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const#browser_compatibility
2021-03-12 17:52:52 +01:00
Jonas Jenwald
276fa4ad8f Replace *most* cases of var with let/const in the examples/ folder
These changes were done automatically, by using the `gulp lint --fix` command, in preparation for the next patch.
2021-03-12 17:16:59 +01:00
Jonas Jenwald
39cd844243 Ensure that *all* errors are handled in rasterizeTextLayer/rasterizeAnnotationLayer
Currently errors occurring within the `src/display/{text_layer, annotation_layer}.js` files are not being handled properly by the test-suite, and the tests simply time out rather than failing as intended.
This makes it *very* easy to accidentally overlook a certain type of errors, see e.g. https://github.com/mozilla/pdf.js/pull/13055#discussion_r589005041, which this patch will thus prevent.
2021-03-12 14:05:53 +01:00
Jonas Jenwald
ab91f42a5e Convert code in src/core/type1_parser.js to use "standard" classes
All of this code predates the existence of native JS classes, however we can now clean this up a little bit.
2021-03-12 12:16:50 +01:00
Jonas Jenwald
8fc8dc020e Enable the ESLint no-var rule in the src/core/type1_parser.js file
Note that the majority of these changes were done automatically, by using `gulp lint --fix`, and the manual changes were limited to the following diff:

```diff
diff --git a/src/core/type1_parser.js b/src/core/type1_parser.js
index 192781de1..05c5fe2e5 100644
--- a/src/core/type1_parser.js
+++ b/src/core/type1_parser.js
@@ -251,7 +251,7 @@ const Type1CharString = (function Type1CharStringClosure() {
               // vhea tables reconstruction -- ignoring it.
               this.stack.pop(); // wy
               wx = this.stack.pop();
-              var sby = this.stack.pop();
+              const sby = this.stack.pop();
               sbx = this.stack.pop();
               this.lsb = sbx;
               this.width = wx;
@@ -263,8 +263,8 @@ const Type1CharString = (function Type1CharStringClosure() {
                 error = true;
                 break;
               }
-              var num2 = this.stack.pop();
-              var num1 = this.stack.pop();
+              const num2 = this.stack.pop();
+              const num1 = this.stack.pop();
               this.stack.push(num1 / num2);
               break;
             case (12 << 8) + 16: // callothersubr
@@ -273,7 +273,7 @@ const Type1CharString = (function Type1CharStringClosure() {
                 break;
               }
               subrNumber = this.stack.pop();
-              var numArgs = this.stack.pop();
+              const numArgs = this.stack.pop();
               if (subrNumber === 0 && numArgs === 3) {
                 const flexArgs = this.stack.splice(this.stack.length - 17, 17);
                 this.stack.push(
@@ -397,9 +397,9 @@ const Type1Parser = (function Type1ParserClosure() {
     if (discardNumber >= data.length) {
       return new Uint8Array(0);
     }
+    const c1 = 52845,
+      c2 = 22719;
     let r = key | 0,
-      c1 = 52845,
-      c2 = 22719,
       i,
       j;
     for (i = 0; i < discardNumber; i++) {
@@ -416,9 +416,9 @@ const Type1Parser = (function Type1ParserClosure() {
   }

   function decryptAscii(data, key, discardNumber) {
-    let r = key | 0,
-      c1 = 52845,
+    const c1 = 52845,
       c2 = 22719;
+    let r = key | 0;
     const count = data.length,
       maybeLength = count >>> 1;
     const decrypted = new Uint8Array(maybeLength);
@@ -429,7 +429,7 @@ const Type1Parser = (function Type1ParserClosure() {
         continue;
       }
       i++;
-      var digit2;
+      let digit2;
       while (i < count && !isHexDigit((digit2 = data[i]))) {
         i++;
       }
@@ -599,7 +599,7 @@ const Type1Parser = (function Type1ParserClosure() {
               if (token !== "/") {
                 continue;
               }
-              var glyph = this.getToken();
+              const glyph = this.getToken();
               length = this.readInt();
               this.getToken(); // read in 'RD' or '-|'
               data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
@@ -638,7 +638,7 @@ const Type1Parser = (function Type1ParserClosure() {
           case "OtherBlues":
           case "FamilyBlues":
           case "FamilyOtherBlues":
-            var blueArray = this.readNumberArray();
+            const blueArray = this.readNumberArray();
             // *Blue* values may contain invalid data: disables reading of
             // those values when hinting is disabled.
             if (
@@ -672,7 +672,7 @@ const Type1Parser = (function Type1ParserClosure() {
       }

       for (let i = 0; i < charstrings.length; i++) {
-        glyph = charstrings[i].glyph;
+        const glyph = charstrings[i].glyph;
         encoded = charstrings[i].encoded;
         const charString = new Type1CharString();
         const error = charString.convert(
@@ -728,12 +728,12 @@ const Type1Parser = (function Type1ParserClosure() {
         token = this.getToken();
         switch (token) {
           case "FontMatrix":
-            var matrix = this.readNumberArray();
+            const matrix = this.readNumberArray();
             properties.fontMatrix = matrix;
             break;
           case "Encoding":
-            var encodingArg = this.getToken();
-            var encoding;
+            const encodingArg = this.getToken();
+            let encoding;
             if (!/^\d+$/.test(encodingArg)) {
               // encoding name is specified
               encoding = getEncoding(encodingArg);
@@ -764,7 +764,7 @@ const Type1Parser = (function Type1ParserClosure() {
             properties.builtInEncoding = encoding;
             break;
           case "FontBBox":
-            var fontBBox = this.readNumberArray();
+            const fontBBox = this.readNumberArray();
             // adjusting ascent/descent
             properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
             properties.descent = Math.min(fontBBox[1], fontBBox[3]);
```
2021-03-12 12:05:48 +01:00
Jonas Jenwald
82062f7e0d Enable the ESLint no-var rule in the src/core/cff_parser.js file
Note that the majority of these changes were done automatically, by using `gulp lint --fix`, and the manual changes were limited to the following diff:

```diff
diff --git a/src/core/cff_parser.js b/src/core/cff_parser.js
index d684c200e..2e2b811e4 100644
--- a/src/core/cff_parser.js
+++ b/src/core/cff_parser.js
@@ -555,7 +555,7 @@ const CFFParser = (function CFFParserClosure() {
           stackSize %= 2;
           validationCommand = CharstringValidationData[value];
         } else if (value === 10 || value === 29) {
-          var subrsIndex;
+          let subrsIndex;
           if (value === 10) {
             subrsIndex = localSubrIndex;
           } else {
@@ -886,15 +886,15 @@ const CFFParser = (function CFFParserClosure() {
         format = bytes[pos++];
         switch (format & 0x7f) {
           case 0:
-            var glyphsCount = bytes[pos++];
+            const glyphsCount = bytes[pos++];
             for (i = 1; i <= glyphsCount; i++) {
               encoding[bytes[pos++]] = i;
             }
             break;

           case 1:
-            var rangesCount = bytes[pos++];
-            var gid = 1;
+            const rangesCount = bytes[pos++];
+            let gid = 1;
             for (i = 0; i < rangesCount; i++) {
               const start = bytes[pos++];
               const left = bytes[pos++];
@@ -938,7 +938,7 @@ const CFFParser = (function CFFParserClosure() {
           }
           break;
         case 3:
-          var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
+          const rangesCount = (bytes[pos++] << 8) | bytes[pos++];
           for (i = 0; i < rangesCount; ++i) {
             let first = (bytes[pos++] << 8) | bytes[pos++];
             if (i === 0 && first !== 0) {
@@ -1173,7 +1173,7 @@ class CFFDict {
   }
 }

-var CFFTopDict = (function CFFTopDictClosure() {
+const CFFTopDict = (function CFFTopDictClosure() {
   const layout = [
     [[12, 30], "ROS", ["sid", "sid", "num"], null],
     [[12, 20], "SyntheticBase", "num", null],
@@ -1229,7 +1229,7 @@ var CFFTopDict = (function CFFTopDictClosure() {
   return CFFTopDict;
 })();

-var CFFPrivateDict = (function CFFPrivateDictClosure() {
+const CFFPrivateDict = (function CFFPrivateDictClosure() {
   const layout = [
     [6, "BlueValues", "delta", null],
     [7, "OtherBlues", "delta", null],
@@ -1265,11 +1265,12 @@ var CFFPrivateDict = (function CFFPrivateDictClosure() {
   return CFFPrivateDict;
 })();

-var CFFCharsetPredefinedTypes = {
+const CFFCharsetPredefinedTypes = {
   ISO_ADOBE: 0,
   EXPERT: 1,
   EXPERT_SUBSET: 2,
 };
+
 class CFFCharset {
   constructor(predefined, format, charset, raw) {
     this.predefined = predefined;
@@ -1695,7 +1696,7 @@ class CFFCompiler {
             // For offsets we just insert a 32bit integer so we don't have to
             // deal with figuring out the length of the offset when it gets
             // replaced later on by the compiler.
-            var name = dict.keyToNameMap[key];
+            const name = dict.keyToNameMap[key];
             // Some offsets have the offset and the length, so just record the
             // position of the first one.
             if (!offsetTracker.isTracking(name)) {
```
2021-03-12 12:00:38 +01:00
Jonas Jenwald
f3948aeb90 Enable the ESLint no-var rule in the src/core/font_renderer.js file
Note that the majority of these changes were done automatically, by using `gulp lint --fix`, and the manual changes were limited to the following diff:

```diff
diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js
index e1538c481..00f5424cd 100644
--- a/src/core/font_renderer.js
+++ b/src/core/font_renderer.js
@@ -152,9 +152,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
   }

   function lookupCmap(ranges, unicode) {
-    let code = unicode.codePointAt(0),
-      gid = 0;
-    let l = 0,
+    const code = unicode.codePointAt(0);
+    let gid = 0,
+      l = 0,
       r = ranges.length - 1;
     while (l < r) {
       const c = (l + r + 1) >> 1;
@@ -199,7 +199,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
         flags = (code[i] << 8) | code[i + 1];
         const glyphIndex = (code[i + 2] << 8) | code[i + 3];
         i += 4;
-        var arg1, arg2;
+        let arg1, arg2;
         if (flags & 0x01) {
           arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
           arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
@@ -366,7 +366,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
       while (i < code.length) {
         let stackClean = false;
         let v = code[i++];
-        var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
+        let xa, xb, ya, yb, y1, y2, y3, n, subrCode;
         switch (v) {
           case 1: // hstem
             stems += stack.length >> 1;
@@ -494,7 +494,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
                 bezierCurveTo(xa, y2, xb, y3, x, y);
                 break;
               case 37: // flex1
-                var x0 = x,
+                const x0 = x,
                   y0 = y;
                 xa = x + stack.shift();
                 ya = y + stack.shift();
```
2021-03-12 11:57:27 +01:00
Brendan Dahl
56fd01bf8d
Merge pull request #13078 from brendandahl/disable-missing
Disable intermittent unit test "creates pdf doc from non-existent URL"
2021-03-11 21:17:54 -08:00
Brendan Dahl
47a5550f10 Disable intermittent unit test "creates pdf doc from non-existent URL"
Disable this test so we don't have to manually review unit test
failure log all the time.
2021-03-11 11:40:40 -08:00
Brendan Dahl
1b42fe2917
Merge pull request #13015 from calixteman/avoid_dl
JS - Avoid a popup to ask for updating Acrobat.
2021-03-11 08:43:49 -08:00
Jonas Jenwald
b326432895 Simplify the data lookup in the AnnotationStorage.getValue method
Rather than first checking if data exists before fetching it from storage, we can simply do the lookup directly and then check its value.
Note that this follows the same pattern as utilized in the `AnnotationStorage.setValue` method.
2021-03-11 16:37:38 +01:00
Jonas Jenwald
a0e584eeb2 Replace the objectFromEntries helper function with an objectFromMap one instead
Given that it's only used with `Map`s, and that it's currently implemented in such a way that we (indirectly) must iterate through the data *twice*, some simplification cannot hurt here.
Note that the only reason that we're not using `Object.fromEntries(...)` directly, at each call-site, is that that one won't guarantee that a `null` prototype is being used.
2021-03-11 16:37:34 +01:00
Brendan Dahl
3d4bb5e5c5
Merge pull request #13018 from calixteman/xfa_bind
XFA - Create Form DOM in merging template and data trees
2021-03-10 10:27:06 -08:00
Jonas Jenwald
52a598915f Re-factor the PDFScriptingManager._destroyScripting method (PR 13042 follow-up)
*Please note:* Given the pre-existing issues raised in PR 13056, which seem to block immediate progress there, this patch extracts some *overall* improvements of the scripting/sandbox destruction in `PDFScriptingManager`.

As can be seen in `BaseViewer.setDocument`, it's currently necessary to *manually* delay the `PDFScriptingManager`-destruction in order for things to work correctly. This is, in hindsight, obviously an *extremely poor* design choice on my part; sorry about the churn here!

In order to improve things overall, the `PDFScriptingManager._destroyScripting`-method is re-factored to wait for the relevant events to be dispatched *before* sandbox-destruction occurs.
To avoid the scripting/sandbox-destruction hanging indefinitely, we utilize a timeout to force-destroy the sandbox after a short time (currently set to 1 second).
2021-03-10 13:08:19 +01:00
Calixte Denizet
3243672727 XFA - Create Form DOM in merging template and data trees
- Spec: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=171;
  - support for the 2 ways of merging: consumeData and matchTemplate;
  - create additional nodes in template DOM when occur node allows it;
  - support for global values in data DOM.
2021-03-08 14:10:30 +01:00
Tim van der Meij
5e3af62d58
Merge pull request #13063 from Snuffleupagus/more-web-optional-chaining
Use more optional chaining in the web/-folder (PR 12961 follow-up)
2021-03-07 19:00:57 +01:00
Jonas Jenwald
bc13932ac1 Use more optional chaining in the web/-folder (PR 12961 follow-up)
I overlooked these cases previously, but there's no reason why optional chaining (and nullish coalescing) cannot be used here as well.
2021-03-07 16:20:52 +01:00
Jonas Jenwald
bdde621366 Avoid unnecessary size_kb calculation, for large files, in PDFDocumentProperties._parseFileSize (PR 13050 follow-up) 2021-03-07 16:10:11 +01:00
Tim van der Meij
34c9e889ac
Merge pull request #13062 from Snuffleupagus/rm-features
Remove the `test/features` folder, since it's very out of date (issue 11954)
2021-03-07 13:51:49 +01:00
Jonas Jenwald
36bb4fa823 Remove the test/features folder, since it's very out of date (issue 11954)
These tests, and their [accompanying Wiki page](https://github.com/mozilla/pdf.js/wiki/Required-Browser-Features), haven't received any real updates for *many years* and are sufficiently out of date to be effectively useless now.
Providing *irrelevant* compatibility information seems overall worse than not providing any information, and as suggested in the issue it'd probably be better to use https://github.com/mozilla/pdf.js#online-demo for checking if a particular platform/browser is supported.

Thanks to version control, it's easy to restore these files should the need ever arise. However, re-introducing these tests would essentially require updating every single test-case *and* a commitment to keeping them up to date with future code changes.
2021-03-07 13:41:30 +01:00
Tim van der Meij
ba1b4097dc
Merge pull request #13055 from calixteman/reset_radio
JS - reset correctly radio buttons
2021-03-07 13:23:18 +01:00
Tim van der Meij
11d86df4a7
Merge pull request #13060 from Snuffleupagus/update-packages
Update packages and translations
2021-03-07 12:54:13 +01:00