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

@ -14,7 +14,7 @@
*/
import { arrayBuffersToBytes, MissingDataException } from "./core_utils.js";
import { assert, createPromiseCapability } from "../shared/util.js";
import { assert, PromiseCapability } from "../shared/util.js";
import { Stream } from "./stream.js";
class ChunkedStream extends Stream {
@ -275,7 +275,7 @@ class ChunkedStreamManager {
this.progressiveDataLength = 0;
this.aborted = false;
this._loadedStreamCapability = createPromiseCapability();
this._loadedStreamCapability = new PromiseCapability();
}
sendRequest(begin, end) {
@ -349,7 +349,7 @@ class ChunkedStreamManager {
return Promise.resolve();
}
const capability = createPromiseCapability();
const capability = new PromiseCapability();
this._promisesByRequest.set(requestId, capability);
const chunksToRequest = [];

View File

@ -18,7 +18,6 @@ import {
AbortException,
assert,
CMapCompressionType,
createPromiseCapability,
FONT_IDENTITY_MATRIX,
FormatError,
IDENTITY_MATRIX,
@ -26,6 +25,7 @@ import {
isArrayEqual,
normalizeUnicode,
OPS,
PromiseCapability,
shadow,
stringToPDFString,
TextRenderingMode,
@ -1253,7 +1253,7 @@ class PartialEvaluator {
return this.fontCache.get(font.cacheKey);
}
const fontCapability = createPromiseCapability();
const fontCapability = new PromiseCapability();
let preEvaluatedFont;
try {

View File

@ -16,12 +16,12 @@
import {
AbortException,
assert,
createPromiseCapability,
getVerbosityLevel,
info,
InvalidPDFException,
MissingPDFException,
PasswordException,
PromiseCapability,
setVerbosityLevel,
stringToPDFString,
UnexpectedResponseException,
@ -46,7 +46,7 @@ class WorkerTask {
constructor(name) {
this.name = name;
this.terminated = false;
this._capability = createPromiseCapability();
this._capability = new PromiseCapability();
}
get finished() {
@ -228,7 +228,7 @@ class WorkerMessageHandler {
password,
rangeChunkSize,
};
const pdfManagerCapability = createPromiseCapability();
const pdfManagerCapability = new PromiseCapability();
let newPdfManager;
if (data) {

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);

View File

@ -16,7 +16,7 @@
import {
AbortException,
assert,
createPromiseCapability,
PromiseCapability,
warn,
} from "../shared/util.js";
import {
@ -118,7 +118,7 @@ class PDFFetchStreamReader {
const source = stream.source;
this._withCredentials = source.withCredentials || false;
this._contentLength = source.length;
this._headersCapability = createPromiseCapability();
this._headersCapability = new PromiseCapability();
this._disableRange = source.disableRange || false;
this._rangeChunkSize = source.rangeChunkSize;
if (!this._rangeChunkSize && !this._disableRange) {
@ -224,7 +224,7 @@ class PDFFetchStreamRangeReader {
this._loaded = 0;
const source = stream.source;
this._withCredentials = source.withCredentials || false;
this._readCapability = createPromiseCapability();
this._readCapability = new PromiseCapability();
this._isStreamingSupported = !source.disableStream;
this._abortController = new AbortController();

View File

@ -13,11 +13,7 @@
* limitations under the License.
*/
import {
assert,
createPromiseCapability,
stringToBytes,
} from "../shared/util.js";
import { assert, PromiseCapability, stringToBytes } from "../shared/util.js";
import {
createResponseStatusError,
extractFilenameFromHeader,
@ -259,7 +255,7 @@ class PDFNetworkStreamFullRequestReader {
};
this._url = source.url;
this._fullRequestId = manager.requestFull(args);
this._headersReceivedCapability = createPromiseCapability();
this._headersReceivedCapability = new PromiseCapability();
this._disableRange = source.disableRange || false;
this._contentLength = source.length; // Optional
this._rangeChunkSize = source.rangeChunkSize;
@ -380,7 +376,7 @@ class PDFNetworkStreamFullRequestReader {
if (this._done) {
return { value: undefined, done: true };
}
const requestCapability = createPromiseCapability();
const requestCapability = new PromiseCapability();
this._requests.push(requestCapability);
return requestCapability.promise;
}
@ -471,7 +467,7 @@ class PDFNetworkStreamRangeRequestReader {
if (this._done) {
return { value: undefined, done: true };
}
const requestCapability = createPromiseCapability();
const requestCapability = new PromiseCapability();
this._requests.push(requestCapability);
return requestCapability.promise;
}

View File

@ -17,8 +17,8 @@
import {
AbortException,
assert,
createPromiseCapability,
MissingPDFException,
PromiseCapability,
} from "../shared/util.js";
import {
extractFilenameFromHeader,
@ -124,8 +124,8 @@ class BaseFullReader {
this._isRangeSupported = !source.disableRange;
this._readableStream = null;
this._readCapability = createPromiseCapability();
this._headersCapability = createPromiseCapability();
this._readCapability = new PromiseCapability();
this._headersCapability = new PromiseCapability();
}
get headersReady() {
@ -159,7 +159,7 @@ class BaseFullReader {
const chunk = this._readableStream.read();
if (chunk === null) {
this._readCapability = createPromiseCapability();
this._readCapability = new PromiseCapability();
return this.read();
}
this._loaded += chunk.length;
@ -226,7 +226,7 @@ class BaseRangeReader {
this.onProgress = null;
this._loaded = 0;
this._readableStream = null;
this._readCapability = createPromiseCapability();
this._readCapability = new PromiseCapability();
const source = stream.source;
this._isStreamingSupported = !source.disableStream;
}
@ -246,7 +246,7 @@ class BaseRangeReader {
const chunk = this._readableStream.read();
if (chunk === null) {
this._readCapability = createPromiseCapability();
this._readCapability = new PromiseCapability();
return this.read();
}
this._loaded += chunk.length;

View File

@ -18,8 +18,8 @@
import {
AbortException,
createPromiseCapability,
FeatureTest,
PromiseCapability,
Util,
} from "../shared/util.js";
import { deprecated, setLayerDimensions } from "./display_utils.js";
@ -317,7 +317,7 @@ class TextLayerRenderTask {
this._reader = null;
this._textDivProperties = textDivProperties || new WeakMap();
this._canceled = false;
this._capability = createPromiseCapability();
this._capability = new PromiseCapability();
this._layoutTextParams = {
prevFontSize: null,
prevFontFamily: null,
@ -417,7 +417,7 @@ class TextLayerRenderTask {
* @private
*/
_render() {
const capability = createPromiseCapability();
const capability = new PromiseCapability();
let styleCache = Object.create(null);
if (this._isReadableStream) {

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { assert, createPromiseCapability } from "../shared/util.js";
import { assert, PromiseCapability } from "../shared/util.js";
import { isPdfFile } from "./display_utils.js";
/** @implements {IPDFStream} */
@ -235,7 +235,7 @@ class PDFDataTransportStreamReader {
if (this._done) {
return { value: undefined, done: true };
}
const requestCapability = createPromiseCapability();
const requestCapability = new PromiseCapability();
this._requests.push(requestCapability);
return requestCapability.promise;
}
@ -300,7 +300,7 @@ class PDFDataTransportStreamRangeReader {
if (this._done) {
return { value: undefined, done: true };
}
const requestCapability = createPromiseCapability();
const requestCapability = new PromiseCapability();
this._requests.push(requestCapability);
return requestCapability.promise;
}

View File

@ -30,7 +30,6 @@ import {
AnnotationEditorType,
AnnotationMode,
CMapCompressionType,
createPromiseCapability,
createValidAbsoluteUrl,
FeatureTest,
InvalidPDFException,
@ -39,6 +38,7 @@ import {
OPS,
PasswordResponses,
PermissionFlag,
PromiseCapability,
shadow,
UnexpectedResponseException,
Util,
@ -88,7 +88,6 @@ export {
AnnotationMode,
build,
CMapCompressionType,
createPromiseCapability,
createValidAbsoluteUrl,
FeatureTest,
getDocument,
@ -109,6 +108,7 @@ export {
PDFWorker,
PermissionFlag,
PixelsPerInch,
PromiseCapability,
RenderingCancelledException,
renderTextLayer,
setLayerDimensions,

View File

@ -16,9 +16,9 @@
import {
AbortException,
assert,
createPromiseCapability,
MissingPDFException,
PasswordException,
PromiseCapability,
UnexpectedResponseException,
UnknownErrorException,
unreachable,
@ -190,7 +190,7 @@ class MessageHandler {
*/
sendWithPromise(actionName, data, transfers) {
const callbackId = this.callbackId++;
const capability = createPromiseCapability();
const capability = new PromiseCapability();
this.callbackCapabilities[callbackId] = capability;
try {
this.comObj.postMessage(
@ -228,7 +228,7 @@ class MessageHandler {
return new ReadableStream(
{
start: controller => {
const startCapability = createPromiseCapability();
const startCapability = new PromiseCapability();
this.streamControllers[streamId] = {
controller,
startCall: startCapability,
@ -252,7 +252,7 @@ class MessageHandler {
},
pull: controller => {
const pullCapability = createPromiseCapability();
const pullCapability = new PromiseCapability();
this.streamControllers[streamId].pullCall = pullCapability;
comObj.postMessage({
sourceName,
@ -268,7 +268,7 @@ class MessageHandler {
cancel: reason => {
assert(reason instanceof Error, "cancel must have a valid reason");
const cancelCapability = createPromiseCapability();
const cancelCapability = new PromiseCapability();
this.streamControllers[streamId].cancelCall = cancelCapability;
this.streamControllers[streamId].isClosed = true;
comObj.postMessage({
@ -305,7 +305,7 @@ class MessageHandler {
// so when it changes from positive to negative,
// set ready as unresolved promise.
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
this.sinkCapability = createPromiseCapability();
this.sinkCapability = new PromiseCapability();
this.ready = this.sinkCapability.promise;
}
comObj.postMessage(
@ -349,7 +349,7 @@ class MessageHandler {
});
},
sinkCapability: createPromiseCapability(),
sinkCapability: new PromiseCapability(),
onPull: null,
onCancel: null,
isCancelled: false,

View File

@ -975,42 +975,41 @@ function getModificationDate(date = new Date()) {
return buffer.join("");
}
/**
* Promise Capability object.
*
* @typedef {Object} PromiseCapability
* @property {Promise<any>} promise - A Promise object.
* @property {boolean} settled - If the Promise has been fulfilled/rejected.
* @property {function} resolve - Fulfills the Promise.
* @property {function} reject - Rejects the Promise.
*/
class PromiseCapability {
#settled = false;
/**
* Creates a promise capability object.
* @alias createPromiseCapability
*
* @returns {PromiseCapability}
*/
function createPromiseCapability() {
const capability = Object.create(null);
let isSettled = false;
constructor() {
/**
* @type {Promise<any>} The Promise object.
*/
this.promise = new Promise((resolve, reject) => {
/**
* @type {function} Fulfills the Promise.
*/
this.resolve = data => {
this.#settled = true;
resolve(data);
};
Object.defineProperty(capability, "settled", {
get() {
return isSettled;
},
});
capability.promise = new Promise(function (resolve, reject) {
capability.resolve = function (data) {
isSettled = true;
resolve(data);
};
capability.reject = function (reason) {
isSettled = true;
reject(reason);
};
});
return capability;
/**
* @type {function} Rejects the Promise.
*/
this.reject = reason => {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
assert(reason instanceof Error, 'Expected valid "reason" argument.');
}
this.#settled = true;
reject(reason);
};
});
}
/**
* @type {boolean} If the Promise has been fulfilled/rejected.
*/
get settled() {
return this.#settled;
}
}
let NormalizeRegex = null;
@ -1052,7 +1051,6 @@ export {
BASELINE_FACTOR,
bytesToString,
CMapCompressionType,
createPromiseCapability,
createValidAbsoluteUrl,
DocumentActionEventType,
FeatureTest,
@ -1078,6 +1076,7 @@ export {
PasswordException,
PasswordResponses,
PermissionFlag,
PromiseCapability,
RenderingIntentFlag,
setVerbosityLevel,
shadow,

View File

@ -17,10 +17,10 @@
const {
AnnotationLayer,
AnnotationMode,
createPromiseCapability,
getDocument,
GlobalWorkerOptions,
PixelsPerInch,
PromiseCapability,
renderTextLayer,
shadow,
XfaLayer,
@ -922,7 +922,7 @@ class Driver {
}
_send(url, message) {
const capability = createPromiseCapability();
const capability = new PromiseCapability();
this.inflight.textContent = this.inFlightRequests++;
fetch(url, {

View File

@ -17,7 +17,6 @@ import {
AnnotationEditorType,
AnnotationMode,
AnnotationType,
createPromiseCapability,
ImageKind,
InvalidPDFException,
MissingPDFException,
@ -26,6 +25,7 @@ import {
PasswordException,
PasswordResponses,
PermissionFlag,
PromiseCapability,
UnknownErrorException,
} from "../../src/shared/util.js";
import {
@ -137,7 +137,7 @@ describe("api", function () {
const loadingTask = getDocument(basicApiGetDocumentParams);
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
const progressReportedCapability = createPromiseCapability();
const progressReportedCapability = new PromiseCapability();
// Attach the callback that is used to report loading progress;
// similarly to how viewer.js works.
loadingTask.onProgress = function (progressData) {
@ -199,7 +199,7 @@ describe("api", function () {
const loadingTask = getDocument(typedArrayPdf);
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
const progressReportedCapability = createPromiseCapability();
const progressReportedCapability = new PromiseCapability();
loadingTask.onProgress = function (data) {
progressReportedCapability.resolve(data);
};
@ -229,7 +229,7 @@ describe("api", function () {
const loadingTask = getDocument(arrayBufferPdf);
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
const progressReportedCapability = createPromiseCapability();
const progressReportedCapability = new PromiseCapability();
loadingTask.onProgress = function (data) {
progressReportedCapability.resolve(data);
};
@ -291,8 +291,8 @@ describe("api", function () {
const loadingTask = getDocument(buildGetDocumentParams("pr6531_1.pdf"));
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
const passwordNeededCapability = createPromiseCapability();
const passwordIncorrectCapability = createPromiseCapability();
const passwordNeededCapability = new PromiseCapability();
const passwordIncorrectCapability = new PromiseCapability();
// Attach the callback that is used to request a password;
// similarly to how the default viewer handles passwords.
loadingTask.onPassword = function (updatePassword, reason) {

View File

@ -15,7 +15,7 @@
import {
AbortException,
createPromiseCapability,
PromiseCapability,
UnknownErrorException,
} from "../../src/shared/util.js";
import { LoopbackPort } from "../../src/display/api.js";
@ -338,7 +338,7 @@ describe("message_handler", function () {
it("should ignore any pull after close is called", async function () {
let log = "";
const port = new LoopbackPort();
const capability = createPromiseCapability();
const capability = new PromiseCapability();
const messageHandler2 = new MessageHandler("worker", "main", port);
messageHandler2.on("fakeHandler", (data, sink) => {
sink.onPull = function () {

View File

@ -15,10 +15,10 @@
import {
bytesToString,
createPromiseCapability,
createValidAbsoluteUrl,
getModificationDate,
isArrayBuffer,
PromiseCapability,
string32,
stringToBytes,
stringToPDFString,
@ -212,9 +212,9 @@ describe("util", function () {
});
});
describe("createPromiseCapability", function () {
describe("PromiseCapability", function () {
it("should resolve with correct data", async function () {
const promiseCapability = createPromiseCapability();
const promiseCapability = new PromiseCapability();
expect(promiseCapability.settled).toEqual(false);
promiseCapability.resolve({ test: "abc" });
@ -225,7 +225,7 @@ describe("util", function () {
});
it("should reject with correct reason", async function () {
const promiseCapability = createPromiseCapability();
const promiseCapability = new PromiseCapability();
expect(promiseCapability.settled).toEqual(false);
promiseCapability.reject(new Error("reason"));

View File

@ -36,7 +36,6 @@ import {
import {
AnnotationEditorType,
build,
createPromiseCapability,
FeatureTest,
getDocument,
getFilenameFromUrl,
@ -49,6 +48,7 @@ import {
MissingPDFException,
OPS,
PDFWorker,
PromiseCapability,
shadow,
UnexpectedResponseException,
version,
@ -156,7 +156,7 @@ class DefaultExternalServices {
const PDFViewerApplication = {
initialBookmark: document.location.hash.substring(1),
_initializedCapability: createPromiseCapability(),
_initializedCapability: new PromiseCapability(),
appConfig: null,
pdfDocument: null,
pdfLoadingTask: null,

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { createPromiseCapability, PasswordResponses } from "pdfjs-lib";
import { PasswordResponses, PromiseCapability } from "pdfjs-lib";
/**
* @typedef {Object} PasswordPromptOptions
@ -69,7 +69,7 @@ class PasswordPrompt {
if (this.#activeCapability) {
await this.#activeCapability.promise;
}
this.#activeCapability = createPromiseCapability();
this.#activeCapability = new PromiseCapability();
try {
await this.overlayManager.open(this.dialog);

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { createPromiseCapability, getFilenameFromUrl } from "pdfjs-lib";
import { getFilenameFromUrl, PromiseCapability } from "pdfjs-lib";
import { BaseTreeViewer } from "./base_tree_viewer.js";
import { waitOnEventOrTimeout } from "./event_utils.js";
@ -50,7 +50,7 @@ class PDFAttachmentViewer extends BaseTreeViewer {
if (!keepRenderedCapability) {
// The only situation in which the `_renderedCapability` should *not* be
// replaced is when appending FileAttachment annotations.
this._renderedCapability = createPromiseCapability();
this._renderedCapability = new PromiseCapability();
}
this._pendingDispatchEvent = false;
}

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
import { createPromiseCapability, PDFDateString } from "pdfjs-lib";
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
import { PDFDateString, PromiseCapability } from "pdfjs-lib";
const DEFAULT_FIELD_CONTENT = "-";
@ -201,7 +201,7 @@ class PDFDocumentProperties {
this.pdfDocument = null;
this.#fieldData = null;
this._dataAvailableCapability = createPromiseCapability();
this._dataAvailableCapability = new PromiseCapability();
this._currentPageNumber = 1;
this._pagesRotation = 0;
}

View File

@ -19,7 +19,7 @@
import { binarySearchFirstItem, scrollIntoView } from "./ui_utils.js";
import { getCharacterType, getNormalizeWithNFKC } from "./pdf_find_utils.js";
import { createPromiseCapability } from "pdfjs-lib";
import { PromiseCapability } from "pdfjs-lib";
const FindState = {
FOUND: 0,
@ -582,7 +582,7 @@ class PDFFindController {
clearTimeout(this._findTimeout);
this._findTimeout = null;
this._firstPageCapability = createPromiseCapability();
this._firstPageCapability = new PromiseCapability();
}
/**
@ -849,7 +849,7 @@ class PDFFindController {
let promise = Promise.resolve();
const textOptions = { disableNormalization: true };
for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
const extractTextCapability = createPromiseCapability();
const extractTextCapability = new PromiseCapability();
this._extractTextPromises[i] = extractTextCapability.promise;
promise = promise.then(() => {

View File

@ -14,7 +14,7 @@
*/
import { BaseTreeViewer } from "./base_tree_viewer.js";
import { createPromiseCapability } from "pdfjs-lib";
import { PromiseCapability } from "pdfjs-lib";
import { SidebarView } from "./ui_utils.js";
/**
@ -89,7 +89,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
* @private
*/
_dispatchEvent(outlineCount) {
this._currentOutlineItemCapability = createPromiseCapability();
this._currentOutlineItemCapability = new PromiseCapability();
if (
outlineCount === 0 ||
this._pdfDocument?.loadingParams.disableAutoFetch
@ -308,7 +308,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
if (this._pageNumberToDestHashCapability) {
return this._pageNumberToDestHashCapability.promise;
}
this._pageNumberToDestHashCapability = createPromiseCapability();
this._pageNumberToDestHashCapability = new PromiseCapability();
const pageNumberToDestHash = new Map(),
pageNumberNesting = new Map();

View File

@ -16,7 +16,7 @@
/** @typedef {import("./event_utils").EventBus} EventBus */
import { apiPageLayoutToViewerModes, RenderingStates } from "./ui_utils.js";
import { createPromiseCapability, shadow } from "pdfjs-lib";
import { PromiseCapability, shadow } from "pdfjs-lib";
/**
* @typedef {Object} PDFScriptingManagerOptions
@ -357,7 +357,7 @@ class PDFScriptingManager {
visitedPages = this._visitedPages;
if (initialize) {
this._closeCapability = createPromiseCapability();
this._closeCapability = new PromiseCapability();
}
if (!this._closeCapability) {
return; // Scripting isn't fully initialized yet.
@ -443,7 +443,7 @@ class PDFScriptingManager {
* @private
*/
_createScripting() {
this._destroyCapability = createPromiseCapability();
this._destroyCapability = new PromiseCapability();
if (this._scripting) {
throw new Error("_createScripting: Scripting already exists.");

View File

@ -28,9 +28,9 @@ import {
AnnotationEditorType,
AnnotationEditorUIManager,
AnnotationMode,
createPromiseCapability,
PermissionFlag,
PixelsPerInch,
PromiseCapability,
version,
} from "pdfjs-lib";
import {
@ -1025,9 +1025,9 @@ class PDFViewer {
this._location = null;
this._pagesRotation = 0;
this._optionalContentConfigPromise = null;
this._firstPageCapability = createPromiseCapability();
this._onePageRenderedCapability = createPromiseCapability();
this._pagesCapability = createPromiseCapability();
this._firstPageCapability = new PromiseCapability();
this._onePageRenderedCapability = new PromiseCapability();
this._pagesCapability = new PromiseCapability();
this._scrollMode = ScrollMode.VERTICAL;
this._previousScrollMode = ScrollMode.UNKNOWN;
this._spreadMode = SpreadMode.NONE;