Replace some ternary operators with optional chaining, and nullish coalescing, in the src/display/-folder

This way, we can further reduce unnecessary code-repetition in some cases.
This commit is contained in:
Jonas Jenwald 2021-01-19 16:28:47 +01:00
parent 172abc02e1
commit 298ee5cfbb
7 changed files with 8 additions and 14 deletions

View File

@ -2605,7 +2605,7 @@ class WorkerTransport {
.sendWithPromise("SaveDocument", { .sendWithPromise("SaveDocument", {
numPages: this._numPages, numPages: this._numPages,
annotationStorage: annotationStorage?.getAll() || null, annotationStorage: annotationStorage?.getAll() || null,
filename: this._fullReader ? this._fullReader.filename : null, filename: this._fullReader?.filename ?? null,
}) })
.finally(() => { .finally(() => {
if (annotationStorage) { if (annotationStorage) {
@ -2800,7 +2800,7 @@ class PDFObjects {
has(objId) { has(objId) {
const obj = this._objs[objId]; const obj = this._objs[objId];
return obj ? obj.resolved : false; return obj?.resolved || false;
} }
/** /**

View File

@ -1506,10 +1506,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
if (!fontObj) { if (!fontObj) {
throw new Error(`Can't find font for ${fontRefName}`); throw new Error(`Can't find font for ${fontRefName}`);
} }
current.fontMatrix = fontObj.fontMatrix || FONT_IDENTITY_MATRIX;
current.fontMatrix = fontObj.fontMatrix
? fontObj.fontMatrix
: FONT_IDENTITY_MATRIX;
// A valid matrix needs all main diagonal elements to be non-zero // A valid matrix needs all main diagonal elements to be non-zero
// This also ensures we bypass FF bugzilla bug #719844. // This also ensures we bypass FF bugzilla bug #719844.

View File

@ -66,7 +66,7 @@ class PDFFetchStream {
} }
get _progressiveDataLength() { get _progressiveDataLength() {
return this._fullRequestReader ? this._fullRequestReader._loaded : 0; return this._fullRequestReader?._loaded ?? 0;
} }
getFullReader() { getFullReader() {

View File

@ -146,7 +146,7 @@ class Metadata {
} }
get(name) { get(name) {
return this._metadataMap.has(name) ? this._metadataMap.get(name) : null; return this._metadataMap.get(name) ?? null;
} }
getAll() { getAll() {

View File

@ -69,7 +69,7 @@ class PDFNodeStream {
} }
get _progressiveDataLength() { get _progressiveDataLength() {
return this._fullRequestReader ? this._fullRequestReader._loaded : 0; return this._fullRequestReader?._loaded ?? 0;
} }
getFullReader() { getFullReader() {

View File

@ -981,10 +981,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this.addFontStyle(fontObj); this.addFontStyle(fontObj);
this.embeddedFonts[fontObj.loadedName] = fontObj; this.embeddedFonts[fontObj.loadedName] = fontObj;
} }
current.fontMatrix = fontObj.fontMatrix || FONT_IDENTITY_MATRIX;
current.fontMatrix = fontObj.fontMatrix
? fontObj.fontMatrix
: FONT_IDENTITY_MATRIX;
let bold = "normal"; let bold = "normal";
if (fontObj.black) { if (fontObj.black) {

View File

@ -83,7 +83,7 @@ class PDFDataTransportStream {
} }
get _progressiveDataLength() { get _progressiveDataLength() {
return this._fullRequestReader ? this._fullRequestReader._loaded : 0; return this._fullRequestReader?._loaded ?? 0;
} }
_onProgress(evt) { _onProgress(evt) {