mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-05 06:35:48 +02:00
Merge pull request #21511 from Snuffleupagus/eslint-logical-assignment-operators
Enable the unicorn/logical-assignment-operators ESLint plugin rule
This commit is contained in:
commit
c79b005db7
@ -178,6 +178,11 @@ export default [
|
|||||||
"unicorn/prefer-dom-node-remove": "error",
|
"unicorn/prefer-dom-node-remove": "error",
|
||||||
"unicorn/prefer-import-meta-properties": "error",
|
"unicorn/prefer-import-meta-properties": "error",
|
||||||
"unicorn/prefer-includes": "error",
|
"unicorn/prefer-includes": "error",
|
||||||
|
"unicorn/logical-assignment-operators": [
|
||||||
|
"error",
|
||||||
|
"always",
|
||||||
|
{ enforceForIfStatements: true },
|
||||||
|
],
|
||||||
"unicorn/prefer-logical-operator-over-ternary": "error",
|
"unicorn/prefer-logical-operator-over-ternary": "error",
|
||||||
"unicorn/prefer-modern-dom-apis": "error",
|
"unicorn/prefer-modern-dom-apis": "error",
|
||||||
"unicorn/prefer-modern-math-apis": "error",
|
"unicorn/prefer-modern-math-apis": "error",
|
||||||
|
|||||||
@ -192,7 +192,7 @@ function renderDefaultZoomValue(shortDescription) {
|
|||||||
document.getElementById("settings-boxes").append(wrapper);
|
document.getElementById("settings-boxes").append(wrapper);
|
||||||
|
|
||||||
function renderPreference(value) {
|
function renderPreference(value) {
|
||||||
value = value || "auto";
|
value ||= "auto";
|
||||||
select.value = value;
|
select.value = value;
|
||||||
var customOption = select.querySelector("option.custom-zoom");
|
var customOption = select.querySelector("option.custom-zoom");
|
||||||
if (select.selectedIndex === -1 && value) {
|
if (select.selectedIndex === -1 && value) {
|
||||||
|
|||||||
@ -150,7 +150,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
function didUpdateSinceLastCheck() {
|
function didUpdateSinceLastCheck() {
|
||||||
var chromeVersion = /Chrome\/(\d+)\./.exec(navigator.userAgent);
|
var chromeVersion = /Chrome\/(\d+)\./.exec(navigator.userAgent);
|
||||||
chromeVersion = chromeVersion && chromeVersion[1];
|
chromeVersion &&= chromeVersion[1];
|
||||||
if (!chromeVersion || localStorage.telemetryLastVersion === chromeVersion) {
|
if (!chromeVersion || localStorage.telemetryLastVersion === chromeVersion) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3318,13 +3318,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
return super.getOperatorList(evaluator, task, intent, annotationStorage);
|
return super.getOperatorList(evaluator, task, intent, annotationStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value === null || value === undefined) {
|
// There is no default appearance, `value === null || value === undefined`,
|
||||||
// There is no default appearance so use the one derived
|
// so use the one derived from the field value.
|
||||||
// from the field value.
|
value ??= this.data.checkBox
|
||||||
value = this.data.checkBox
|
? this.data.fieldValue === this.data.exportValue
|
||||||
? this.data.fieldValue === this.data.exportValue
|
: this.data.fieldValue === this.data.buttonValue;
|
||||||
: this.data.fieldValue === this.data.buttonValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.#getOperatorListForAppearance(
|
return this.#getOperatorListForAppearance(
|
||||||
evaluator,
|
evaluator,
|
||||||
@ -4716,9 +4714,7 @@ class PolylineAnnotation extends MarkupAnnotation {
|
|||||||
const strokeAlpha = dict.get("CA");
|
const strokeAlpha = dict.get("CA");
|
||||||
|
|
||||||
let fillColor = getRgbColor(dict.getArray("IC"), null);
|
let fillColor = getRgbColor(dict.getArray("IC"), null);
|
||||||
if (fillColor) {
|
fillColor &&= getPdfColorArray(fillColor);
|
||||||
fillColor = getPdfColorArray(fillColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
let operator;
|
let operator;
|
||||||
if (fillColor) {
|
if (fillColor) {
|
||||||
|
|||||||
@ -58,11 +58,9 @@ class CCITTFaxStream extends DecodeStream {
|
|||||||
if (this.eof) {
|
if (this.eof) {
|
||||||
return this.buffer;
|
return this.buffer;
|
||||||
}
|
}
|
||||||
if (!bytes) {
|
bytes ??= this.stream.isAsync
|
||||||
bytes = this.stream.isAsync
|
? (await this.stream.asyncGetBytes()) || this.bytes
|
||||||
? (await this.stream.asyncGetBytes()) || this.bytes
|
: this.bytes;
|
||||||
: this.bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.buffer = await JBig2CCITTFaxImage.instance.decode(
|
this.buffer = await JBig2CCITTFaxImage.instance.decode(
|
||||||
bytes,
|
bytes,
|
||||||
|
|||||||
@ -775,14 +775,12 @@ class CFFParser {
|
|||||||
} else if (localSubrIndex) {
|
} else if (localSubrIndex) {
|
||||||
localSubrToUse = localSubrIndex;
|
localSubrToUse = localSubrIndex;
|
||||||
}
|
}
|
||||||
if (valid) {
|
valid &&= this.parseCharString(
|
||||||
valid = this.parseCharString(
|
state,
|
||||||
state,
|
charstring,
|
||||||
charstring,
|
localSubrToUse,
|
||||||
localSubrToUse,
|
globalSubrIndex
|
||||||
globalSubrIndex
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
if (state.width !== null) {
|
if (state.width !== null) {
|
||||||
const nominalWidth = privateDictToUse.getByName("nominalWidthX");
|
const nominalWidth = privateDictToUse.getByName("nominalWidthX");
|
||||||
widths[i] = nominalWidth + state.width;
|
widths[i] = nominalWidth + state.width;
|
||||||
|
|||||||
@ -243,9 +243,7 @@ class ColorSpaceUtils {
|
|||||||
break;
|
break;
|
||||||
case "Pattern":
|
case "Pattern":
|
||||||
baseCS = cs[1] || null;
|
baseCS = cs[1] || null;
|
||||||
if (baseCS) {
|
baseCS &&= this.#subParse(baseCS, options);
|
||||||
baseCS = this.#subParse(baseCS, options);
|
|
||||||
}
|
|
||||||
return new PatternCS(baseCS);
|
return new PatternCS(baseCS);
|
||||||
case "I":
|
case "I":
|
||||||
case "Indexed":
|
case "Indexed":
|
||||||
|
|||||||
@ -151,9 +151,8 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
|
|||||||
glyphId = glyphNames.indexOf(glyphName);
|
glyphId = glyphNames.indexOf(glyphName);
|
||||||
|
|
||||||
if (glyphId === -1) {
|
if (glyphId === -1) {
|
||||||
if (!glyphsUnicodeMap) {
|
glyphsUnicodeMap ??= getGlyphsUnicode();
|
||||||
glyphsUnicodeMap = getGlyphsUnicode();
|
|
||||||
}
|
|
||||||
const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
|
const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
|
||||||
if (standardGlyphName !== glyphName) {
|
if (standardGlyphName !== glyphName) {
|
||||||
glyphId = glyphNames.indexOf(standardGlyphName);
|
glyphId = glyphNames.indexOf(standardGlyphName);
|
||||||
|
|||||||
@ -160,11 +160,9 @@ class XFAFactory {
|
|||||||
const { html } = result;
|
const { html } = result;
|
||||||
const { attributes } = html;
|
const { attributes } = html;
|
||||||
if (attributes) {
|
if (attributes) {
|
||||||
if (attributes.class) {
|
attributes.class &&= attributes.class.filter(
|
||||||
attributes.class = attributes.class.filter(
|
attr => !attr.startsWith("xfa")
|
||||||
attr => !attr.startsWith("xfa")
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
attributes.dir = "auto";
|
attributes.dir = "auto";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,9 +31,7 @@ class FontFinder {
|
|||||||
this.addPdfFont(pdfFont);
|
this.addPdfFont(pdfFont);
|
||||||
}
|
}
|
||||||
for (const pdfFont of this.fonts.values()) {
|
for (const pdfFont of this.fonts.values()) {
|
||||||
if (!pdfFont.regular) {
|
pdfFont.regular ||= pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
|
||||||
pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reallyMissingFonts || reallyMissingFonts.size === 0) {
|
if (!reallyMissingFonts || reallyMissingFonts.size === 0) {
|
||||||
@ -72,10 +70,7 @@ class FontFinder {
|
|||||||
property += "italic";
|
property += "italic";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
property ||= "regular";
|
||||||
if (!property) {
|
|
||||||
property = "regular";
|
|
||||||
}
|
|
||||||
|
|
||||||
font[property] = pdfFont;
|
font[property] = pdfFont;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3000,7 +3000,7 @@ class Field extends XFAObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.ui.imageEdit && ui.children?.[0] && this.h) {
|
if (!this.ui.imageEdit && ui.children?.[0] && this.h) {
|
||||||
borderDims = borderDims || getBorderDims(this.ui[$getExtra]());
|
borderDims ||= getBorderDims(this.ui[$getExtra]());
|
||||||
|
|
||||||
let captionHeight = 0;
|
let captionHeight = 0;
|
||||||
if (this.caption && ["top", "bottom"].includes(this.caption.placement)) {
|
if (this.caption && ["top", "bottom"].includes(this.caption.placement)) {
|
||||||
|
|||||||
@ -518,9 +518,7 @@ class XFAObject {
|
|||||||
true /* = dotDotAllowed */,
|
true /* = dotDotAllowed */,
|
||||||
false /* = useCache */
|
false /* = useCache */
|
||||||
);
|
);
|
||||||
if (proto) {
|
proto &&= proto[0];
|
||||||
proto = proto[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!proto) {
|
if (!proto) {
|
||||||
|
|||||||
@ -740,9 +740,7 @@ class XRef {
|
|||||||
if (isCmd(obj, "xref")) {
|
if (isCmd(obj, "xref")) {
|
||||||
// Parse end-of-file XRef
|
// Parse end-of-file XRef
|
||||||
dict = this.processXRefTable(parser);
|
dict = this.processXRefTable(parser);
|
||||||
if (!this.topDict) {
|
this.topDict ||= dict;
|
||||||
this.topDict = dict;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recursively get other XRefs 'XRefStm', if any
|
// Recursively get other XRefs 'XRefStm', if any
|
||||||
obj = dict.get("XRefStm");
|
obj = dict.get("XRefStm");
|
||||||
@ -762,9 +760,8 @@ class XRef {
|
|||||||
throw new FormatError("Invalid XRef stream");
|
throw new FormatError("Invalid XRef stream");
|
||||||
}
|
}
|
||||||
dict = this.processXRefStream(obj);
|
dict = this.processXRefStream(obj);
|
||||||
if (!this.topDict) {
|
this.topDict ||= dict;
|
||||||
this.topDict = dict;
|
|
||||||
}
|
|
||||||
if (!dict) {
|
if (!dict) {
|
||||||
throw new FormatError("Failed to read XRef stream");
|
throw new FormatError("Failed to read XRef stream");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1187,10 +1187,8 @@ class LinkAnnotationElement extends AnnotationElement {
|
|||||||
if (data.overlaidText) {
|
if (data.overlaidText) {
|
||||||
link.title = data.overlaidText;
|
link.title = data.overlaidText;
|
||||||
}
|
}
|
||||||
|
link.onclick ||= () => false;
|
||||||
|
|
||||||
if (!link.onclick) {
|
|
||||||
link.onclick = () => false;
|
|
||||||
}
|
|
||||||
this.#setInternalLink();
|
this.#setInternalLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -488,12 +488,10 @@ class StampEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
copyCanvas(maxDataDimension, maxPreviewDimension, createImageData = false) {
|
copyCanvas(maxDataDimension, maxPreviewDimension, createImageData = false) {
|
||||||
if (!maxDataDimension) {
|
// TODO: get this value from Firefox
|
||||||
// TODO: get this value from Firefox
|
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1908184)
|
||||||
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1908184)
|
// It's the maximum dimension that the AI can handle.
|
||||||
// It's the maximum dimension that the AI can handle.
|
maxDataDimension ||= 224;
|
||||||
maxDataDimension = 224;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { width: bitmapWidth, height: bitmapHeight } = this.#bitmap;
|
const { width: bitmapWidth, height: bitmapHeight } = this.#bitmap;
|
||||||
const outputScale = new OutputScale();
|
const outputScale = new OutputScale();
|
||||||
|
|||||||
@ -334,17 +334,11 @@ class Field extends PDFObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buttonGetCaption(nFace = 0) {
|
buttonGetCaption(nFace = 0) {
|
||||||
if (this._buttonCaption) {
|
return this._buttonCaption ? this._buttonCaption[nFace] : "";
|
||||||
return this._buttonCaption[nFace];
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonGetIcon(nFace = 0) {
|
buttonGetIcon(nFace = 0) {
|
||||||
if (this._buttonIcon) {
|
return this._buttonIcon ? this._buttonIcon[nFace] : null;
|
||||||
return this._buttonIcon[nFace];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonImportIcon(cPath = null, nPave = 0) {
|
buttonImportIcon(cPath = null, nPave = 0) {
|
||||||
@ -352,9 +346,7 @@ class Field extends PDFObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buttonSetCaption(cCaption, nFace = 0) {
|
buttonSetCaption(cCaption, nFace = 0) {
|
||||||
if (!this._buttonCaption) {
|
this._buttonCaption ??= ["", "", ""];
|
||||||
this._buttonCaption = ["", "", ""];
|
|
||||||
}
|
|
||||||
this._buttonCaption[nFace] = cCaption;
|
this._buttonCaption[nFace] = cCaption;
|
||||||
// TODO: send to the annotation layer
|
// TODO: send to the annotation layer
|
||||||
// Right now the button is drawn on the canvas using its appearance so
|
// Right now the button is drawn on the canvas using its appearance so
|
||||||
@ -363,9 +355,7 @@ class Field extends PDFObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buttonSetIcon(oIcon, nFace = 0) {
|
buttonSetIcon(oIcon, nFace = 0) {
|
||||||
if (!this._buttonIcon) {
|
this._buttonIcon ??= [null, null, null];
|
||||||
this._buttonIcon = [null, null, null];
|
|
||||||
}
|
|
||||||
this._buttonIcon[nFace] = oIcon;
|
this._buttonIcon[nFace] = oIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -119,9 +119,7 @@ class Util extends PDFObject {
|
|||||||
}
|
}
|
||||||
cFlags = flags;
|
cFlags = flags;
|
||||||
|
|
||||||
if (nWidth) {
|
nWidth &&= parseInt(nWidth);
|
||||||
nWidth = parseInt(nWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
let intPart = Math.trunc(arg);
|
let intPart = Math.trunc(arg);
|
||||||
|
|
||||||
@ -136,9 +134,7 @@ class Util extends PDFObject {
|
|||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nPrecision) {
|
nPrecision &&= parseInt(nPrecision.substring(1));
|
||||||
nPrecision = parseInt(nPrecision.substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
nDecSep = nDecSep ? nDecSep.substring(1) : "0";
|
nDecSep = nDecSep ? nDecSep.substring(1) : "0";
|
||||||
const separators = {
|
const separators = {
|
||||||
|
|||||||
@ -968,9 +968,7 @@ class Driver {
|
|||||||
if (task.type === "other" || task.enableXfa) {
|
if (task.type === "other" || task.enableXfa) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!task._prefetchedLoadingTask) {
|
task._prefetchedLoadingTask ??= getDocument(this._getDocumentOptions(task));
|
||||||
task._prefetchedLoadingTask = getDocument(this._getDocumentOptions(task));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanup() {
|
_cleanup() {
|
||||||
|
|||||||
@ -801,9 +801,8 @@ async function handleWsBinaryResult(data) {
|
|||||||
if (!taskResults) {
|
if (!taskResults) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!taskResults[round]) {
|
taskResults[round] ||= [];
|
||||||
taskResults[round] = [];
|
|
||||||
}
|
|
||||||
if (taskResults[round][page - 1]) {
|
if (taskResults[round][page - 1]) {
|
||||||
console.error(
|
console.error(
|
||||||
`Results for ${browser}:${id}:${round}:${page - 1} were already submitted`
|
`Results for ${browser}:${id}:${round}:${page - 1} were already submitted`
|
||||||
@ -1010,9 +1009,7 @@ async function startBrowser({
|
|||||||
protocolTimeout: 0.75 * /* jasmine.DEFAULT_TIMEOUT_INTERVAL = */ 30000,
|
protocolTimeout: 0.75 * /* jasmine.DEFAULT_TIMEOUT_INTERVAL = */ 30000,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!tempDir) {
|
tempDir ||= fs.mkdtempSync(path.join(os.tmpdir(), "pdfjs-"));
|
||||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pdfjs-"));
|
|
||||||
}
|
|
||||||
const printFile = path.join(tempDir, "print.pdf");
|
const printFile = path.join(tempDir, "print.pdf");
|
||||||
|
|
||||||
if (browserName === "chrome") {
|
if (browserName === "chrome") {
|
||||||
|
|||||||
@ -2068,11 +2068,9 @@ const PDFViewerApplication = {
|
|||||||
);
|
);
|
||||||
this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
|
this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
|
||||||
|
|
||||||
if (!this.pdfViewer.currentScaleValue) {
|
// Scale was not initialized: invalid bookmark or scale was not specified.
|
||||||
// Scale was not initialized: invalid bookmark or scale was not specified.
|
// Setting the default one.
|
||||||
// Setting the default one.
|
this.pdfViewer.currentScaleValue ||= DEFAULT_SCALE_VALUE;
|
||||||
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -272,11 +272,10 @@ let port;
|
|||||||
// 4. Page: Invoke callback.
|
// 4. Page: Invoke callback.
|
||||||
function setReferer(url, callback) {
|
function setReferer(url, callback) {
|
||||||
dnrRequestId ??= crypto.getRandomValues(new Uint32Array(1))[0] % 0x80000000;
|
dnrRequestId ??= crypto.getRandomValues(new Uint32Array(1))[0] % 0x80000000;
|
||||||
if (!port) {
|
// The background page will accept the port, and keep adding the Referer
|
||||||
// The background page will accept the port, and keep adding the Referer
|
// request header to requests to |url| until the port is disconnected.
|
||||||
// request header to requests to |url| until the port is disconnected.
|
port ??= chrome.runtime.connect({ name: "chromecom-referrer" });
|
||||||
port = chrome.runtime.connect({ name: "chromecom-referrer" });
|
|
||||||
}
|
|
||||||
port.onDisconnect.addListener(onDisconnect);
|
port.onDisconnect.addListener(onDisconnect);
|
||||||
port.onMessage.addListener(onMessage);
|
port.onMessage.addListener(onMessage);
|
||||||
// Initiate the information exchange.
|
// Initiate the information exchange.
|
||||||
|
|||||||
@ -1854,9 +1854,7 @@ class PDFThumbnailViewer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!nextThumbnail) {
|
nextThumbnail ??= firstWithDifferentY;
|
||||||
nextThumbnail = firstWithDifferentY;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (nextThumbnail) {
|
if (nextThumbnail) {
|
||||||
this.#focusThumbnailElement(nextThumbnail, navigateCheckboxes);
|
this.#focusThumbnailElement(nextThumbnail, navigateCheckboxes);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user