1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Enable the unicorn/prefer-optional-catch-binding ESLint plugin rule

According to MDN this format is available in all browsers/environments that we currently support, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#browser_compatibility

Please also see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-optional-catch-binding.md
This commit is contained in:
Jonas Jenwald 2023-06-12 11:46:11 +02:00
parent 9af50dc358
commit fee850737b
32 changed files with 45 additions and 44 deletions

View file

@ -28,7 +28,7 @@ class CFFFont {
this.seacs = this.cff.seacs;
try {
this.data = compiler.compile();
} catch (e) {
} catch {
warn("Failed to compile font " + properties.loadedName);
// There may have just been an issue with the compiler, set the data
// anyway and hope the font loaded.

View file

@ -1734,7 +1734,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() {
if (revision === 6) {
try {
password = utf8StringToString(password);
} catch (ex) {
} catch {
warn(
"CipherTransformFactory: Unable to convert UTF8 encoded password."
);

View file

@ -53,7 +53,7 @@ class DatasetReader {
const parser = new DatasetXMLParser({ hasAttributes: true });
try {
parser.parseFromString(data["xdp:xdp"]);
} catch (_) {}
} catch {}
this.node = parser.node;
}
}

View file

@ -1057,7 +1057,7 @@ class PDFDocument {
const str = stringToUTF8String(stream.getString());
const data = { [key]: str };
return shadow(this, "xfaDatasets", new DatasetReader(data));
} catch (_) {
} catch {
warn("XFA - Invalid utf-8 string.");
break;
}
@ -1077,7 +1077,7 @@ class PDFDocument {
}
try {
data[key] = stringToUTF8String(stream.getString());
} catch (_) {
} catch {
warn("XFA - Invalid utf-8 string.");
return null;
}

View file

@ -1498,7 +1498,7 @@ class PartialEvaluator {
);
operatorList.addOp(fn, tilingPatternIR);
return undefined;
} catch (ex) {
} catch {
// Handle any errors during normal TilingPattern parsing.
}
}

View file

@ -3045,7 +3045,7 @@ class Font {
cff.duplicateFirstGlyph();
const compiler = new CFFCompiler(cff);
tables["CFF "].data = compiler.compile();
} catch (e) {
} catch {
warn("Failed to compile font " + properties.loadedName);
}
}

View file

@ -129,7 +129,7 @@ class ImageResizer {
const opacity = ctx.getImageData(0, 0, 1, 1).data[3];
canvas.width = canvas.height = 1;
return opacity !== 0;
} catch (e) {
} catch {
return false;
}
}

View file

@ -67,7 +67,7 @@ function getHeaderBlock(stream, suggestedLength) {
try {
headerBytes = stream.getBytes(suggestedLength);
headerBytesLength = headerBytes.length;
} catch (ex) {
} catch {
// Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
// cannot hold the result of `getBytes`, and fallback to simply checking
// the entire stream (fixes issue3928.pdf).

View file

@ -644,7 +644,7 @@ class XFAObject {
for (const $symbol of Object.getOwnPropertySymbols(this)) {
try {
clone[$symbol] = this[$symbol];
} catch (_) {
} catch {
shadow(clone, $symbol, this[$symbol]);
}
}

View file

@ -523,7 +523,7 @@ function getUrlProp(val) {
try {
// The full path is required in the 'url' field.
return new URL(val, window.location).href;
} catch (ex) {
} catch {
if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC") &&
@ -2011,7 +2011,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
if (!base.origin || base.origin === "null") {
return false; // non-HTTP url
}
} catch (e) {
} catch {
return false;
}
@ -2187,7 +2187,7 @@ class PDFWorker {
}
try {
sendTest();
} catch (e) {
} catch {
// We need fallback to a faked worker.
this._setupFakeWorker();
}
@ -2204,7 +2204,7 @@ class PDFWorker {
// The worker shall process only the first received "test" message.
sendTest();
return;
} catch (e) {
} catch {
info("The worker has been disabled.");
}
}
@ -2305,7 +2305,7 @@ class PDFWorker {
static get _mainThreadWorkerMessageHandler() {
try {
return globalThis.pdfjsWorker?.WorkerMessageHandler || null;
} catch (ex) {
} catch {
return null;
}
}

View file

@ -89,7 +89,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
const buffer = stringToBytes(value);
value = decoder.decode(buffer);
needsEncodingFixup = false;
} catch (e) {
} catch {
// TextDecoder constructor threw - unrecognized encoding.
}
}
@ -207,7 +207,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
} // else encoding is b or B - base64 (RFC 2047 section 4.1)
try {
text = atob(text);
} catch (e) {}
} catch {}
return textdecode(charset, text);
}
);

View file

@ -648,7 +648,7 @@ function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
suggestedFilename = reFilename.exec(
decodeURIComponent(suggestedFilename)
)[0];
} catch (ex) {
} catch {
// Possible (extremely rare) errors:
// URIError "Malformed URI", e.g. for "%AA.pdf"
// TypeError "null has no properties", e.g. for "%2F.pdf"
@ -702,7 +702,7 @@ function isValidFetchUrl(url, baseUrl) {
const { protocol } = baseUrl ? new URL(url, baseUrl) : new URL(url);
// The Fetch API only supports the http/https protocols, and not file/ftp.
return protocol === "http:" || protocol === "https:";
} catch (ex) {
} catch {
return false; // `new URL()` will throw on incorrect data.
}
}

View file

@ -74,7 +74,7 @@ function extractFilenameFromHeader(getResponseHeader) {
if (filename.includes("%")) {
try {
filename = decodeURIComponent(filename);
} catch (ex) {}
} catch {}
}
if (isPdfFile(filename)) {
return filename;

View file

@ -144,7 +144,7 @@ class AForm {
let date = null;
try {
date = this._util.scand(cFormat, cDate);
} catch (error) {}
} catch {}
if (!date) {
date = Date.parse(cDate);
if (isNaN(date)) {

View file

@ -434,7 +434,7 @@ function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
if (options.tryConvertEncoding) {
try {
url = stringToUTF8String(url);
} catch (ex) {}
} catch {}
}
}
@ -442,7 +442,7 @@ function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
if (_isValidProtocol(absoluteUrl)) {
return absoluteUrl;
}
} catch (ex) {
} catch {
/* `new URL()` will throw on incorrect data. */
}
return null;
@ -605,7 +605,7 @@ function isEvalSupported() {
try {
new Function(""); // eslint-disable-line no-new, no-new-func
return true;
} catch (e) {
} catch {
return false;
}
}