Commit Graph

13200 Commits

Author SHA1 Message Date
Tim van der Meij
47b3b39a88
Merge pull request #12561 from Snuffleupagus/static-analyzer-warnings
Fix some static static analyzer warnings (issue 11965)
2020-11-01 14:46:20 +01:00
Tim van der Meij
c89f21b9b2
Merge pull request #12560 from Snuffleupagus/update-packages
Update `npm` packages
2020-11-01 14:10:49 +01:00
Jonas Jenwald
a177afc206 Fix some static static analyzer warnings (issue 11965)
This fixes only those warnings, as reported by https://lgtm.com/projects/g/mozilla/pdf.js?mode=list, that make sense (as far as I'm concerned).

Hence this patch leaves the following things unaddressed:
 - The "recommendation"-category, since it only complains about unused variables. However, note that all of those cases are purposely included and that there's thus ESLint-disable comments added to explictly allow them.
 - The "warning"-category, which still contains two complaints. However, as far as I can tell, they are both false positives.

Given first of all the false positives of the LGTM static analyzer, and secondly that we'd need to add (essentially duplicated) disable-comments for the unused variable cases, it's not entirely clear to me if we actually want to work towards including LGTM in the PDF.js project (e.g. running alongside Travis) or if we should just close issue 11965.
2020-11-01 12:08:38 +01:00
Jonas Jenwald
75af932b79 Update npm packages 2020-11-01 10:04:57 +01:00
Tim van der Meij
46e60a266c
Merge pull request #12552 from Snuffleupagus/annotation-fixes
Miscellaneous (small) improvements in `src/core/annotation.js`
2020-10-31 00:41:39 +01:00
Tim van der Meij
e341e6e542
Merge pull request #12525 from brendandahl/mark-info
[api-minor] Implement API to get MarkInfo from the catalog.
2020-10-31 00:05:19 +01:00
Brendan Dahl
8a8b4f9697 Collect telemetry in the viewer on whether a PDF is tagged. 2020-10-30 10:59:45 -07:00
Brendan Dahl
f5c821e9c3 [api-minor] Implement API to get MarkInfo from the catalog. 2020-10-30 10:59:45 -07:00
Jonas Jenwald
fdb6520012 Change the Catalog.openAction getter back to using an Object internally (PR 12543 follow-up)
Given that the `Map`-pattern apparently has undesirable performance characteristics, change this getter back to using an Object instead and check its size before returning it.
2020-10-30 13:27:05 +01:00
Jonas Jenwald
a1e5581a0b Let Annotation._collectActions return null when no actions are present
Rather than returning an *empty* Object[1] we should be returning `null` instead, since that's consistent with existing API-functionality.
To avoid having to *manually* track if the Object is empty, this patch also introduces a small helper function to check its size.
2020-10-30 13:23:05 +01:00
Jonas Jenwald
8540b4cc76 Stop calling Font.charsToGlyphs, in src/core/annotation.js, with unused arguments
As can be seen in `src/core/fonts.js`, this method only accepts *one* parameter, hence it's somewhat difficult to understand what the Annotation-code is actually attempting to do here.
The only possible explanation that I can imagine, is that the intention was initially to call `Font.charToGlyph` *directly* instead. However, note that that'd would not actually have been correct, since that'd ignore one level of font-caching (see `this.charsCache`). Hence the unused arguments are removed, in `src/core/annotation.js`, and the `Font.charToGlyph` method is now marked as "private" as intended.
2020-10-30 13:17:52 +01:00
Tim van der Meij
bf870bd2ac
Merge pull request #12551 from Snuffleupagus/no-useless-escape
Fix *some* errors reported by the ESLint `no-useless-escape` rule
2020-10-29 23:18:51 +01:00
Jonas Jenwald
46e94cad17 Fix *some* errors reported by the ESLint no-useless-escape rule
This patch removes unnecessary escape-sequence in (mostly) strings, as a first step, since the ones in regular expressions probably requires more careful testing (just in case).
The only exception is a regular expression in `src/core/annotation.js`, since we should have both unit- and reference-tests for this code *and* given [this information on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes#Types):
 > Inside a character set, the dot loses its special meaning and matches a literal dot.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/no-useless-escape
2020-10-29 15:40:40 +01:00
Tim van der Meij
7853d9798b
Merge pull request #12543 from Snuffleupagus/openActionMap
Use a `Map`, rather than an `Object`, internally in the `Catalog.openAction` getter (PR 11644 follow-up)
2020-10-28 22:21:49 +01:00
Tim van der Meij
91ca2674c3
Merge pull request #12542 from Snuffleupagus/murmurhash-slice-test
Add a `MurmurHash3_64.update` unit-test for TypedArrays which share the same underlying ArrayBuffer (PR 12534 follow-up)
2020-10-28 22:15:00 +01:00
Jonas Jenwald
820fb7f969 Update all Object.fromEntries call-sites to ensure that a null prototype is used
Given that `Object.fromEntries` doesn't seem to *guarantee* that a `null` prototype is used, we thus hack around that by using `Object.assign` with `Object.create(null)`.
2020-10-28 14:43:44 +01:00
Jonas Jenwald
9fc7cdcc9d Use a Map, rather than an Object, internally in the Catalog.openAction getter (PR 11644 follow-up)
This provides a work-around to avoid having to conditionally try to initialize the `openAction`-object in multiple places.
Given that `Object.fromEntries` doesn't seem to *guarantee* that a `null` prototype is used, we thus hack around that by using `Object.assign` with `Object.create(null)`.
2020-10-28 14:43:28 +01:00
Jonas Jenwald
852c61ef57 Add a MurmurHash3_64.update unit-test for TypedArrays which share the same underlying ArrayBuffer (PR 12534 follow-up)
This probably ought to have been included in PR 12534, but better late than never I suppose, since it helps to more clearly demonstrate the bug in a way that a reference-test alone just cannot do.

When writing this unit-test I also noticed that it required a certain amount of "luck" to actually trigger the bug, prior to the patch, since it seems that the bug only reproduced for certain *unfortunate* sequences of TypedArray data. (The added unit-test contains one such, purposely simple, example.)
2020-10-28 12:42:04 +01:00
Tim van der Meij
ea4d88a330
Merge pull request #12395 from calixteman/checks
Render not displayed annotations in using normal appearance when printing
2020-10-28 00:11:10 +01:00
Tim van der Meij
08b00c13a7
Merge pull request #12539 from Snuffleupagus/TestReporter-import
Use standard `import` statements more when running the unit-tests
2020-10-27 22:26:37 +01:00
Tim van der Meij
6fae381c57
Merge pull request #12540 from Snuffleupagus/BaseViewer-version-check
Ensure that the same version of PDF.js is used in both the API and the Viewer (PR 8959 follow-up)
2020-10-27 22:22:47 +01:00
Calixte Denizet
6be2f84b4e Render not displayed annotations in using normal appearance when printing 2020-10-27 19:00:31 +01:00
Jonas Jenwald
62b19f7e9a Ensure that the same version of PDF.js is used in both the API and the Viewer (PR 8959 follow-up)
Given that we're now accessing certain API-functionality *directly* in this file, e.g. the AnnotationStorage and Optional Content configuration, ensuring that there's not a version mismatch definitely seem like a good idea to prevent any *subtle* future bugs.
2020-10-27 17:09:42 +01:00
Jonas Jenwald
d8da6afa4c Update the description of the test-case used in the escapeString unit-test
The description *itself* didn't escape the control characters correctly, leading to line-breaks being inserted in the test logs.
2020-10-27 11:47:40 +01:00
Jonas Jenwald
92477333f6 Load the non-test files with standard import statements when running the unit-tests
The unit-test files themselves shouldn't be loaded until Jasmine has been setup/configured, however that doesn't matter for the "normal" PDF.js library files. Hence we can simply `import` them in the standard way.
2020-10-27 11:47:35 +01:00
Jonas Jenwald
8eeb0bcbe4 Import the TestReporter, in the unit and font tests
This way it's no longer necessary to load it as a script in the html-files.
2020-10-27 11:30:15 +01:00
Tim van der Meij
8098102714
Merge pull request #12532 from Snuffleupagus/refactor-font-tests
Modernize, and remove SystemJS usage from, the font-tests
2020-10-27 00:06:47 +01:00
Jonas Jenwald
939af08ee1 Remove SystemJS usage from the font-tests
With these changes, SystemJS is now *only* used to load the worker-file in development mode (pending removal once https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 is fixed).
2020-10-26 23:42:44 +01:00
Jonas Jenwald
15a5f66973 Enable the ESLint no-var rule in the test/font/ folder
This was done automatically, using the `gulp lint --fix` command.
2020-10-26 23:42:44 +01:00
Jonas Jenwald
6967b9dd96 Modernize the font-tests
This patch first of all enables linting of the files in the `test/font/` folder, and secondly it also re-factors all test files to use native `import`/`export` statements. Finally, all tests are now loaded correctly, rather than being included as scripts through the `font_test.html` file.
2020-10-26 23:42:44 +01:00
Tim van der Meij
71a14be8e7
Merge pull request #12534 from Snuffleupagus/murmurhash-slice
Ensure that `MurmurHash3_64.update` handles `ArrayBuffer` input correctly, to avoid hash-collisions (issue 12533)
2020-10-26 23:34:03 +01:00
Tim van der Meij
b27e4fac9e
Merge pull request #12527 from Snuffleupagus/worker-rm-require
Remove SystemJS usage from the development viewer and the unit-tests
2020-10-26 23:28:03 +01:00
Jonas Jenwald
f2fa053c51 Ensure that MurmurHash3_64.update handles ArrayBuffer input correctly, to avoid hash-collisions (issue 12533)
Different fonts incorrectly end up with *identical* hashes, despite having different /ToUnicode data.
The issue, and it's very interesting that we've apparently not seen it before, appears to be caused by the fact that different /ToUnicode entries share the *same* underlying `ArrayBuffer`, which thus becomes problematic at the `const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);` line. The simplest solution thus seem to be to just *copy* the input, when it's an `ArrayBuffer`, rather than using it as-is. (Note that if we'd stringified the input, when calling `MurmurHash3_64.update`, the issue would also have been fixed. In this case, we're already creating an unique TypedArray.)
2020-10-26 16:27:33 +01:00
Jonas Jenwald
666535be47 Prevent use of optional chaining and nullish coalescing in the src/shared/ folder
Given that this code is used on the worker-thread, where SystemJS is still used during development, we need to (for now) handle this folder the same way as the `src/core/` one.
2020-10-26 13:16:01 +01:00
Jonas Jenwald
c293fc2b8f Add (some) optional chaining usage in src/display/api.js
Since we no longer use SystemJS to load the unit-tests, there's now nothing that prevents us from using optional chaining and nullish coalescing in the `src/display/` directory.
2020-10-26 11:11:48 +01:00
Jonas Jenwald
1c4495843c Load all unit-tests with native import, rather than SystemJS 2020-10-26 11:11:48 +01:00
Jonas Jenwald
d9084c0be2 Load the fake worker, in non-PRODUCTION mode, with native async import
This removes the last SystemJS usage from both the API and the default viewer.
2020-10-26 11:11:48 +01:00
Jonas Jenwald
126f42a266 Only ignore the src/core/{glyphlist, unicode}.js files, during building of pdf.worker.js, when source-maps are enabled
This produces a slightly smaller built `pdf.worker.js` file, for e.g. the `gulp mozcentral` build-target.
2020-10-26 11:11:44 +01:00
Jonas Jenwald
56fa6d414c Add a getArrayLookupTableFactory helper function and use it to re-format src/core/{glyphlist, unicode}.js
*Please note:* Once https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 is implemented, and we've removed SystemJS completely, this entire patch can (and even should) be reverted.

This is similar to the existing `getLookupTableFactory` helper function, but is implemented as outlined in issue 6774.
The re-formatting of the tables were done automatically, by using find-and-replace with regular expressions.

For reasons that I don't even pretend to understand, using this particular structure for these *very* long lookup tables allow SystemJS to process the files correctly/quickly and the development viewer thus works as intended.
2020-10-26 11:08:00 +01:00
Jonas Jenwald
441d9c8cc0 Change src/core/{glyphlist, unicode}.js to use standard import/export statements
While the *built* `pdf.worker.js` file still works correctly with these changes, despite these two files being excluded by Babel[1], the development viewer does not because of issues with SystemJS[2] and/or its Babel-plugin (both of which are old).
Furthermore, note also that excluding these two files from Babel-processing isn't *generally* necessary since e.g. the `gulp mozcentral` command works anyway. The explanation is rather that it's actually the source-map generation which fails for these huge sequences when building the `pdf.worker.js` file.

However, not using standard `import`/`export` statements in all files means we also need to use SystemJS when e.e. running the unit-tests. This is very unfortunate, since SystemJS (or its old Babel-version) doesn't support modern ECMAScript features such as e.g. optional chaining and nullish coalescing.

Unfortunately it also seems that https://bugzilla.mozilla.org/show_bug.cgi?id=1247687, which tracks the implementation of worker-modules in Firefox, has stalled since there hasn't been any updates for six months now.

To hopefully address all of the above, this patch is the first in a series that attempts to further reduce our reliance on SystemJS.

---
[1] The only difference being how the dependencies are handled, in the Webpack-bundled file.

[2] Parsing takes way too long and consumes too much memory, thus rendering the development viewer essentially unusable.
2020-10-26 11:08:00 +01:00
Tim van der Meij
b2a4dacd31
Merge pull request #12529 from Snuffleupagus/scripting-build-tweaks
Tweak the `pdf.scripting.js` bundling, to improve overall consistency
2020-10-25 18:41:20 +01:00
Tim van der Meij
2251677e5a
Merge pull request #12528 from timvandermeij/test-unit-no-var
Convert `var` to `const`/`let` in the `test/unit` folder
2020-10-25 18:34:13 +01:00
Jonas Jenwald
61ffa9caa9 Tweak the pdf.scripting.js bundling, to improve overall consistency
This brings the new `pdf.scripting.js` bundling more in-line with the pre-existing handling for the  `pdf.js`/`pdf.worker.js` files:
 - Add a new `src/pdf.scripting.js` file as the entry-point for the build scripts.

 - Add the version/build numbers at the top of the *built* `pdf.scripting.js` files, since all other built files include that information given that it's often helpful to be able to easily determine the *exact* version.

 - Tweak the `createScriptingBundle` in the gulp-file, since it looks like a little bit too much copy-and-paste in the variable names.
2020-10-25 16:36:56 +01:00
Tim van der Meij
fe08ef4e39
Fix var conversions that ESLint could not do automatically
This mainly involves the `crypto_spec.js` file which declared most
variables before their usage, which is not really consistent with the
rest of the codebase. This also required reformatting some long arrays
in that file because otherwise we would exceed the 80 character line
limit. Overall, this makes the code more readable.
2020-10-25 16:17:12 +01:00
Tim van der Meij
3e2bfb5819
Convert var to const/let in the test/unit folder
This has been done automatically using ESLint's `--fix` argument.
2020-10-25 15:40:51 +01:00
Tim van der Meij
314ac21842
Disable var usage for the test/unit folder
This allows us to enforce that `var` is not used anymore in the unit
tests to modernize the code and prevent subtle bugs.
2020-10-25 15:38:52 +01:00
Tim van der Meij
b4ca3d55b8
Merge pull request #12508 from calixteman/button_fallback_font
Fallback font for buttons must be ZapfDingbats.
2020-10-24 18:56:12 +02:00
Tim van der Meij
0d1a874358
Merge pull request #12464 from baloone/Fix_getVisibleElements_in_rtl_direction
Fix getVisibleElements helper in RTL-locales
2020-10-24 17:03:57 +02:00
Tim van der Meij
e8e029dfb5
Merge pull request #12522 from Snuffleupagus/_initializeJavaScript-fixes
Fix a couple of edge-cases in `PDFViewerApplication._initializeJavaScript` (PR 12432 follow-up)
2020-10-24 16:11:06 +02:00
Tim van der Meij
da73537fdb
Merge pull request #12524 from Snuffleupagus/pr-12333-followup
A couple of small (viewer) tweaks of tooltip-only Annotations (PR 12333 follow-up)
2020-10-24 16:06:01 +02:00