mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 10:15:37 +02:00
Use more optional chaining in the code-base
This patch updates a bunch of older code, that makes conditional function calls, to use optional chaining rather than `if`-blocks. These mostly mechanical changes reduce the size of the `gulp mozcentral` build by a little over 1 kB.
This commit is contained in:
parent
9578152ae4
commit
38ee28b1d3
15 changed files with 51 additions and 119 deletions
|
@ -88,9 +88,8 @@ class PDFFetchStream {
|
|||
}
|
||||
|
||||
cancelAllRequests(reason) {
|
||||
if (this._fullRequestReader) {
|
||||
this._fullRequestReader.cancel(reason);
|
||||
}
|
||||
this._fullRequestReader?.cancel(reason);
|
||||
|
||||
for (const reader of this._rangeRequestReaders.slice(0)) {
|
||||
reader.cancel(reason);
|
||||
}
|
||||
|
@ -202,9 +201,7 @@ class PDFFetchStreamReader {
|
|||
}
|
||||
|
||||
cancel(reason) {
|
||||
if (this._reader) {
|
||||
this._reader.cancel(reason);
|
||||
}
|
||||
this._reader?.cancel(reason);
|
||||
this._abortController.abort();
|
||||
}
|
||||
}
|
||||
|
@ -256,17 +253,14 @@ class PDFFetchStreamRangeReader {
|
|||
return { value, done };
|
||||
}
|
||||
this._loaded += value.byteLength;
|
||||
if (this.onProgress) {
|
||||
this.onProgress({ loaded: this._loaded });
|
||||
}
|
||||
this.onProgress?.({ loaded: this._loaded });
|
||||
|
||||
const buffer = new Uint8Array(value).buffer;
|
||||
return { value: buffer, done: false };
|
||||
}
|
||||
|
||||
cancel(reason) {
|
||||
if (this._reader) {
|
||||
this._reader.cancel(reason);
|
||||
}
|
||||
this._reader?.cancel(reason);
|
||||
this._abortController.abort();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue