Commit Graph

91 Commits

Author SHA1 Message Date
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
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
Jonas Jenwald
fb5e756683 Fix errors reported by the no-cond-assign ESLint rule
http://eslint.org/docs/rules/no-cond-assign
2016-12-12 20:26:06 +01:00
Tim van der Meij
cf3a7425b6 Compatibility: refactor user agent detection
This patch moves the user agent checks to the top of the file to reduce
duplication and to provide a clear overview of which user agent we are
detecting.

Moreover, we extract inline user agent checks as well and use existing
checks in more places. Finally, we fix the indenting in one place for
consistency.
2016-11-22 22:42:01 +01:00
Tim van der Meij
0b0e18f05c Compatibility: disable range request for iOS
Fixes #7815.
2016-11-22 22:19:20 +01:00
Jonas Jenwald
db2ce3ff64 Replace the Safari detection in checkRangeRequests in compatibility.js with a regular expression
According to e.g. issue 7754, it appears that the current `isSafari` check is failing in newer version of the browser. Despite the fact that checking the userAgent is an anti-pattern, which should be avoided, it's currently the simplest solution.
2016-11-11 17:15:24 +01:00
Gioele Masini
1c96cb8862 Added context to compatibility.js to have 'use strict' directive in our context only 2016-05-12 10:04:51 +02:00
Manas
a2ba1b8189 Uses editorconfig to maintain consistent coding styles
Removes the following as they unnecessary
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-11-14 07:32:18 +05:30
Yury Delendik
28d340679a Uses document.currentScript for pdf.worker.js path. 2015-11-06 07:50:21 -06:00
Fabian Lange
063ca95f5f Remove TryCatch in canvas fill
As verified by @Rob--W, the evenodd fill rule works correctly in all supported browsers. This now allows optimization by JS engines.

