Remove the closure used with the InternalRenderTask class

This patch utilizes the same approach as used in lots of other parts of the code-base, which thus *slightly* reduces the size of this code.
This commit is contained in:
Jonas Jenwald 2021-07-28 11:58:08 +02:00
parent b18620ac0f
commit 4c679d80ac

View File

@ -3063,11 +3063,11 @@ class RenderTask {
* For internal use only. * For internal use only.
* @ignore * @ignore
*/ */
const InternalRenderTask = (function InternalRenderTaskClosure() {
const canvasInRendering = new WeakSet();
// eslint-disable-next-line no-shadow
class InternalRenderTask { class InternalRenderTask {
static get canvasInUse() {
return shadow(this, "canvasInUse", new WeakSet());
}
constructor({ constructor({
callback, callback,
params, params,
@ -3117,14 +3117,14 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
return; return;
} }
if (this._canvas) { if (this._canvas) {
if (canvasInRendering.has(this._canvas)) { if (InternalRenderTask.canvasInUse.has(this._canvas)) {
throw new Error( throw new Error(
"Cannot use the same canvas during multiple render() operations. " + "Cannot use the same canvas during multiple render() operations. " +
"Use different canvas or ensure previous operations were " + "Use different canvas or ensure previous operations were " +
"cancelled or completed." "cancelled or completed."
); );
} }
canvasInRendering.add(this._canvas); InternalRenderTask.canvasInUse.add(this._canvas);
} }
if (this._pdfBug && globalThis.StepperManager?.enabled) { if (this._pdfBug && globalThis.StepperManager?.enabled) {
@ -3163,7 +3163,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
this.gfx.endDrawing(); this.gfx.endDrawing();
} }
if (this._canvas) { if (this._canvas) {
canvasInRendering.delete(this._canvas); InternalRenderTask.canvasInUse.delete(this._canvas);
} }
this.callback( this.callback(
error || error ||
@ -3229,15 +3229,13 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
if (this.operatorList.lastChunk) { if (this.operatorList.lastChunk) {
this.gfx.endDrawing(); this.gfx.endDrawing();
if (this._canvas) { if (this._canvas) {
canvasInRendering.delete(this._canvas); InternalRenderTask.canvasInUse.delete(this._canvas);
} }
this.callback(); this.callback();
} }
} }
} }
} }
return InternalRenderTask;
})();
/** @type {string} */ /** @type {string} */
const version = const version =