Commit Graph

12370 Commits

Author SHA1 Message Date
Tim van der Meij
62ec8109b5
Merge pull request #11370 from Snuffleupagus/fetchCompressed-isStream
Stop caching Streams in `XRef.fetchCompressed`
2019-11-30 14:56:47 +01:00
Jonas Jenwald
168c6aecae Stop caching Streams in XRef.fetchCompressed
I'm slightly surprised that this hasn't actually caused any (known) bugs, but that may be more luck than anything else since it fortunately doesn't seem common for Streams to be defined inside of an 'ObjStm'.[1]

Note that in the `XRef.fetchUncompressed` method we're *not* caching Streams, and that for very good reasons too.

 - Streams, especially the `DecodeStream` ones, can become *very* large once read. Hence caching them really isn't a good idea simply because of the (potential) memory impact of doing so.

 - Attempting to read from the *same* Stream more than once won't work, unless it's `reset` in between, since using any method such as e.g. `getBytes` always starts at the current data position.

 - Given that even the `src/core/` code is now fairly asynchronous, see e.g. the `PartialEvaluator`, it's generally impossible to assert that any one Stream isn't being accessed "concurrently" by e.g. different `getOperatorList` calls. Hence `reset`-ing a cached Streams isn't going to work in the general case.

All in all, I cannot understand why it'd ever be correct to cache Streams in the `XRef.fetchCompressed` method.

---
[1] One example where that happens is the `issue3115r.pdf` file in the test-suite, where the streams in question are not actually used for anything within the PDF.js code.
2019-11-30 10:21:08 +01:00
Jonas Jenwald
06412a557b Slighthly re-factor XRef.fetchCompressed
- Change all occurences of `var` to `let`/`const`.

 - Initialize the (temporary) Arrays with the correct sizes upfront.

 - Inline the `isCmd` check. Obviously this won't make a huge difference, but given that the check is only relevant for corrupt documents it cannot hurt.
2019-11-30 09:49:51 +01:00
Tim van der Meij
b0aee6b1f0
Merge pull request #11363 from Snuffleupagus/fetchUncompressed-isInteger-checks
Remove the `Number.isInteger` checks from `XRef.fetchUncompressed` (PR 8857 follow-up)
2019-11-29 22:27:38 +01:00
Jonas Jenwald
725566cfea Remove the Number.isInteger checks from XRef.fetchUncompressed (PR 8857 follow-up)
Having ran the entire test-suite locally with these `Number.isInteger` checks removed, there wasn't a single test failure anywhere; see also PR 8857.
Hence everything points to this being completely unnecessary now, and by removing this code there's thus fewer function calls being made in `XRef.fetchUncompressed`.
2019-11-28 23:25:39 +01:00
Tim van der Meij
dcf998a1c1
Merge pull request #11356 from Snuffleupagus/rm-wrong-PDFDocument-comment
Remove outdated, and misleading, JSDoc comment from the `PDFDocument` class
2019-11-25 22:24:54 +01:00
Jonas Jenwald
cc76132c24 Remove outdated, and misleading, JSDoc comment from the PDFDocument class
The contents of this comment hasn't been correct for *years*, ever since the library was properly split into main/worker-threads, so it's probably high time for this to be updated.
2019-11-25 11:36:29 +01:00
Tim van der Meij
827eb64b75
Merge pull request #11354 from Snuffleupagus/eslint-more-rules
Enable the `getter-return`, `no-dupe-else-if`, and `no-setter-return` ESLint rules
2019-11-23 14:03:51 +01:00
Jonas Jenwald
1319c9f13b Update l10n files 2019-11-23 12:02:31 +01:00
Jonas Jenwald
a965662184 Enable the getter-return, no-dupe-else-if, and no-setter-return ESLint rules
All of these rules can help catch errors during development. Please note that only `getter-return` required a few changes, which was limited to disabling the rule in a couple of spots; please find additional details about these rules at:
 - https://eslint.org/docs/rules/getter-return
 - https://eslint.org/docs/rules/no-dupe-else-if
 - https://eslint.org/docs/rules/no-setter-return