This fixes #5458
2015-09-05 11:10:51 +02:00
Tim van der Meij
12be47c57c Merge pull request #5598 from CodingFabian/chrome39-range-disable
Disable Range Support for Chrome 39+40 (#5512)
2015-04-30 22:31:50 +02:00
Fabian Lange
1d4758dadf Disable Range Support for Chrome 39+40 (#5512)
Disabling Range Support for Chrome 39 and 40, due to regression in
Chromium. https://crbug.com/442318
2015-04-29 23:25:58 +02:00
Jonas Jenwald
65a5543efe Disable PresentationMode for certain problematic configurations
Instead of trying to hack around various browser defects, let's just disable PresentationMode in the affected browsers. This patch:

- Disables PresentationMode in IE11+ when the viewer is embedded; fixes 4711.
2015-03-13 22:09:36 +01:00
Rob Wu
ac5a8bcdda [l10n] Treat language as case-insensitive
See "Case-insensitive language comparisons per RFC 4646"
https://github.com/fabi1cazenave/webL10n/pull/51

Removed the "patch" in compatibility.js and fixed the bug in webL10n,
because the logic belongs to webL10n instead of PDF.js.
The immediate motivation for this patch is that Chrome 40 converts
navigator.language to lower case: https://crbug.com/454331
2015-02-02 22:02:18 +01:00
Yury Delendik
c3f191a27c Implement streaming using moz-chunk-arraybuffer 2014-09-19 19:05:25 -05:00
Tom De Wolf
a265861ba6 only convert in IE9 if the requested responseType is actually an arraybuffer, otherwise just return the responseText. That way the compatibility.js does not break other frameworks like angular that not always want an array from xhr requests. 2014-08-10 10:26:32 +02:00
Tim van der Meij
097bf41285 Use strict equalities in web/compatibility.js 2014-08-01 19:21:33 +02:00
Yury Delendik
561fc8f98b Adds ImageData set support for legacy safari 2014-07-22 11:40:32 -05:00
Fabian Lange
54fb1f7226 Improving CanvasPixelArray polyfill for Android 2014-06-25 18:44:49 +02:00
Fabian Lange
9fd6cc7f1e Fixes CanvasPixelArray set polyfill for chrome < 21 (#4974) 2014-06-24 19:36:02 +02:00
Yury Delendik
dccc709b50 Disables broken rAF on iOS 2014-06-17 12:44:52 -05:00
Samuel Chantaraud
952545e20f Limit the size of canvases to 5MP (iOS restriction) 2014-06-12 17:58:58 -04:00
Yury Delendik
5ded0ea163 Merge pull request #4866 from yurydelendik/issue4673
Removes mozResponseArrayBuffer
2014-06-02 12:51:29 -05:00
Yury Delendik
f9befa189b Disables worker if XHR does not support arraybuffer 2014-05-29 20:38:50 -05:00
Yury Delendik
9c87fa24f7 Removes mozResponseArrayBuffer 2014-05-29 20:38:50 -05:00
Yury Delendik
34089212e0 Reverts mozRequestAnimationFrame to compatibility.js 2014-05-29 16:23:13 -05:00
Michał Gołębiowski
85291dd8da Update web/compatibility.js
1) Remove obsolete workarounds
2) Add support comments
2014-05-28 09:57:25 +02:00
Tim van der Meij
53f3b1326a Removes unused code from web/compatibility.js 2014-05-09 21:26:07 +02:00
Yury Delendik
c5eb058b09 Uses rAF to interrupt the operator list execution 2014-05-09 07:00:47 -05:00
Jonas Jenwald
8bb19fac2d Catch error when the creation of localStorage polyfill fails in the generic viewer 2014-04-29 15:50:48 +02:00
Tim van der Meij
b348243866 Fixes lint warning W004 in /web 2014-04-11 00:02:33 +02:00
Yury Delendik
b39f0c311c Refactors history and how the database is stored 2014-04-03 13:23:18 -05:00
Yury Delendik
cebf7836f4 Simulate support of the Int8Array for IE9 2014-03-20 18:50:34 -05:00
Yury Delendik
31ea4e0f4d Merge pull request #4420 from prometheansacrifice/RemovingCheckSetPresence
Removing set-presence-in-ImageData check from canvas.js
2014-03-13 08:31:53 -05:00
Manas (prometheansacrifice)
30e00bc573 Removing set-presence-in-ImageData check from canvas.js 2014-03-11 08:48:37 +05:30
Jonas Jenwald
665b862b7f Fix coding style in web/compatibility.js 2014-03-09 11:51:15 +01:00
Samuel Chantaraud
cbc9ad3cb6 Correct formatting of locale to make it compatible with l10n (safari issue) 2014-02-26 16:09:58 -04:00
Mitar
628de8a1f4 Fix for bind compatibility implementation (polyfill).
Previously, reconstruction of arguments was incorrect if arguments contained
arrays. Arrays were added to arguments as their elements and not as a whole
array. It is enough to simply pass whole array to concat and it will be (only
one level deep) added to arguments.

In addition, we call slice on arguments for maximum compatibility (it is used
in Underscore.js library, with which I was comparing implementations while
debugging).
2014-02-15 03:48:18 -08:00
Yury Delendik
a8c11ad1e5 Introduces disableObjectCreateURL 2014-01-10 16:30:41 -06:00
Lu Wang
6553bd6c0c add 'contains' for the classList implementation 2013-11-06 14:52:04 +08:00
Jonas
f61d272754 Disable range requests in old Android versions 2013-08-29 01:53:57 +02:00
Brendan Dahl
e9f5336cc9 Add atob polyfill. Remove uneeded data uri polyfill. 2013-07-17 10:26:12 -07:00
Rob Wu
b076cd1d6a Always declare window.URL even if undefined
Otherwise it breaks feature detection,
"ReferenceError: Can't find variabl: URL" in Safari 5.1
2013-07-10 23:34:10 +02:00
Rob Wu
69a64d45bc Put URL = URL || webkitURL in compatibility.js
Declares the URL variable globally. If the feature is not
supported, the variable will still be declared, but have the
"undefined" value.

Supported by:

- Firefox 4
  Firefox 21 in Web worker

- Chrome 8  (prefixed as webkitURL), 23+ unprefixed
  Chrome 10 (prefixed as webkitURL) in Web Worker, 23+ unprefixed

- Opera 15
  Opera 15 in Web Worker

- Internet Explorer 10
  Internet Explorer 11 in Web Worker

- Safari 6 (prefixed as webkitURL)
  Safari 6 (prefixed as webkitURL) in Web Worker
2013-07-09 22:54:12 +02:00
benbro
74ee295812 Add IE 11 to the text/html data URI shim 2013-06-29 23:43:41 +03:00
Jonas
5c93ec3a2c Check if the browser supports manipulation of the history 2013-06-24 20:46:13 +02:00
Yury Delendik
729e35079f Disables range requestes for safari immediately 2013-06-12 12:03:27 -05:00
Yury Delendik
152e376971 Capturing disableRange set on capture phase of DOMContentLoaded event 2013-06-11 09:01:36 -05:00
Brendan Dahl
e6dadaadb8 Disable range request loading for safari. 2013-06-03 15:31:42 -07:00
vyv03354
385a5f7dcc Add a console warning when JavaScript/AcroForm/XFA was found 2013-03-19 07:27:09 +09:00