Commit Graph

9334 Commits

Author SHA1 Message Date
Jonas Jenwald
3aa37ae8bc Add the external/builder/fixtures/ directory to .eslintignore, to avoid having to disable various lint rules locally
This is similar to the already existing exception for `external/builder/fixtures_esprima`.
2017-01-10 14:45:40 +01:00
Jonas Jenwald
fe9a561d45 Actually increment the errors counter on failures in test-fixtures.js/test_fixtures_esprima.js, so that the test runners won't incorrectly report that the tests passed 2017-01-10 14:45:36 +01:00
Jonas Jenwald
cf00516f04 Rename the external/builder/test*.js files to make it more obvious what they test
Currently you have to open the files to be certain which tests each one will run, which we can avoid by appending the directory names to the file names of the tests themselves.
2017-01-10 14:27:05 +01:00
Jonas Jenwald
ca0ebdfa56 Merge pull request #7942 from yurydelendik/rm-deadcode
Fixes preprocessor testing and adds deadcode removal.
2017-01-10 13:31:47 +01:00
Yury Delendik
77b7b84d1e Removes rest of 'no-else-return' comments. 2017-01-09 19:13:36 -06:00
Yury Delendik
6265bb6038 Fixes preprocessor testing and adds deadcode removal. 2017-01-09 19:05:36 -06:00
Tim van der Meij
f828f07ccd Merge pull request #7941 from Snuffleupagus/Page-idFactory
Replace direct lookup of `uniquePrefix`/`idCounters`, in `Page` instances, with an `idFactory` containing an `createObjId` method instead
2017-01-10 00:25:48 +01:00
Jonas Jenwald
642d8621ef Replace direct lookup of uniquePrefix/idCounters, in Page instances, with an idFactory containing an createObjId method instead
We're currently making use of `uniquePrefix`/`idCounters` in multiple files, to create unique object id's, and adding a new occurrence of them requires some care to ensure that an object id isn't accidentally reused.
Furthermore, having to pass around multiple parameters as we currently do seem like something you want to avoid.

Instead, this patch adds a factory which means that there's only *one* thing that needs to be passed around. And since it's now only necessary to call a method in order to obtain a unique object id, the details are thus abstracted away at the call-sites which avoids accidental reuse of object id's.