2019-11-23 11:40:30 +01:00
Jonas Jenwald
b8f0cf0bc0 Update npm packages 2019-11-23 11:25:24 +01:00
Tim van der Meij
2feb3170bf
Merge pull request #11325 from smohtadi/custom-file-transform
Added custom file transform function
2019-11-22 23:02:34 +01:00
Tim van der Meij
79aa936f33
Merge pull request #11353 from Snuffleupagus/rm-attachEvent
Remove `document.attachEvent` code from `web/pdf_print_service.js` since it's only necessary for old IE versions
2019-11-22 22:54:55 +01:00
Jonas Jenwald
e09310d7a4 Remove document.attachEvent code from web/pdf_print_service.js since it's only necessary for old IE versions
This code was originally added to support IE10 (and below), however with those browsers *explicitly* unsupported since PDF.js version `2.0` this code is now dead.
2019-11-22 13:46:44 +01:00
Tim van der Meij
96c595411a
Merge pull request #11350 from Snuffleupagus/_pagesRequests-WeakMap
Convert `{BaseViewer, PDFThumbnailViewer}._pagesRequests` from an Array to a WeakMap
2019-11-21 23:41:54 +01:00
Jonas Jenwald
0f73758222 Convert {BaseViewer, PDFThumbnailViewer}._pagesRequests from an Array to a WeakMap
Obviously the `_pagesRequests` functionality is *mainly* used when `disableAutoFetch` is set, but it will also be used during ranged/streamed loading of documents.
However, the `_pagesRequests` property is currently an Array which seems a bit strange:

 - Arrays are zero-indexed, but the first element will never actually be set in the code.
 - The `_pagesRequests` Array is never cleared, unless a new document is loaded, and once the `PDFDocumentProxy.getPage` call has resolved/rejected the element is just replaced by `null`.
 - Unless the document is browsed *in order* the resulting `_pagesRequests` Array can also be arbitrarily sparse.

All in all, I don't believe that an Array is an appropriate data structure to use for this purpose.
2019-11-21 09:38:37 +01:00
Tim van der Meij
ef1cd11908
Merge pull request #11338 from Snuffleupagus/toolbar-buttons-init
Reduce duplication when registering event listeners for the `Toolbar` buttons, and other small clean-up
2019-11-19 23:59:14 +01:00
Tim van der Meij
026121286c
Merge pull request #11346 from Snuffleupagus/pageViewsReady-printing
Ensure that attempting to print with `disableAutoFetch` set will fail gracefully (issue 11339)
2019-11-19 23:46:51 +01:00
Jonas Jenwald
0b0bf71ad0 Ensure that attempting to print with disableAutoFetch set will fail gracefully (issue 11339)
This patch simply restores the behaviour that existed prior to PR 7697, since I cannot imagine that that was changed other than by pure accident.
As mentioned by a comment in `BaseViewer.setDocument`: "Printing is semi-broken with auto fetch disabled.", and note that since triggering of printing is a synchronous operation there's generally no easy way to load the missing data.

