|
@@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
|
|
|
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
|
|
}
|
|
|
|
|
|
-PDFJS.version = '1.0.119';
|
|
|
-PDFJS.build = '693152e';
|
|
|
+PDFJS.version = '1.0.122';
|
|
|
+PDFJS.build = 'aab48a2';
|
|
|
|
|
|
(function pdfjsWrapper() {
|
|
|
// Use strict in our context only - users might not want it
|
|
@@ -4122,7 +4122,7 @@ PDFJS.getDocument = function getDocument(source,
|
|
|
pdfDataRangeTransport,
|
|
|
passwordCallback,
|
|
|
progressCallback) {
|
|
|
- var workerInitializedPromise, workerReadyPromise, transport;
|
|
|
+ var workerInitializedCapability, workerReadyCapability, transport;
|
|
|
|
|
|
if (typeof source === 'string') {
|
|
|
source = { url: source };
|
|
@@ -4147,15 +4147,16 @@ PDFJS.getDocument = function getDocument(source,
|
|
|
params[key] = source[key];
|
|
|
}
|
|
|
|
|
|
- workerInitializedPromise = new PDFJS.LegacyPromise();
|
|
|
- workerReadyPromise = new PDFJS.LegacyPromise();
|
|
|
- transport = new WorkerTransport(workerInitializedPromise, workerReadyPromise,
|
|
|
- pdfDataRangeTransport, progressCallback);
|
|
|
- workerInitializedPromise.then(function transportInitialized() {
|
|
|
+ workerInitializedCapability = createPromiseCapability();
|
|
|
+ workerReadyCapability = createPromiseCapability();
|
|
|
+ transport = new WorkerTransport(workerInitializedCapability,
|
|
|
+ workerReadyCapability, pdfDataRangeTransport,
|
|
|
+ progressCallback);
|
|
|
+ workerInitializedCapability.promise.then(function transportInitialized() {
|
|
|
transport.passwordCallback = passwordCallback;
|
|
|
transport.fetchDocument(params);
|
|
|
});
|
|
|
- return workerReadyPromise;
|
|
|
+ return workerReadyCapability.promise;
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -4218,10 +4219,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|
|
* JavaScript strings in the name tree.
|
|
|
*/
|
|
|
getJavaScript: function PDFDocumentProxy_getJavaScript() {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- var js = this.pdfInfo.javaScript;
|
|
|
- promise.resolve(js);
|
|
|
- return promise;
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ var js = this.pdfInfo.javaScript;
|
|
|
+ resolve(js);
|
|
|
+ }.bind(this));
|
|
|
},
|
|
|
/**
|
|
|
* @return {Promise} A promise that is resolved with an {Array} that is a
|
|
@@ -4239,10 +4240,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|
|
* ].
|
|
|
*/
|
|
|
getOutline: function PDFDocumentProxy_getOutline() {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- var outline = this.pdfInfo.outline;
|
|
|
- promise.resolve(outline);
|
|
|
- return promise;
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ var outline = this.pdfInfo.outline;
|
|
|
+ resolve(outline);
|
|
|
+ }.bind(this));
|
|
|
},
|
|
|
/**
|
|
|
* @return {Promise} A promise that is resolved with an {Object} that has
|
|
@@ -4251,23 +4252,23 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|
|
* {Metadata} object with information from the metadata section of the PDF.
|
|
|
*/
|
|
|
getMetadata: function PDFDocumentProxy_getMetadata() {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- var info = this.pdfInfo.info;
|
|
|
- var metadata = this.pdfInfo.metadata;
|
|
|
- promise.resolve({
|
|
|
- info: info,
|
|
|
- metadata: (metadata ? new PDFJS.Metadata(metadata) : null)
|
|
|
- });
|
|
|
- return promise;
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ var info = this.pdfInfo.info;
|
|
|
+ var metadata = this.pdfInfo.metadata;
|
|
|
+ resolve({
|
|
|
+ info: info,
|
|
|
+ metadata: (metadata ? new PDFJS.Metadata(metadata) : null)
|
|
|
+ });
|
|
|
+ }.bind(this));
|
|
|
},
|
|
|
/**
|
|
|
* @return {Promise} A promise that is resolved with a TypedArray that has
|
|
|
* the raw data from the PDF.
|
|
|
*/
|
|
|
getData: function PDFDocumentProxy_getData() {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- this.transport.getData(promise);
|
|
|
- return promise;
|
|
|
+ var capability = createPromiseCapability();
|
|
|
+ this.transport.getData(capability);
|
|
|
+ return capability.promise;
|
|
|
},
|
|
|
/**
|
|
|
* @return {Promise} A promise that is resolved when the document's data
|
|
@@ -4275,7 +4276,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|
|
* property that indicates size of the PDF data in bytes.
|
|
|
*/
|
|
|
getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
|
|
|
- return this.transport.downloadInfoPromise;
|
|
|
+ return this.transport.downloadInfoCapability.promise;
|
|
|
},
|
|
|
/**
|
|
|
* Cleans up resources allocated by the document, e.g. created @font-face.
|
|
@@ -4402,14 +4403,14 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
* annotation objects.
|
|
|
*/
|
|
|
getAnnotations: function PDFPageProxy_getAnnotations() {
|
|
|
- if (this.annotationsPromise) {
|
|
|
- return this.annotationsPromise;
|
|
|
+ if (this.annotationsCapability) {
|
|
|
+ return this.annotationsCapability.promise;
|
|
|
}
|
|
|
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- this.annotationsPromise = promise;
|
|
|
+ var capability = createPromiseCapability();
|
|
|
+ this.annotationsCapability = capability;
|
|
|
this.transport.getAnnotations(this.pageInfo.pageIndex);
|
|
|
- return promise;
|
|
|
+ return capability.promise;
|
|
|
},
|
|
|
/**
|
|
|
* Begins the process of rendering a page to the desired context.
|
|
@@ -4433,11 +4434,11 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
}
|
|
|
var intentState = this.intentStates[renderingIntent];
|
|
|
|
|
|
- // If there is no displayReadyPromise yet, then the operatorList was never
|
|
|
- // requested before. Make the request and create the promise.
|
|
|
- if (!intentState.displayReadyPromise) {
|
|
|
+ // If there's no displayReadyCapability yet, then the operatorList
|
|
|
+ // was never requested before. Make the request and create the promise.
|
|
|
+ if (!intentState.displayReadyCapability) {
|
|
|
intentState.receivingOperatorList = true;
|
|
|
- intentState.displayReadyPromise = new LegacyPromise();
|
|
|
+ intentState.displayReadyCapability = createPromiseCapability();
|
|
|
intentState.operatorList = {
|
|
|
fnArray: [],
|
|
|
argsArray: [],
|
|
@@ -4463,7 +4464,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
var renderTask = new RenderTask(internalRenderTask);
|
|
|
|
|
|
var self = this;
|
|
|
- intentState.displayReadyPromise.then(
|
|
|
+ intentState.displayReadyCapability.promise.then(
|
|
|
function pageDisplayReadyPromise(transparency) {
|
|
|
if (self.pendingDestroy) {
|
|
|
complete();
|
|
@@ -4490,9 +4491,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
self._tryDestroy();
|
|
|
|
|
|
if (error) {
|
|
|
- renderTask.promise.reject(error);
|
|
|
+ internalRenderTask.capability.reject(error);
|
|
|
} else {
|
|
|
- renderTask.promise.resolve();
|
|
|
+ internalRenderTask.capability.resolve();
|
|
|
}
|
|
|
stats.timeEnd('Rendering');
|
|
|
stats.timeEnd('Overall');
|
|
@@ -4505,15 +4506,15 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
* object that represent the page text content.
|
|
|
*/
|
|
|
getTextContent: function PDFPageProxy_getTextContent() {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- this.transport.messageHandler.send('GetTextContent', {
|
|
|
- pageIndex: this.pageNumber - 1
|
|
|
- },
|
|
|
- function textContentCallback(textContent) {
|
|
|
- promise.resolve(textContent);
|
|
|
- }
|
|
|
- );
|
|
|
- return promise;
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ this.transport.messageHandler.send('GetTextContent', {
|
|
|
+ pageIndex: this.pageNumber - 1
|
|
|
+ },
|
|
|
+ function textContentCallback(textContent) {
|
|
|
+ resolve(textContent);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }.bind(this));
|
|
|
},
|
|
|
/**
|
|
|
* Destroys resources allocated by the page.
|
|
@@ -4550,7 +4551,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
_startRenderPage: function PDFPageProxy_startRenderPage(transparency,
|
|
|
intent) {
|
|
|
var intentState = this.intentStates[intent];
|
|
|
- intentState.displayReadyPromise.resolve(transparency);
|
|
|
+ intentState.displayReadyCapability.resolve(transparency);
|
|
|
},
|
|
|
/**
|
|
|
* For internal use only.
|
|
@@ -4587,17 +4588,17 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
* @ignore
|
|
|
*/
|
|
|
var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
- function WorkerTransport(workerInitializedPromise, workerReadyPromise,
|
|
|
+ function WorkerTransport(workerInitializedCapability, workerReadyCapability,
|
|
|
pdfDataRangeTransport, progressCallback) {
|
|
|
this.pdfDataRangeTransport = pdfDataRangeTransport;
|
|
|
|
|
|
- this.workerReadyPromise = workerReadyPromise;
|
|
|
+ this.workerReadyCapability = workerReadyCapability;
|
|
|
this.progressCallback = progressCallback;
|
|
|
this.commonObjs = new PDFObjects();
|
|
|
|
|
|
this.pageCache = [];
|
|
|
- this.pagePromises = [];
|
|
|
- this.downloadInfoPromise = new PDFJS.LegacyPromise();
|
|
|
+ this.pageCapabilities = [];
|
|
|
+ this.downloadInfoCapability = createPromiseCapability();
|
|
|
this.passwordCallback = null;
|
|
|
|
|
|
// If worker support isn't disabled explicit and the browser has worker
|
|
@@ -4610,13 +4611,13 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
globalScope.PDFJS.disableWorker = true;
|
|
|
this.loadFakeWorkerFiles().then(function() {
|
|
|
this.setupFakeWorker();
|
|
|
- workerInitializedPromise.resolve();
|
|
|
+ workerInitializedCapability.resolve();
|
|
|
}.bind(this));
|
|
|
}
|
|
|
WorkerTransport.prototype = {
|
|
|
destroy: function WorkerTransport_destroy() {
|
|
|
this.pageCache = [];
|
|
|
- this.pagePromises = [];
|
|
|
+ this.pageCapabilities = [];
|
|
|
var self = this;
|
|
|
this.messageHandler.send('Terminate', null, function () {
|
|
|
FontLoader.clear();
|
|
@@ -4627,14 +4628,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
},
|
|
|
|
|
|
loadFakeWorkerFiles: function WorkerTransport_loadFakeWorkerFiles() {
|
|
|
- if (!PDFJS.fakeWorkerFilesLoadedPromise) {
|
|
|
- PDFJS.fakeWorkerFilesLoadedPromise = new LegacyPromise();
|
|
|
+ if (!PDFJS.fakeWorkerFilesLoadedCapability) {
|
|
|
+ PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
|
|
|
// In the developer build load worker_loader which in turn loads all the
|
|
|
// other files and resolves the promise. In production only the
|
|
|
// pdf.worker.js file is needed.
|
|
|
- PDFJS.fakeWorkerFilesLoadedPromise.resolve();
|
|
|
+ PDFJS.fakeWorkerFilesLoadedCapability.resolve();
|
|
|
}
|
|
|
- return PDFJS.fakeWorkerFilesLoadedPromise;
|
|
|
+ return PDFJS.fakeWorkerFilesLoadedCapability.promise;
|
|
|
},
|
|
|
|
|
|
setupFakeWorker: function WorkerTransport_setupFakeWorker() {
|
|
@@ -4689,7 +4690,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
this.numPages = data.pdfInfo.numPages;
|
|
|
var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
|
|
|
this.pdfDocument = pdfDocument;
|
|
|
- this.workerReadyPromise.resolve(pdfDocument);
|
|
|
+ this.workerReadyCapability.resolve(pdfDocument);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('NeedPassword', function transportPassword(data) {
|
|
@@ -4697,7 +4698,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
return this.passwordCallback(updatePassword,
|
|
|
PasswordResponses.NEED_PASSWORD);
|
|
|
}
|
|
|
- this.workerReadyPromise.reject(data.exception.message, data.exception);
|
|
|
+ this.workerReadyCapability.reject(data.exception.message,
|
|
|
+ data.exception);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('IncorrectPassword', function transportBadPass(data) {
|
|
@@ -4705,36 +4707,39 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
return this.passwordCallback(updatePassword,
|
|
|
PasswordResponses.INCORRECT_PASSWORD);
|
|
|
}
|
|
|
- this.workerReadyPromise.reject(data.exception.message, data.exception);
|
|
|
+ this.workerReadyCapability.reject(data.exception.message,
|
|
|
+ data.exception);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
|
|
|
- this.workerReadyPromise.reject(data.exception.name, data.exception);
|
|
|
+ this.workerReadyCapability.reject(data.exception.name, data.exception);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('MissingPDF', function transportMissingPDF(data) {
|
|
|
- this.workerReadyPromise.reject(data.exception.message, data.exception);
|
|
|
+ this.workerReadyCapability.reject(data.exception.message,
|
|
|
+ data.exception);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('UnknownError', function transportUnknownError(data) {
|
|
|
- this.workerReadyPromise.reject(data.exception.message, data.exception);
|
|
|
+ this.workerReadyCapability.reject(data.exception.message,
|
|
|
+ data.exception);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('DataLoaded', function transportPage(data) {
|
|
|
- this.downloadInfoPromise.resolve(data);
|
|
|
+ this.downloadInfoCapability.resolve(data);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('GetPage', function transportPage(data) {
|
|
|
var pageInfo = data.pageInfo;
|
|
|
var page = new PDFPageProxy(pageInfo, this);
|
|
|
this.pageCache[pageInfo.pageIndex] = page;
|
|
|
- var promise = this.pagePromises[pageInfo.pageIndex];
|
|
|
+ var promise = this.pageCapabilities[pageInfo.pageIndex];
|
|
|
promise.resolve(page);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('GetAnnotations', function transportAnnotations(data) {
|
|
|
var annotations = data.annotations;
|
|
|
- var promise = this.pageCache[data.pageIndex].annotationsPromise;
|
|
|
+ var promise = this.pageCache[data.pageIndex].annotationsCapability;
|
|
|
promise.resolve(annotations);
|
|
|
}, this);
|
|
|
|
|
@@ -4828,14 +4833,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('DocError', function transportDocError(data) {
|
|
|
- this.workerReadyPromise.reject(data);
|
|
|
+ this.workerReadyCapability.reject(data);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('PageError', function transportError(data, intent) {
|
|
|
var page = this.pageCache[data.pageNum - 1];
|
|
|
var intentState = page.intentStates[intent];
|
|
|
- if (intentState.displayReadyPromise) {
|
|
|
- intentState.displayReadyPromise.reject(data.error);
|
|
|
+ if (intentState.displayReadyCapability.promise) {
|
|
|
+ intentState.displayReadyCapability.reject(data.error);
|
|
|
} else {
|
|
|
error(data.error);
|
|
|
}
|
|
@@ -4893,38 +4898,36 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- getData: function WorkerTransport_getData(promise) {
|
|
|
+ getData: function WorkerTransport_getData(capability) {
|
|
|
this.messageHandler.send('GetData', null, function(data) {
|
|
|
- promise.resolve(data);
|
|
|
+ capability.resolve(data);
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- getPage: function WorkerTransport_getPage(pageNumber, promise) {
|
|
|
+ getPage: function WorkerTransport_getPage(pageNumber, capability) {
|
|
|
if (pageNumber <= 0 || pageNumber > this.numPages ||
|
|
|
(pageNumber|0) !== pageNumber) {
|
|
|
- var pagePromise = new PDFJS.LegacyPromise();
|
|
|
- pagePromise.reject(new Error('Invalid page request'));
|
|
|
- return pagePromise;
|
|
|
+ return new Promise.reject(new Error('Invalid page request'));
|
|
|
}
|
|
|
|
|
|
var pageIndex = pageNumber - 1;
|
|
|
- if (pageIndex in this.pagePromises) {
|
|
|
- return this.pagePromises[pageIndex];
|
|
|
+ if (pageIndex in this.pageCapabilities) {
|
|
|
+ return this.pageCapabilities[pageIndex].promise;
|
|
|
}
|
|
|
- promise = new PDFJS.LegacyPromise();
|
|
|
- this.pagePromises[pageIndex] = promise;
|
|
|
+ capability = createPromiseCapability();
|
|
|
+ this.pageCapabilities[pageIndex] = capability;
|
|
|
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex });
|
|
|
- return promise;
|
|
|
+ return capability.promise;
|
|
|
},
|
|
|
|
|
|
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- this.messageHandler.send('GetPageIndex', { ref: ref },
|
|
|
- function (pageIndex) {
|
|
|
- promise.resolve(pageIndex);
|
|
|
- }
|
|
|
- );
|
|
|
- return promise;
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ this.messageHandler.send('GetPageIndex', { ref: ref },
|
|
|
+ function (pageIndex) {
|
|
|
+ resolve(pageIndex);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }.bind(this));
|
|
|
},
|
|
|
|
|
|
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
|
|
@@ -4933,23 +4936,23 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
},
|
|
|
|
|
|
getDestinations: function WorkerTransport_getDestinations() {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- this.messageHandler.send('GetDestinations', null,
|
|
|
- function transportDestinations(destinations) {
|
|
|
- promise.resolve(destinations);
|
|
|
- }
|
|
|
- );
|
|
|
- return promise;
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ this.messageHandler.send('GetDestinations', null,
|
|
|
+ function transportDestinations(destinations) {
|
|
|
+ resolve(destinations);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }.bind(this));
|
|
|
},
|
|
|
|
|
|
getAttachments: function WorkerTransport_getAttachments() {
|
|
|
- var promise = new PDFJS.LegacyPromise();
|
|
|
- this.messageHandler.send('GetAttachments', null,
|
|
|
- function transportAttachments(attachments) {
|
|
|
- promise.resolve(attachments);
|
|
|
- }
|
|
|
- );
|
|
|
- return promise;
|
|
|
+ return new Promise(function (resolve) {
|
|
|
+ this.messageHandler.send('GetAttachments', null,
|
|
|
+ function transportAttachments(attachments) {
|
|
|
+ resolve(attachments);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }.bind(this));
|
|
|
},
|
|
|
|
|
|
startCleanup: function WorkerTransport_startCleanup() {
|
|
@@ -4994,7 +4997,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|
|
}
|
|
|
|
|
|
var obj = {
|
|
|
- promise: new LegacyPromise(),
|
|
|
+ capability: createPromiseCapability(),
|
|
|
data: null,
|
|
|
resolved: false
|
|
|
};
|
|
@@ -5016,7 +5019,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|
|
// If there is a callback, then the get can be async and the object is
|
|
|
// not required to be resolved right now
|
|
|
if (callback) {
|
|
|
- this.ensureObj(objId).promise.then(callback);
|
|
|
+ this.ensureObj(objId).capability.promise.then(callback);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -5041,7 +5044,7 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|
|
|
|
|
obj.resolved = true;
|
|
|
obj.data = data;
|
|
|
- obj.promise.resolve(data);
|
|
|
+ obj.capability.resolve(data);
|
|
|
},
|
|
|
|
|
|
isResolved: function PDFObjects_isResolved(objId) {
|
|
@@ -5088,7 +5091,7 @@ var RenderTask = (function RenderTaskClosure() {
|
|
|
* Promise for rendering task completion.
|
|
|
* @type {Promise}
|
|
|
*/
|
|
|
- this.promise = new PDFJS.LegacyPromise();
|
|
|
+ this.promise = this.internalRenderTask.capability.promise;
|
|
|
}
|
|
|
|
|
|
RenderTask.prototype = /** @lends RenderTask.prototype */ {
|
|
@@ -5099,7 +5102,6 @@ var RenderTask = (function RenderTaskClosure() {
|
|
|
*/
|
|
|
cancel: function RenderTask_cancel() {
|
|
|
this.internalRenderTask.cancel();
|
|
|
- this.promise.reject(new Error('Rendering is cancelled'));
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -5137,6 +5139,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|
|
this.graphicsReadyCallback = null;
|
|
|
this.graphicsReady = false;
|
|
|
this.cancelled = false;
|
|
|
+ this.capability = createPromiseCapability();
|
|
|
}
|
|
|
|
|
|
InternalRenderTask.prototype = {
|
|
@@ -5169,6 +5172,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|
|
cancel: function InternalRenderTask_cancel() {
|
|
|
this.running = false;
|
|
|
this.cancelled = true;
|
|
|
+ this.capability.reject(new Error('Rendering is cancelled'));
|
|
|
this.callback('cancelled');
|
|
|
},
|
|
|
|
|
@@ -10059,33 +10063,26 @@ var Dict = (function DictClosure() {
|
|
|
// Same as get(), but returns a promise and uses fetchIfRefAsync().
|
|
|
getAsync: function Dict_getAsync(key1, key2, key3) {
|
|
|
var value;
|
|
|
- var promise;
|
|
|
var xref = this.xref;
|
|
|
if (typeof (value = this.map[key1]) !== undefined || key1 in this.map ||
|
|
|
typeof key2 === undefined) {
|
|
|
if (xref) {
|
|
|
return xref.fetchIfRefAsync(value);
|
|
|
}
|
|
|
- promise = new LegacyPromise();
|
|
|
- promise.resolve(value);
|
|
|
- return promise;
|
|
|
+ return Promise.resolve(value);
|
|
|
}
|
|
|
if (typeof (value = this.map[key2]) !== undefined || key2 in this.map ||
|
|
|
typeof key3 === undefined) {
|
|
|
if (xref) {
|
|
|
return xref.fetchIfRefAsync(value);
|
|
|
}
|
|
|
- promise = new LegacyPromise();
|
|
|
- promise.resolve(value);
|
|
|
- return promise;
|
|
|
+ return Promise.resolve(value);
|
|
|
}
|
|
|
value = this.map[key3] || null;
|
|
|
if (xref) {
|
|
|
return xref.fetchIfRefAsync(value);
|
|
|
}
|
|
|
- promise = new LegacyPromise();
|
|
|
- promise.resolve(value);
|
|
|
- return promise;
|
|
|
+ return Promise.resolve(value);
|
|
|
},
|
|
|
|
|
|
// no dereferencing
|
|
@@ -10482,7 +10479,7 @@ var Catalog = (function CatalogClosure() {
|
|
|
},
|
|
|
|
|
|
getPageDict: function Catalog_getPageDict(pageIndex) {
|
|
|
- var promise = new LegacyPromise();
|
|
|
+ var capability = createPromiseCapability();
|
|
|
var nodesToVisit = [this.catDict.getRaw('Pages')];
|
|
|
var currentPageIndex = 0;
|
|
|
var xref = this.xref;
|
|
@@ -10495,7 +10492,7 @@ var Catalog = (function CatalogClosure() {
|
|
|
xref.fetchAsync(currentNode).then(function (obj) {
|
|
|
if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
|
|
|
if (pageIndex === currentPageIndex) {
|
|
|
- promise.resolve([obj, currentNode]);
|
|
|
+ capability.resolve([obj, currentNode]);
|
|
|
} else {
|
|
|
currentPageIndex++;
|
|
|
next();
|
|
@@ -10504,7 +10501,7 @@ var Catalog = (function CatalogClosure() {
|
|
|
}
|
|
|
nodesToVisit.push(obj);
|
|
|
next();
|
|
|
- }.bind(this), promise.reject.bind(promise));
|
|
|
+ }.bind(this), capability.reject.bind(capability));
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -10539,10 +10536,10 @@ var Catalog = (function CatalogClosure() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- promise.reject('Page index ' + pageIndex + ' not found.');
|
|
|
+ capability.reject('Page index ' + pageIndex + ' not found.');
|
|
|
}
|
|
|
next();
|
|
|
- return promise;
|
|
|
+ return capability.promise;
|
|
|
},
|
|
|
|
|
|
getPageIndex: function Catalog_getPageIndex(ref) {
|
|
@@ -11200,29 +11197,27 @@ var XRef = (function XRefClosure() {
|
|
|
|
|
|
fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
|
|
|
if (!isRef(obj)) {
|
|
|
- var promise = new LegacyPromise();
|
|
|
- promise.resolve(obj);
|
|
|
- return promise;
|
|
|
+ return Promise.resolve(obj);
|
|
|
}
|
|
|
return this.fetchAsync(obj);
|
|
|
},
|
|
|
|
|
|
fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
|
|
|
- var promise = new LegacyPromise();
|
|
|
- var tryFetch = function (promise) {
|
|
|
- try {
|
|
|
- promise.resolve(this.fetch(ref, suppressEncryption));
|
|
|
- } catch (e) {
|
|
|
- if (e instanceof MissingDataException) {
|
|
|
- this.stream.manager.requestRange(e.begin, e.end, tryFetch);
|
|
|
- return;
|
|
|
- }
|
|
|
- promise.reject(e);
|
|
|
- }
|
|
|
- }.bind(this, promise);
|
|
|
- tryFetch();
|
|
|
- return promise;
|
|
|
- },
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ var tryFetch = function () {
|
|
|
+ try {
|
|
|
+ resolve(this.fetch(ref, suppressEncryption));
|
|
|
+ } catch (e) {
|
|
|
+ if (e instanceof MissingDataException) {
|
|
|
+ this.stream.manager.requestRange(e.begin, e.end, tryFetch);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ reject(e);
|
|
|
+ }
|
|
|
+ }.bind(this);
|
|
|
+ tryFetch();
|
|
|
+ }.bind(this));
|
|
|
+ },
|
|
|
|
|
|
getCatalogObj: function XRef_getCatalogObj() {
|
|
|
return this.root;
|
|
@@ -11427,12 +11422,12 @@ var ObjectLoader = (function() {
|
|
|
ObjectLoader.prototype = {
|
|
|
load: function ObjectLoader_load() {
|
|
|
var keys = this.keys;
|
|
|
- this.promise = new LegacyPromise();
|
|
|
+ this.capability = createPromiseCapability();
|
|
|
// Don't walk the graph if all the data is already loaded.
|
|
|
if (!(this.xref.stream instanceof ChunkedStream) ||
|
|
|
this.xref.stream.getMissingChunks().length === 0) {
|
|
|
- this.promise.resolve();
|
|
|
- return this.promise;
|
|
|
+ this.capability.resolve();
|
|
|
+ return this.capability.promise;
|
|
|
}
|
|
|
|
|
|
this.refSet = new RefSet();
|
|
@@ -11443,7 +11438,7 @@ var ObjectLoader = (function() {
|
|
|
}
|
|
|
|
|
|
this.walk(nodesToVisit);
|
|
|
- return this.promise;
|
|
|
+ return this.capability.promise;
|
|
|
},
|
|
|
|
|
|
walk: function ObjectLoader_walk(nodesToVisit) {
|
|
@@ -11510,7 +11505,7 @@ var ObjectLoader = (function() {
|
|
|
}
|
|
|
// Everything is loaded.
|
|
|
this.refSet = null;
|
|
|
- this.promise.resolve();
|
|
|
+ this.capability.resolve();
|
|
|
}
|
|
|
};
|
|
|
|