Change the createPromiseCapability helper function into a PromiseCapability class

This is not only slightly more compact, but it also simplifies the handling of the `settled` getter.
This commit is contained in:
Jonas Jenwald 2022-03-07 17:41:41 +01:00
parent f9c2a8d437
commit 317abd6d07
24 changed files with 117 additions and 122 deletions

View file

@ -21,7 +21,6 @@ import {
AbortException,
AnnotationMode,
assert,
createPromiseCapability,
getVerbosityLevel,
info,
InvalidPDFException,
@ -29,6 +28,7 @@ import {
MAX_IMAGE_SIZE_TO_CACHE,
MissingPDFException,
PasswordException,
PromiseCapability,
RenderingIntentFlag,
setVerbosityLevel,
shadow,
@ -588,7 +588,7 @@ class PDFDocumentLoadingTask {
static #docId = 0;
constructor() {
this._capability = createPromiseCapability();
this._capability = new PromiseCapability();
this._transport = null;
this._worker = null;
@ -675,7 +675,7 @@ class PDFDataRangeTransport {
this._progressListeners = [];
this._progressiveReadListeners = [];
this._progressiveDoneListeners = [];
this._readyCapability = createPromiseCapability();
this._readyCapability = new PromiseCapability();
}
/**
@ -1460,7 +1460,7 @@ class PDFPageProxy {
// If there's no displayReadyCapability yet, then the operatorList
// was never requested before. Make the request and create the promise.
if (!intentState.displayReadyCapability) {
intentState.displayReadyCapability = createPromiseCapability();
intentState.displayReadyCapability = new PromiseCapability();
intentState.operatorList = {
fnArray: [],
argsArray: [],
@ -1578,7 +1578,7 @@ class PDFPageProxy {
if (!intentState.opListReadCapability) {
opListTask = Object.create(null);
opListTask.operatorListChanged = operatorListChanged;
intentState.opListReadCapability = createPromiseCapability();
intentState.opListReadCapability = new PromiseCapability();
(intentState.renderTasks ||= new Set()).add(opListTask);
intentState.operatorList = {
fnArray: [],
@ -2054,7 +2054,7 @@ class PDFWorker {
this.destroyed = false;
this.verbosity = verbosity;
this._readyCapability = createPromiseCapability();
this._readyCapability = new PromiseCapability();
this._port = null;
this._webWorker = null;
this._messageHandler = null;
@ -2388,7 +2388,7 @@ class WorkerTransport {
this._networkStream = networkStream;
this._fullReader = null;
this._lastProgress = null;
this.downloadInfoCapability = createPromiseCapability();
this.downloadInfoCapability = new PromiseCapability();
this.setupMessageHandler();
@ -2487,7 +2487,7 @@ class WorkerTransport {
}
this.destroyed = true;
this.destroyCapability = createPromiseCapability();
this.destroyCapability = new PromiseCapability();
if (this._passwordCapability) {
this._passwordCapability.reject(
@ -2581,7 +2581,7 @@ class WorkerTransport {
});
messageHandler.on("ReaderHeadersReady", data => {
const headersCapability = createPromiseCapability();
const headersCapability = new PromiseCapability();
const fullReader = this._fullReader;
fullReader.headersReady.then(() => {
// If stream or range are disabled, it's our only way to report
@ -2696,7 +2696,7 @@ class WorkerTransport {
});
messageHandler.on("PasswordRequest", exception => {
this._passwordCapability = createPromiseCapability();
this._passwordCapability = new PromiseCapability();
if (loadingTask.onPassword) {
const updatePassword = password => {
@ -3117,7 +3117,7 @@ class PDFObjects {
return obj;
}
return (this.#objs[objId] = {
capability: createPromiseCapability(),
capability: new PromiseCapability(),
data: null,
});
}
@ -3277,7 +3277,7 @@ class InternalRenderTask {
this._useRequestAnimationFrame =
useRequestAnimationFrame === true && typeof window !== "undefined";
this.cancelled = false;
this.capability = createPromiseCapability();
this.capability = new PromiseCapability();
this.task = new RenderTask(this);
// caching this-bound methods
this._cancelBound = this.cancel.bind(this);