https://github.com/mozilla/pdf.js/pull/7697/files#diff-529d1853ee1bba753a0fcb40ea778723L1114-L1118
2019-11-19 12:13:15 +01:00
Jonas Jenwald
07473e9e2a Inline the Toolbar._localized method in the 'localized' event handler
Considering just how small/simple this code is, it doesn't seem necessary to have a separate method for it (even more so when there's only one call-site).
2019-11-17 14:17:47 +01:00
Jonas Jenwald
eaa2e216f4 Use for...of in a couple of loops in web/toolbar.js and web/secondary_toolbar.js 2019-11-17 13:59:28 +01:00
Jonas Jenwald
3edaebbded Reduce duplication when registering event listeners for the Toolbar buttons
This uses the same kind of format as is being used in the `SecondaryToolbar` class.
2019-11-17 13:55:29 +01:00
Tim van der Meij
be02e67972
Merge pull request #11335 from Snuffleupagus/issue-11330
Subtract `stream.start` when getting the `startXRef` property for documents with a Linearization dictionary (issue 11330)
2019-11-16 13:56:01 +01:00
Tim van der Meij
789c2c6a7e
Merge pull request #11334 from Snuffleupagus/FlateStream-readBlock-getBytes
Use `getBytes`, rather than looping over `getByte`, in `FlateStream.prototype.readBlock`
2019-11-16 13:50:40 +01:00
Jonas Jenwald
9199b02a42 Subtract stream.start when getting the startXRef property for documents with a Linearization dictionary (issue 11330)
For documents with a Linearization dictionary the computed `startXRef` position will be relative to the raw file, rather than the actual PDF document itself (which begins with `%PDF-`).
Hence it's necessary to subtract `stream.start` in this case, since otherwise the `XRef.readXRef` method will increment the position too far resulting in parsing errors.
2019-11-16 09:29:10 +01:00
Jonas Jenwald
688d15526e Use getBytes, rather than looping over getByte, in FlateStream.prototype.readBlock
*Please note:* A a similar change was attempted in PR 5005, but it was subsequently backed out (in PR 5069) since other parts of the patch caused issues.

With these changes, it's possible to replace repeated function calls within a loop with just a single function call and subsequent assignment instead.
2019-11-15 15:45:31 +01:00
smohtadi
fe6d86fb52 added transform function
added depedencies

removed gulp-transform dependency

removed dependencies

removed gulptransform dependency
2019-11-14 14:45:00 -08:00
Tim van der Meij
f7aafcb218
Merge pull request #11317 from Snuffleupagus/update-npm-packages
Update npm packages
2019-11-12 00:14:00 +01:00
Tim van der Meij
3a05f6fe25
Merge pull request #11318 from Snuffleupagus/IE-polyfill-pushState-replaceState
[PDFHistory] Move the IE11 `pushState`/`replaceState` work-around to `src/shared/compatibility.js` (PR 10461 follow-up)
2019-11-12 00:09:27 +01:00
Jonas Jenwald
878432784c [PDFHistory] Move the IE11 pushState/replaceState work-around to src/shared/compatibility.js (PR 10461 follow-up)
I've always disliked the solution in PR 10461, since it required changes to the `PDFHistory` code itself to deal with a bug in IE11.
Now that IE11 support is limited, it seems reasonable to remove these `pushState`/`replaceState` hacks from the main code-base and simply use polyfills instead.
2019-11-11 17:48:04 +01:00
Jonas Jenwald
f46fd9e306 Fix (some) vulnerabilities reported by npm audit
This was done automatically, using the `npm audit fix` command.
2019-11-11 11:23:17 +01:00
Jonas Jenwald
ae4af9ab58 Update npm packages 2019-11-11 11:22:03 +01:00
Tim van der Meij
21895aa75a
Merge pull request #11316 from Snuffleupagus/globalScope-isNodeJS-modules
Convert `globalScope` and `isNodeJS` to proper modules
2019-11-10 19:43:01 +01:00
Jonas Jenwald
74e00ed93c Change isNodeJS from a function to a constant
Given that this shouldn't change after the `pdf.js`/`pdf.worker.js` files have been loaded, it doesn't seems necessary to keep this as a function.
2019-11-10 16:44:29 +01:00
Jonas Jenwald
2817121bc1 Convert globalScope and isNodeJS to proper modules
Slightly unrelated to the rest of the patch, but this also removes an out-of-place `globals` definition from the `web/viewer.js` file.
2019-11-10 16:44:29 +01:00
Tim van der Meij
c2bd3a0bfb
Merge pull request #11300 from nisarhassan12/master
Simplifies code contributions by automating the dev setup
2019-11-10 16:32:02 +01:00
Tim van der Meij
9de05161a7
Merge pull request #11315 from timvandermeij/issue6179_reduced
Include a reduced test case for annotations without a `Border`/`BS` entry (PR 6180 follow-up)
2019-11-10 15:45:02 +01:00
Tim van der Meij
6972bbea74
Include a reduced test case for annotations without a Border/BS entry (PR 6180 follow-up) 2019-11-10 14:37:42 +01:00
Tim van der Meij
8c97281b74
Merge pull request #11305 from mgrigis/master
Fix nodejs core module :  ignore url module for web browser
2019-11-10 13:48:47 +01:00
Tim van der Meij
6763e16804
Merge pull request #11313 from Snuffleupagus/issue-11122
Ensure that Popup annotations, where the parent annotation is a polyline, will always be possible to open/close (issue 11122)
2019-11-10 13:31:51 +01:00
Tim van der Meij
c6ee4480f7
Merge pull request #11314 from Snuffleupagus/revert-11312-async-getPageDict
Revert "Convert `Catalog.getPageDict` to an `async` method"
2019-11-10 13:05:57 +01:00
Jonas Jenwald
0233fc07b6
Revert "Convert Catalog.getPageDict to an async method" 2019-11-09 22:36:23 +01:00
Jonas Jenwald
536a52e981 Ensure that Popup annotations, where the parent annotation is a polyline, will always be possible to open/close (issue 11122)
For Popup annotation trigger elements consisting of an arbitrary polyline, you need to ensure that the 'stroke-width' is always non-zero since otherwise it's impossible to actually open/close the popup.

Unfortunately I don't believe that any of the test-suites can be used to test this, hence why no tests are included in the patch.
2019-11-09 13:35:59 +01:00
Tim van der Meij
b1440a11c1
Merge pull request #11312 from Snuffleupagus/async-getPageDict
Convert `Catalog.getPageDict` to an `async` method
2019-11-08 22:38:22 +01:00
Jonas Jenwald
79d7c002de Inline a couple of isRef/isDict checks in the getPageDict method
As we've seen in numerous other cases, avoiding unnecessary function calls is never a bad thing (even if the effect is probably tiny here).

With these changes we also avoid potentially two back-to-back `isDict` checks when evaluating possible Page nodes, and can also no longer accidentally pick a dictionary with an incorrect /Type.
2019-11-08 17:53:00 +01:00
Jonas Jenwald
0d89006bf1 Convert Catalog.getPageDict to an async method
This makes it possible to remove the internal `next` helper function, and also gets rid of the need to manually resolve/reject a `PromiseCapability`.
2019-11-08 17:45:28 +01:00
Tim van der Meij
668650d564
Merge pull request #11308 from Snuffleupagus/abortOperatorList-assert
Prevent browser exceptions from incorrectly triggering the `assert` in `PDFPageProxy._abortOperatorList` (PR 11069 follow-up)
2019-11-07 23:35:42 +01:00
Jonas Jenwald
98f570c103 Prevent browser exceptions from incorrectly triggering the assert in PDFPageProxy._abortOperatorList (PR 11069 follow-up)
For certain canvas-related errors (and probably others), the browser rendering exceptions may be propagated "as-is" to the PDF.js code. In this case, the exceptions are of the somewhat cryptic `NS_ERROR_FAILURE` type.
Unfortunately these aren't actual `Error`s, which thus ends up unintentionally triggering the `assert` in `PDFPageProxy._abortOperatorList`; sorry about that!
2019-11-07 11:37:48 +01:00
Nisar Hassan Naqvi
b21a341332 Simplifies code contributions by automating the dev setup with gitpod.io 2019-11-06 04:12:19 +00:00
Tim van der Meij
4e0b02025f
Merge pull request #11307 from Snuffleupagus/stringToPDFString-little-endian
Support UTF-16 little-endian strings in the `stringToPDFString` helper function (bug 1593902)
2019-11-05 22:43:42 +01:00