Convert a couple of fields/methods into properly private ones in PDFPageProxy

These were always intended to be *private*, so let's use modern JS features to actually enforce that.
This commit is contained in:
Jonas Jenwald 2023-03-04 09:42:32 +01:00
parent a0ef5a4ae1
commit e7a7f02f4c

View File

@ -1262,6 +1262,8 @@ class PDFDocumentProxy {
* Proxy to a `PDFPage` in the worker thread. * Proxy to a `PDFPage` in the worker thread.
*/ */
class PDFPageProxy { class PDFPageProxy {
#pendingCleanup = false;
constructor(pageIndex, pageInfo, transport, pdfBug = false) { constructor(pageIndex, pageInfo, transport, pdfBug = false) {
this._pageIndex = pageIndex; this._pageIndex = pageIndex;
this._pageInfo = pageInfo; this._pageInfo = pageInfo;
@ -1273,7 +1275,6 @@ class PDFPageProxy {
this.objs = new PDFObjects(); this.objs = new PDFObjects();
this.cleanupAfterRender = false; this.cleanupAfterRender = false;
this.pendingCleanup = false;
this._intentStates = new Map(); this._intentStates = new Map();
this.destroyed = false; this.destroyed = false;
} }
@ -1414,7 +1415,7 @@ class PDFPageProxy {
); );
// If there was a pending destroy, cancel it so no cleanup happens during // If there was a pending destroy, cancel it so no cleanup happens during
// this call to render. // this call to render.
this.pendingCleanup = false; this.#pendingCleanup = false;
if (!optionalContentConfigPromise) { if (!optionalContentConfigPromise) {
optionalContentConfigPromise = this._transport.getOptionalContentConfig(); optionalContentConfigPromise = this._transport.getOptionalContentConfig();
@ -1457,9 +1458,9 @@ class PDFPageProxy {
// Attempt to reduce memory usage during *printing*, by always running // Attempt to reduce memory usage during *printing*, by always running
// cleanup once rendering has finished (regardless of cleanupAfterRender). // cleanup once rendering has finished (regardless of cleanupAfterRender).
if (this.cleanupAfterRender || intentPrint) { if (this.cleanupAfterRender || intentPrint) {
this.pendingCleanup = true; this.#pendingCleanup = true;
} }
this._tryCleanup(); this.#tryCleanup();
if (error) { if (error) {
internalRenderTask.capability.reject(error); internalRenderTask.capability.reject(error);
@ -1509,7 +1510,7 @@ class PDFPageProxy {
{ transparency, isOffscreenCanvasSupported }, { transparency, isOffscreenCanvasSupported },
optionalContentConfig, optionalContentConfig,
]) => { ]) => {
if (this.pendingCleanup) { if (this.#pendingCleanup) {
complete(); complete();
return; return;
} }
@ -1681,7 +1682,7 @@ class PDFPageProxy {
} }
} }
this.objs.clear(); this.objs.clear();
this.pendingCleanup = false; this.#pendingCleanup = false;
return Promise.all(waitOn); return Promise.all(waitOn);
} }
@ -1693,16 +1694,15 @@ class PDFPageProxy {
* @returns {boolean} Indicates if clean-up was successfully run. * @returns {boolean} Indicates if clean-up was successfully run.
*/ */
cleanup(resetStats = false) { cleanup(resetStats = false) {
this.pendingCleanup = true; this.#pendingCleanup = true;
return this._tryCleanup(resetStats); return this.#tryCleanup(resetStats);
} }
/** /**
* Attempts to clean up if rendering is in a state where that's possible. * Attempts to clean up if rendering is in a state where that's possible.
* @private
*/ */
_tryCleanup(resetStats = false) { #tryCleanup(resetStats = false) {
if (!this.pendingCleanup) { if (!this.#pendingCleanup) {
return false; return false;
} }
for (const { renderTasks, operatorList } of this._intentStates.values()) { for (const { renderTasks, operatorList } of this._intentStates.values()) {
@ -1716,7 +1716,7 @@ class PDFPageProxy {
if (resetStats && this._stats) { if (resetStats && this._stats) {
this._stats = new StatTimer(); this._stats = new StatTimer();
} }
this.pendingCleanup = false; this.#pendingCleanup = false;
return true; return true;
} }
@ -1756,7 +1756,7 @@ class PDFPageProxy {
} }
if (operatorListChunk.lastChunk) { if (operatorListChunk.lastChunk) {
this._tryCleanup(); this.#tryCleanup();
} }
} }
@ -1814,7 +1814,7 @@ class PDFPageProxy {
for (const internalRenderTask of intentState.renderTasks) { for (const internalRenderTask of intentState.renderTasks) {
internalRenderTask.operatorListChanged(); internalRenderTask.operatorListChanged();
} }
this._tryCleanup(); this.#tryCleanup();
} }
if (intentState.displayReadyCapability) { if (intentState.displayReadyCapability) {