To test that this works as expected a very simple `Page` unit-test is added, and the existing `Annotation layer` tests are also adjusted slightly.
2017-01-09 23:16:25 +01:00
Tim van der Meij
e259bc2c16 Merge pull request #7939 from yurydelendik/unittesttravis
Enables some unit tests on travis.
2017-01-09 23:14:17 +01:00
Tim van der Meij
098acb1269 Merge pull request #7935 from Snuffleupagus/eslint_no-else-return
Enable the `no-else-return` ESLint rule
2017-01-09 23:03:48 +01:00
Yury Delendik
c45300e06c Enables some unit tests on travis. 2017-01-09 15:43:45 -06:00
Jonas Jenwald
4046d67fde Enable the no-else-return ESLint rule
Using `else` after `return` is not necessary, and can often lead to unnecessarily cluttered code. By using the `no-else-return` rule in ESLint we can avoid this pattern, see http://eslint.org/docs/rules/no-else-return.
2017-01-09 20:27:39 +01:00
Yury Delendik
049d7fa277 Merge pull request #7934 from porlan1/master
Unit test files as modules
2017-01-09 11:27:31 -06:00
porlan1
d9e1cb7955 unit test files as UMD modules 2017-01-09 11:40:57 -05:00
Jonas Jenwald
aabfb7788a Merge pull request #7926 from Snuffleupagus/api-onPassword-abort/throw-Promise
[api-minor] Ensure that the `getDocument` Promise is rejected if the `loadingTask` is destroyed, or an `Error` is thrown, inside of the `onPassword` callback (issue 7806)
2017-01-04 10:44:18 +01:00
Jonas Jenwald
14b8523314 Refactor the password handling so that it's stored in the PdfManagers, instead of in the XRef
We're already passing in a, currently unused, `PdfManager` instance when initializing the `XRef`. To avoid having to pass a single `password` parameter around, we could thus simply get the `password` through the `PdfManager` instance instead.
2017-01-03 20:29:52 +01:00
Jonas Jenwald
27513cd23b [api-minor] Ensure that the getDocument Promise is rejected if the loadingTask is destroyed, or an Error is thrown, inside of the onPassword callback (issue 7806)
This patch also removes the `UpdatePassword` message, in favour of using the `sendWithPromise` method of `MessageHandler`.
Furthermore, the patch also refactors the `BasePdfManager_updatePassword`/`BasePdfManager_passwordChanged` methods (in pdf_manager.js), and the `pdfManagerReady` function (in worker.js).
2017-01-03 20:29:46 +01:00
Jonas Jenwald
4e62562a36 Update l10n files 2017-01-02 13:26:09 +01:00
Jonas Jenwald
59afb4b9f0 Merge pull request #7920 from Snuffleupagus/bug-1157493-followup
Improve the handling of `Encoding` dictionary, with `Differences` array, in `PartialEvaluator_preEvaluateFont`
2016-12-29 10:52:31 +01:00
Jonas Jenwald
ddea9a6b04 Improve the handling of Encoding dictionary, with Differences array, in PartialEvaluator_preEvaluateFont
I recently happened to look at the code I wrote for PR 5964, which fixed [bug 1157493](https://bugzilla.mozilla.org/show_bug.cgi?id=1157493), and I quickly realized that the solution is way too simplistic.
The fact that only using the `length` of a `Differences` array worked seems more like a happy accident for a particular set of font data, but could just as easily be incorrect for other PDF files.

Note that in practice, the case where the `Encoding` entry is a regular `Dict` (and not a `Ref` or `Name`) is very rare, hence I don't think that we really need to worry about having to reparse this data.
Also, the performance of this code-block is quite a bit better by updating the `hash` with the data from the *entire* `Differences` array, instead of at every loop iteration.
2016-12-28 21:32:54 +01:00
Tim van der Meij
22f0a04df0 Merge pull request #7829 from Snuffleupagus/finishPaintTask-promise
Let `finishPaintTask` in pdf_page_view.js return a promise instead, to avoid having to throw in the `paintTask.promise` rejection handler, and don't reject the `PDFPageView_draw` promise when rendering is `cancelled`
2016-12-27 23:51:06 +01:00
Yury Delendik
3b3a179486 Merge pull request #7879 from rossj/highlight-fix
Make use of textAdvanceScale consistent during combineTextItems. Fix for #7878.
2016-12-19 09:18:13 -06:00
Jonas Jenwald
33063a486e Update l10n files 2016-12-19 11:10:14 +01:00
Jonas Jenwald
73e0daed6c Let finishPaintTask in pdf_page_view.js return a promise instead, to avoid having to throw in the paintTask.promise rejection handler, and don't reject the PDFPageView_draw promise when rendering is cancelled
As mentioned on IRC yesterday, we currently throw even when rendering is `cancelled`, which is annoying when the devtools are active. Furthermore, since `cancelled` isn't really an error, rejecting the `PDFPageView_draw` promise seems somewhat strange in that case.
2016-12-17 22:29:48 +01:00
Tim van der Meij
017e9b98d1 Merge pull request #7898 from timvandermeij/acroforms-checkbox-radiobutton
Interactive forms: render button widget annotations (checkboxes and radio buttons)
2016-12-17 21:22:15 +01:00
Tim van der Meij
a428899b3c Button widget annotations: improve unit tests, simplify code and remove labels
Modern browsers support styling radio buttons and checkboxes with CSS.
This makes the implementation much easier, and the fallback for older
browsers is still decent.
2016-12-17 20:38:48 +01:00
Tim van der Meij
77148c7880 Button widget annotations: implement radio button value fetching according to the specification 2016-12-17 20:34:32 +01:00
Tim van der Meij
0c9a06c020 Button widget annotations: implement reference testing
Moreover, ensure that the read-only state is respected and improve CSS
names.
2016-12-17 20:33:35 +01:00
benweet
ba012c7a68 Button widget annotations: implement checkboxes and radio buttons 2016-12-17 20:31:30 +01:00
Tim van der Meij
d0893b0c48 Merge pull request #7900 from Snuffleupagus/choiceWidget-Opt-indirect-objects
Ensure that we handle indirect objects in all types of `Opt` entries in `ChoiceWidget` annotation dictionaries
2016-12-17 20:29:43 +01:00
Jonas Jenwald
bd91f34513 Ensure that we handle indirect objects in all types of Opt entries in ChoiceWidget annotation dictionaries
I haven't got an example where the current code breaks, but given all the previous cases we've seen where PDF generators use indirect objects in Arrays it makes sense to fix this pro-actively.
I've modified the relevant unit-tests slightly, and they would *not* pass without the code changes in this patch.

*Note:* `Dict_getArray` only dereferences Array elements on the "top-level", to avoid recursion issues. Furthermore if you have to loop through the Array at the call-site anyway, then using `Dict_get` in combination with `XRef_fetchIfRef` is a tiny bit more efficient.
2016-12-17 13:44:20 +01:00
Tim van der Meij
a719b71e59 Merge pull request #7897 from Snuffleupagus/eslint-switch
Switch to using ESLint, instead of JSHint, for linting
2016-12-16 22:40:41 +01:00
Jonas Jenwald
c850968fa7 Remove globals that are now unnecessary thanks to the use of various ESLint environments (e.g. Node, ShellJS, Jasmine) 2016-12-16 21:09:55 +01:00
Jonas Jenwald
2f3805efbc Switch to using ESLint, instead of JSHint, for linting
*Please note that most of the necessary code adjustments were made in PR 7890.*

ESLint has a number of advantageous properties, compared to JSHint. Among those are:
 - The ability to find subtle bugs, thanks to more rules (e.g. PR 7881).
 - Much more customizable in general, and many rules allow fine-tuned behaviour rather than the just the on/off rules in JSHint.
 - Many more rules that can help developers avoid bugs, and a lot of rules that can be used to enforce a consistent coding style. The latter should be particularily useful for new contributors (and reduce the amount of stylistic review comments necessary).
 - The ability to easily specify exactly what rules to use/not to use, as opposed to JSHint which has a default set. *Note:* in future JSHint version some of the rules we depend on will be removed, according to warnings in http://jshint.com/docs/options/, so we wouldn't be able to update without losing lint coverage.
 - More easily disable one, or more, rules temporarily. In JSHint this requires using a numeric code, which isn't very user friendly, whereas in ESLint the rule name is simply used instead.

By default there's no rules enabled in ESLint, but there are some default rule sets available. However, to prevent linting failures if we update ESLint in the future, it seemed easier to just explicitly specify what rules we want.
Obviously this makes the ESLint config file somewhat bigger than the old JSHint config file, but given how rarely that one has been updated over the years I don't think that matters too much.

I've tried, to the best of my ability, to ensure that we enable the same rules for ESLint that we had for JSHint. Furthermore, I've also enabled a number of rules that seemed to make sense, both to catch possible errors *and* various style guide violations.

Despite the ESLint README claiming that it's slower that JSHint, https://github.com/eslint/eslint#how-does-eslint-performance-compare-to-jshint, locally this patch actually reduces the runtime for `gulp` lint (by approximately 20-25%).

A couple of stylistic rules that would have been nice to enable, but where our code currently differs to much to make it feasible:
 - `comma-dangle`, controls trailing commas in Objects and Arrays (among others).
 - `object-curly-spacing`, controls spacing inside of Objects.
 - `spaced-comment`, used to enforce spaces after `//` and `/*. (This is made difficult by the fact that there's still some usage of the old preprocessor left.)

Rules that I indend to look into possibly enabling in follow-ups, if it seems to make sense: `no-else-return`, `no-lonely-if`, `brace-style` with the `allowSingleLine` parameter removed.

Useful links:
 - http://eslint.org/docs/user-guide/configuring
 - http://eslint.org/docs/rules/
2016-12-16 21:06:36 +01:00
Ross Johnson
4537590033 Consitently apply textAdvanceScale during building of textContentItems for improved highlighting. Fixes #7878. 2016-12-14 21:02:19 -06:00
Jonas Jenwald
b629be05bd Merge pull request #7886 from Snuffleupagus/viewer-async-initialization
Move the `Preferences` initialization/fetching code to the top of `PDFViewerApplication.initialize`, to enable using them when initializing e.g. the viewer components
2016-12-14 17:30:40 +01:00
Jonas Jenwald
a96b0f80dd Convert the only remaining consumer (in hand_tool.js) of the 'localized' event to use the localized Promise instead, and only re-dispatch the 'localized' event on the eventBus for GENERIC builds
Ideally we'd remove the 'localized' event from the `eventBus`, but for backwards compatibility we keep it in `GENERIC` builds.
Note that while we want to ensure that the direction attribute of the HTML is updated as soon as the `localized` Promise is resolved, we purposely wait until the viewer has been initialized to ensure that the 'localized' event will always be dispatched.
2016-12-14 16:19:10 +01:00
Jonas Jenwald
648024f5d0 Don't call bindEvents() until PDFViewerApplication has been initialized, and move binding of window event listeners to a helper method, to prevent errors if an event manages to arrive too soon
With `bindEvents()` now being called after the viewer has been initialized, we no longer need to have `PDFViewerApplication.initialized` checks in the event handler functions.
Furthermore by moving the `window.addEventListener`s to a helper method, `PDFViewerApplication.initialized` checks are no longer necessary in the event handlers, hence we thus address part of issue 7797 here as well.
2016-12-14 16:17:10 +01:00
Jonas Jenwald
849f5dde9d Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing e.g. the viewer components
Note that in quick testing using `console.time/timeEnd`, both locally and with the Firefox addon, the total run time of the *entire* `PDFViewerApplication.initialize` function does not seem to change with this patch.
2016-12-14 16:15:53 +01:00
Jonas Jenwald
2c1436f6cb Refactor PDFViewerApplication.initialize into two methods, one that reads the Preferences and one that initializes the various viewer components 2016-12-14 16:13:20 +01:00
Tim van der Meij
7d8fa1385d Merge pull request #7890 from Snuffleupagus/pre-eslint-fixes
Fix a number of code style issues found by various ESLint rules, to make it easier to switch from JSHint to ESLint
2016-12-14 01:16:24 +01:00
Jonas Jenwald
28e50cfa21 Fix errors reported by the space-infix-ops ESLint rule
http://eslint.org/docs/rules/space-infix-ops
2016-12-12 20:36:00 +01:00
Jonas Jenwald
68bf47d55d Fix errors reported by the space-before-function-paren ESLint rule
http://eslint.org/docs/rules/space-before-function-paren
2016-12-12 20:35:59 +01:00
Jonas Jenwald
551eb263e3 Fix errors reported by the semi-spacing ESLint rule
http://eslint.org/docs/rules/semi-spacing
2016-12-12 20:35:58 +01:00
Jonas Jenwald
aae27e76bb Fix errors reported by the no-multiple-empty-lines ESLint rule
http://eslint.org/docs/rules/no-multiple-empty-lines
2016-12-12 20:35:58 +01:00
Jonas Jenwald
efbb1e9b1c Fix errors reported by the new-cap ESLint rule
http://eslint.org/docs/rules/new-cap
2016-12-12 20:35:57 +01:00
Jonas Jenwald
c36468cbce Fix errors reported by the keyword-spacing ESLint rule
http://eslint.org/docs/rules/keyword-spacing
2016-12-12 20:35:56 +01:00
Jonas Jenwald
86ba634c97 Fix errors reported by the key-spacing ESLint rule
http://eslint.org/docs/rules/key-spacing
2016-12-12 20:35:55 +01:00
Jonas Jenwald
6606540fe4 Fix errors reported by the func-call-spacing ESLint rule
http://eslint.org/docs/rules/func-call-spacing
2016-12-12 20:35:54 +01:00
Jonas Jenwald
ad915f8af1 Fix errors reported by the comma-spacing ESLint rule
http://eslint.org/docs/rules/comma-spacing
2016-12-12 20:35:53 +01:00