Browse Source

PDF.js version 1.0.122

master v1.0.122
Yury Delendik 11 years ago
parent
commit
80669eb24d
  1. 2
      bower.json
  2. 223
      build/pdf.combined.js
  3. 178
      build/pdf.js
  4. 53
      build/pdf.worker.js
  5. 2
      package.json

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.0.119", "version": "1.0.122",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",
"pdf", "pdf",

223
build/pdf.combined.js

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

178
build/pdf.js

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.119'; PDFJS.version = '1.0.122';
PDFJS.build = '693152e'; PDFJS.build = 'aab48a2';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -4122,7 +4122,7 @@ PDFJS.getDocument = function getDocument(source,
pdfDataRangeTransport, pdfDataRangeTransport,
passwordCallback, passwordCallback,
progressCallback) { progressCallback) {
var workerInitializedPromise, workerReadyPromise, transport; var workerInitializedCapability, workerReadyCapability, transport;
if (typeof source === 'string') { if (typeof source === 'string') {
source = { url: source }; source = { url: source };
@ -4147,15 +4147,16 @@ PDFJS.getDocument = function getDocument(source,
params[key] = source[key]; params[key] = source[key];
} }
workerInitializedPromise = new PDFJS.LegacyPromise(); workerInitializedCapability = createPromiseCapability();
workerReadyPromise = new PDFJS.LegacyPromise(); workerReadyCapability = createPromiseCapability();
transport = new WorkerTransport(workerInitializedPromise, workerReadyPromise, transport = new WorkerTransport(workerInitializedCapability,
pdfDataRangeTransport, progressCallback); workerReadyCapability, pdfDataRangeTransport,
workerInitializedPromise.then(function transportInitialized() { progressCallback);
workerInitializedCapability.promise.then(function transportInitialized() {
transport.passwordCallback = passwordCallback; transport.passwordCallback = passwordCallback;
transport.fetchDocument(params); transport.fetchDocument(params);
}); });
return workerReadyPromise; return workerReadyCapability.promise;
}; };
/** /**
@ -4218,10 +4219,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* JavaScript strings in the name tree. * JavaScript strings in the name tree.
*/ */
getJavaScript: function PDFDocumentProxy_getJavaScript() { getJavaScript: function PDFDocumentProxy_getJavaScript() {
var promise = new PDFJS.LegacyPromise(); return new Promise(function (resolve) {
var js = this.pdfInfo.javaScript; var js = this.pdfInfo.javaScript;
promise.resolve(js); resolve(js);
return promise; }.bind(this));
}, },
/** /**
* @return {Promise} A promise that is resolved with an {Array} that is a * @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() { getOutline: function PDFDocumentProxy_getOutline() {
var promise = new PDFJS.LegacyPromise(); return new Promise(function (resolve) {
var outline = this.pdfInfo.outline; var outline = this.pdfInfo.outline;
promise.resolve(outline); resolve(outline);
return promise; }.bind(this));
}, },
/** /**
* @return {Promise} A promise that is resolved with an {Object} that has * @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. * {Metadata} object with information from the metadata section of the PDF.
*/ */
getMetadata: function PDFDocumentProxy_getMetadata() { getMetadata: function PDFDocumentProxy_getMetadata() {
var promise = new PDFJS.LegacyPromise(); return new Promise(function (resolve) {
var info = this.pdfInfo.info; var info = this.pdfInfo.info;
var metadata = this.pdfInfo.metadata; var metadata = this.pdfInfo.metadata;
promise.resolve({ resolve({
info: info, info: info,
metadata: (metadata ? new PDFJS.Metadata(metadata) : null) metadata: (metadata ? new PDFJS.Metadata(metadata) : null)
}); });
return promise; }.bind(this));
}, },
/** /**
* @return {Promise} A promise that is resolved with a TypedArray that has * @return {Promise} A promise that is resolved with a TypedArray that has
* the raw data from the PDF. * the raw data from the PDF.
*/ */
getData: function PDFDocumentProxy_getData() { getData: function PDFDocumentProxy_getData() {
var promise = new PDFJS.LegacyPromise(); var capability = createPromiseCapability();
this.transport.getData(promise); this.transport.getData(capability);
return promise; return capability.promise;
}, },
/** /**
* @return {Promise} A promise that is resolved when the document's data * @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. * property that indicates size of the PDF data in bytes.
*/ */
getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() { 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. * Cleans up resources allocated by the document, e.g. created @font-face.
@ -4402,14 +4403,14 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* annotation objects. * annotation objects.
*/ */
getAnnotations: function PDFPageProxy_getAnnotations() { getAnnotations: function PDFPageProxy_getAnnotations() {
if (this.annotationsPromise) { if (this.annotationsCapability) {
return this.annotationsPromise; return this.annotationsCapability.promise;
} }
var promise = new PDFJS.LegacyPromise(); var capability = createPromiseCapability();
this.annotationsPromise = promise; this.annotationsCapability = capability;
this.transport.getAnnotations(this.pageInfo.pageIndex); this.transport.getAnnotations(this.pageInfo.pageIndex);
return promise; return capability.promise;
}, },
/** /**
* Begins the process of rendering a page to the desired context. * Begins the process of rendering a page to the desired context.
@ -4433,11 +4434,11 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
} }
var intentState = this.intentStates[renderingIntent]; var intentState = this.intentStates[renderingIntent];
// If there is no displayReadyPromise yet, then the operatorList was never // If there's no displayReadyCapability yet, then the operatorList
// requested before. Make the request and create the promise. // was never requested before. Make the request and create the promise.
if (!intentState.displayReadyPromise) { if (!intentState.displayReadyCapability) {
intentState.receivingOperatorList = true; intentState.receivingOperatorList = true;
intentState.displayReadyPromise = new LegacyPromise(); intentState.displayReadyCapability = createPromiseCapability();
intentState.operatorList = { intentState.operatorList = {
fnArray: [], fnArray: [],
argsArray: [], argsArray: [],
@ -4463,7 +4464,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
var renderTask = new RenderTask(internalRenderTask); var renderTask = new RenderTask(internalRenderTask);
var self = this; var self = this;
intentState.displayReadyPromise.then( intentState.displayReadyCapability.promise.then(
function pageDisplayReadyPromise(transparency) { function pageDisplayReadyPromise(transparency) {
if (self.pendingDestroy) { if (self.pendingDestroy) {
complete(); complete();
@ -4490,9 +4491,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
self._tryDestroy(); self._tryDestroy();
if (error) { if (error) {
renderTask.promise.reject(error); internalRenderTask.capability.reject(error);
} else { } else {
renderTask.promise.resolve(); internalRenderTask.capability.resolve();
} }
stats.timeEnd('Rendering'); stats.timeEnd('Rendering');
stats.timeEnd('Overall'); stats.timeEnd('Overall');
@ -4505,15 +4506,15 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* object that represent the page text content. * object that represent the page text content.
*/ */
getTextContent: function PDFPageProxy_getTextContent() { getTextContent: function PDFPageProxy_getTextContent() {
var promise = new PDFJS.LegacyPromise(); return new Promise(function (resolve) {
this.transport.messageHandler.send('GetTextContent', { this.transport.messageHandler.send('GetTextContent', {
pageIndex: this.pageNumber - 1 pageIndex: this.pageNumber - 1
}, },
function textContentCallback(textContent) { function textContentCallback(textContent) {
promise.resolve(textContent); resolve(textContent);
} }
); );
return promise; }.bind(this));
}, },
/** /**
* Destroys resources allocated by the page. * Destroys resources allocated by the page.
@ -4550,7 +4551,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
_startRenderPage: function PDFPageProxy_startRenderPage(transparency, _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
intent) { intent) {
var intentState = this.intentStates[intent]; var intentState = this.intentStates[intent];
intentState.displayReadyPromise.resolve(transparency); intentState.displayReadyCapability.resolve(transparency);
}, },
/** /**
* For internal use only. * For internal use only.
@ -4587,17 +4588,17 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @ignore * @ignore
*/ */
var WorkerTransport = (function WorkerTransportClosure() { var WorkerTransport = (function WorkerTransportClosure() {
function WorkerTransport(workerInitializedPromise, workerReadyPromise, function WorkerTransport(workerInitializedCapability, workerReadyCapability,
pdfDataRangeTransport, progressCallback) { pdfDataRangeTransport, progressCallback) {
this.pdfDataRangeTransport = pdfDataRangeTransport; this.pdfDataRangeTransport = pdfDataRangeTransport;
this.workerReadyPromise = workerReadyPromise; this.workerReadyCapability = workerReadyCapability;
this.progressCallback = progressCallback; this.progressCallback = progressCallback;
this.commonObjs = new PDFObjects(); this.commonObjs = new PDFObjects();
this.pageCache = []; this.pageCache = [];
this.pagePromises = []; this.pageCapabilities = [];
this.downloadInfoPromise = new PDFJS.LegacyPromise(); this.downloadInfoCapability = createPromiseCapability();
this.passwordCallback = null; this.passwordCallback = null;
// If worker support isn't disabled explicit and the browser has worker // If worker support isn't disabled explicit and the browser has worker
@ -4626,12 +4627,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
PDFJS.postMessageTransfers = false; PDFJS.postMessageTransfers = false;
} }
this.setupMessageHandler(messageHandler); this.setupMessageHandler(messageHandler);
workerInitializedPromise.resolve(); workerInitializedCapability.resolve();
} else { } else {
globalScope.PDFJS.disableWorker = true; globalScope.PDFJS.disableWorker = true;
this.loadFakeWorkerFiles().then(function() { this.loadFakeWorkerFiles().then(function() {
this.setupFakeWorker(); this.setupFakeWorker();
workerInitializedPromise.resolve(); workerInitializedCapability.resolve();
}.bind(this)); }.bind(this));
} }
}.bind(this)); }.bind(this));
@ -4656,13 +4657,13 @@ var WorkerTransport = (function WorkerTransportClosure() {
globalScope.PDFJS.disableWorker = true; globalScope.PDFJS.disableWorker = true;
this.loadFakeWorkerFiles().then(function() { this.loadFakeWorkerFiles().then(function() {
this.setupFakeWorker(); this.setupFakeWorker();
workerInitializedPromise.resolve(); workerInitializedCapability.resolve();
}.bind(this)); }.bind(this));
} }
WorkerTransport.prototype = { WorkerTransport.prototype = {
destroy: function WorkerTransport_destroy() { destroy: function WorkerTransport_destroy() {
this.pageCache = []; this.pageCache = [];
this.pagePromises = []; this.pageCapabilities = [];
var self = this; var self = this;
this.messageHandler.send('Terminate', null, function () { this.messageHandler.send('Terminate', null, function () {
FontLoader.clear(); FontLoader.clear();
@ -4673,16 +4674,16 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, },
loadFakeWorkerFiles: function WorkerTransport_loadFakeWorkerFiles() { loadFakeWorkerFiles: function WorkerTransport_loadFakeWorkerFiles() {
if (!PDFJS.fakeWorkerFilesLoadedPromise) { if (!PDFJS.fakeWorkerFilesLoadedCapability) {
PDFJS.fakeWorkerFilesLoadedPromise = new LegacyPromise(); PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
// In the developer build load worker_loader which in turn loads all the // In the developer build load worker_loader which in turn loads all the
// other files and resolves the promise. In production only the // other files and resolves the promise. In production only the
// pdf.worker.js file is needed. // pdf.worker.js file is needed.
Util.loadScript(PDFJS.workerSrc, function() { Util.loadScript(PDFJS.workerSrc, function() {
PDFJS.fakeWorkerFilesLoadedPromise.resolve(); PDFJS.fakeWorkerFilesLoadedCapability.resolve();
}); });
} }
return PDFJS.fakeWorkerFilesLoadedPromise; return PDFJS.fakeWorkerFilesLoadedCapability.promise;
}, },
setupFakeWorker: function WorkerTransport_setupFakeWorker() { setupFakeWorker: function WorkerTransport_setupFakeWorker() {
@ -4737,7 +4738,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.numPages = data.pdfInfo.numPages; this.numPages = data.pdfInfo.numPages;
var pdfDocument = new PDFDocumentProxy(pdfInfo, this); var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
this.pdfDocument = pdfDocument; this.pdfDocument = pdfDocument;
this.workerReadyPromise.resolve(pdfDocument); this.workerReadyCapability.resolve(pdfDocument);
}, this); }, this);
messageHandler.on('NeedPassword', function transportPassword(data) { messageHandler.on('NeedPassword', function transportPassword(data) {
@ -4745,7 +4746,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
return this.passwordCallback(updatePassword, return this.passwordCallback(updatePassword,
PasswordResponses.NEED_PASSWORD); PasswordResponses.NEED_PASSWORD);
} }
this.workerReadyPromise.reject(data.exception.message, data.exception); this.workerReadyCapability.reject(data.exception.message,
data.exception);
}, this); }, this);
messageHandler.on('IncorrectPassword', function transportBadPass(data) { messageHandler.on('IncorrectPassword', function transportBadPass(data) {
@ -4753,36 +4755,39 @@ var WorkerTransport = (function WorkerTransportClosure() {
return this.passwordCallback(updatePassword, return this.passwordCallback(updatePassword,
PasswordResponses.INCORRECT_PASSWORD); PasswordResponses.INCORRECT_PASSWORD);
} }
this.workerReadyPromise.reject(data.exception.message, data.exception); this.workerReadyCapability.reject(data.exception.message,
data.exception);
}, this); }, this);
messageHandler.on('InvalidPDF', function transportInvalidPDF(data) { messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
this.workerReadyPromise.reject(data.exception.name, data.exception); this.workerReadyCapability.reject(data.exception.name, data.exception);
}, this); }, this);
messageHandler.on('MissingPDF', function transportMissingPDF(data) { messageHandler.on('MissingPDF', function transportMissingPDF(data) {
this.workerReadyPromise.reject(data.exception.message, data.exception); this.workerReadyCapability.reject(data.exception.message,
data.exception);
}, this); }, this);
messageHandler.on('UnknownError', function transportUnknownError(data) { messageHandler.on('UnknownError', function transportUnknownError(data) {
this.workerReadyPromise.reject(data.exception.message, data.exception); this.workerReadyCapability.reject(data.exception.message,
data.exception);
}, this); }, this);
messageHandler.on('DataLoaded', function transportPage(data) { messageHandler.on('DataLoaded', function transportPage(data) {
this.downloadInfoPromise.resolve(data); this.downloadInfoCapability.resolve(data);
}, this); }, this);
messageHandler.on('GetPage', function transportPage(data) { messageHandler.on('GetPage', function transportPage(data) {
var pageInfo = data.pageInfo; var pageInfo = data.pageInfo;
var page = new PDFPageProxy(pageInfo, this); var page = new PDFPageProxy(pageInfo, this);
this.pageCache[pageInfo.pageIndex] = page; this.pageCache[pageInfo.pageIndex] = page;
var promise = this.pagePromises[pageInfo.pageIndex]; var promise = this.pageCapabilities[pageInfo.pageIndex];
promise.resolve(page); promise.resolve(page);
}, this); }, this);
messageHandler.on('GetAnnotations', function transportAnnotations(data) { messageHandler.on('GetAnnotations', function transportAnnotations(data) {
var annotations = data.annotations; var annotations = data.annotations;
var promise = this.pageCache[data.pageIndex].annotationsPromise; var promise = this.pageCache[data.pageIndex].annotationsCapability;
promise.resolve(annotations); promise.resolve(annotations);
}, this); }, this);
@ -4876,14 +4881,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, this); }, this);
messageHandler.on('DocError', function transportDocError(data) { messageHandler.on('DocError', function transportDocError(data) {
this.workerReadyPromise.reject(data); this.workerReadyCapability.reject(data);
}, this); }, this);
messageHandler.on('PageError', function transportError(data, intent) { messageHandler.on('PageError', function transportError(data, intent) {
var page = this.pageCache[data.pageNum - 1]; var page = this.pageCache[data.pageNum - 1];
var intentState = page.intentStates[intent]; var intentState = page.intentStates[intent];
if (intentState.displayReadyPromise) { if (intentState.displayReadyCapability.promise) {
intentState.displayReadyPromise.reject(data.error); intentState.displayReadyCapability.reject(data.error);
} else { } else {
error(data.error); error(data.error);
} }
@ -4941,38 +4946,36 @@ var WorkerTransport = (function WorkerTransportClosure() {
}); });
}, },
getData: function WorkerTransport_getData(promise) { getData: function WorkerTransport_getData(capability) {
this.messageHandler.send('GetData', null, function(data) { 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 || if (pageNumber <= 0 || pageNumber > this.numPages ||
(pageNumber|0) !== pageNumber) { (pageNumber|0) !== pageNumber) {
var pagePromise = new PDFJS.LegacyPromise(); return new Promise.reject(new Error('Invalid page request'));
pagePromise.reject(new Error('Invalid page request'));
return pagePromise;
} }
var pageIndex = pageNumber - 1; var pageIndex = pageNumber - 1;
if (pageIndex in this.pagePromises) { if (pageIndex in this.pageCapabilities) {
return this.pagePromises[pageIndex]; return this.pageCapabilities[pageIndex].promise;
} }
promise = new PDFJS.LegacyPromise(); capability = createPromiseCapability();
this.pagePromises[pageIndex] = promise; this.pageCapabilities[pageIndex] = capability;
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex });
return promise; return capability.promise;
}, },
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) { getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
var promise = new PDFJS.LegacyPromise(); return new Promise(function (resolve) {
this.messageHandler.send('GetPageIndex', { ref: ref }, this.messageHandler.send('GetPageIndex', { ref: ref },
function (pageIndex) { function (pageIndex) {
promise.resolve(pageIndex); resolve(pageIndex);
} }
); );
return promise; }.bind(this));
}, },
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) { getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
@ -4981,23 +4984,23 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, },
getDestinations: function WorkerTransport_getDestinations() { getDestinations: function WorkerTransport_getDestinations() {
var promise = new PDFJS.LegacyPromise(); return new Promise(function (resolve) {
this.messageHandler.send('GetDestinations', null, this.messageHandler.send('GetDestinations', null,
function transportDestinations(destinations) { function transportDestinations(destinations) {
promise.resolve(destinations); resolve(destinations);
} }
); );
return promise; }.bind(this));
}, },
getAttachments: function WorkerTransport_getAttachments() { getAttachments: function WorkerTransport_getAttachments() {
var promise = new PDFJS.LegacyPromise(); return new Promise(function (resolve) {
this.messageHandler.send('GetAttachments', null, this.messageHandler.send('GetAttachments', null,
function transportAttachments(attachments) { function transportAttachments(attachments) {
promise.resolve(attachments); resolve(attachments);
} }
); );
return promise; }.bind(this));
}, },
startCleanup: function WorkerTransport_startCleanup() { startCleanup: function WorkerTransport_startCleanup() {
@ -5042,7 +5045,7 @@ var PDFObjects = (function PDFObjectsClosure() {
} }
var obj = { var obj = {
promise: new LegacyPromise(), capability: createPromiseCapability(),
data: null, data: null,
resolved: false resolved: false
}; };
@ -5064,7 +5067,7 @@ var PDFObjects = (function PDFObjectsClosure() {
// If there is a callback, then the get can be async and the object is // If there is a callback, then the get can be async and the object is
// not required to be resolved right now // not required to be resolved right now
if (callback) { if (callback) {
this.ensureObj(objId).promise.then(callback); this.ensureObj(objId).capability.promise.then(callback);
return null; return null;
} }
@ -5089,7 +5092,7 @@ var PDFObjects = (function PDFObjectsClosure() {
obj.resolved = true; obj.resolved = true;
obj.data = data; obj.data = data;
obj.promise.resolve(data); obj.capability.resolve(data);
}, },
isResolved: function PDFObjects_isResolved(objId) { isResolved: function PDFObjects_isResolved(objId) {
@ -5136,7 +5139,7 @@ var RenderTask = (function RenderTaskClosure() {
* Promise for rendering task completion. * Promise for rendering task completion.
* @type {Promise} * @type {Promise}
*/ */
this.promise = new PDFJS.LegacyPromise(); this.promise = this.internalRenderTask.capability.promise;
} }
RenderTask.prototype = /** @lends RenderTask.prototype */ { RenderTask.prototype = /** @lends RenderTask.prototype */ {
@ -5147,7 +5150,6 @@ var RenderTask = (function RenderTaskClosure() {
*/ */
cancel: function RenderTask_cancel() { cancel: function RenderTask_cancel() {
this.internalRenderTask.cancel(); this.internalRenderTask.cancel();
this.promise.reject(new Error('Rendering is cancelled'));
}, },
/** /**
@ -5185,6 +5187,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
this.graphicsReadyCallback = null; this.graphicsReadyCallback = null;
this.graphicsReady = false; this.graphicsReady = false;
this.cancelled = false; this.cancelled = false;
this.capability = createPromiseCapability();
} }
InternalRenderTask.prototype = { InternalRenderTask.prototype = {
@ -5217,6 +5220,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
cancel: function InternalRenderTask_cancel() { cancel: function InternalRenderTask_cancel() {
this.running = false; this.running = false;
this.cancelled = true; this.cancelled = true;
this.capability.reject(new Error('Rendering is cancelled'));
this.callback('cancelled'); this.callback('cancelled');
}, },

53
build/pdf.worker.js vendored

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.119'; PDFJS.version = '1.0.122';
PDFJS.build = '693152e'; PDFJS.build = 'aab48a2';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -5481,33 +5481,26 @@ var Dict = (function DictClosure() {
// Same as get(), but returns a promise and uses fetchIfRefAsync(). // Same as get(), but returns a promise and uses fetchIfRefAsync().
getAsync: function Dict_getAsync(key1, key2, key3) { getAsync: function Dict_getAsync(key1, key2, key3) {
var value; var value;
var promise;
var xref = this.xref; var xref = this.xref;
if (typeof (value = this.map[key1]) !== undefined || key1 in this.map || if (typeof (value = this.map[key1]) !== undefined || key1 in this.map ||
typeof key2 === undefined) { typeof key2 === undefined) {
if (xref) { if (xref) {
return xref.fetchIfRefAsync(value); return xref.fetchIfRefAsync(value);
} }
promise = new LegacyPromise(); return Promise.resolve(value);
promise.resolve(value);
return promise;
} }
if (typeof (value = this.map[key2]) !== undefined || key2 in this.map || if (typeof (value = this.map[key2]) !== undefined || key2 in this.map ||
typeof key3 === undefined) { typeof key3 === undefined) {
if (xref) { if (xref) {
return xref.fetchIfRefAsync(value); return xref.fetchIfRefAsync(value);
} }
promise = new LegacyPromise(); return Promise.resolve(value);
promise.resolve(value);
return promise;
} }
value = this.map[key3] || null; value = this.map[key3] || null;
if (xref) { if (xref) {
return xref.fetchIfRefAsync(value); return xref.fetchIfRefAsync(value);
} }
promise = new LegacyPromise(); return Promise.resolve(value);
promise.resolve(value);
return promise;
}, },
// no dereferencing // no dereferencing
@ -5904,7 +5897,7 @@ var Catalog = (function CatalogClosure() {
}, },
getPageDict: function Catalog_getPageDict(pageIndex) { getPageDict: function Catalog_getPageDict(pageIndex) {
var promise = new LegacyPromise(); var capability = createPromiseCapability();
var nodesToVisit = [this.catDict.getRaw('Pages')]; var nodesToVisit = [this.catDict.getRaw('Pages')];
var currentPageIndex = 0; var currentPageIndex = 0;
var xref = this.xref; var xref = this.xref;
@ -5917,7 +5910,7 @@ var Catalog = (function CatalogClosure() {
xref.fetchAsync(currentNode).then(function (obj) { xref.fetchAsync(currentNode).then(function (obj) {
if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) { if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
if (pageIndex === currentPageIndex) { if (pageIndex === currentPageIndex) {
promise.resolve([obj, currentNode]); capability.resolve([obj, currentNode]);
} else { } else {
currentPageIndex++; currentPageIndex++;
next(); next();
@ -5926,7 +5919,7 @@ var Catalog = (function CatalogClosure() {
} }
nodesToVisit.push(obj); nodesToVisit.push(obj);
next(); next();
}.bind(this), promise.reject.bind(promise)); }.bind(this), capability.reject.bind(capability));
return; return;
} }
@ -5961,10 +5954,10 @@ var Catalog = (function CatalogClosure() {
} }
} }
} }
promise.reject('Page index ' + pageIndex + ' not found.'); capability.reject('Page index ' + pageIndex + ' not found.');
} }
next(); next();
return promise; return capability.promise;
}, },
getPageIndex: function Catalog_getPageIndex(ref) { getPageIndex: function Catalog_getPageIndex(ref) {
@ -6622,28 +6615,26 @@ var XRef = (function XRefClosure() {
fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) { fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
if (!isRef(obj)) { if (!isRef(obj)) {
var promise = new LegacyPromise(); return Promise.resolve(obj);
promise.resolve(obj);
return promise;
} }
return this.fetchAsync(obj); return this.fetchAsync(obj);
}, },
fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) { fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
var promise = new LegacyPromise(); return new Promise(function (resolve, reject) {
var tryFetch = function (promise) { var tryFetch = function () {
try { try {
promise.resolve(this.fetch(ref, suppressEncryption)); resolve(this.fetch(ref, suppressEncryption));
} catch (e) { } catch (e) {
if (e instanceof MissingDataException) { if (e instanceof MissingDataException) {
this.stream.manager.requestRange(e.begin, e.end, tryFetch); this.stream.manager.requestRange(e.begin, e.end, tryFetch);
return; return;
} }
promise.reject(e); reject(e);
} }
}.bind(this, promise); }.bind(this);
tryFetch(); tryFetch();
return promise; }.bind(this));
}, },
getCatalogObj: function XRef_getCatalogObj() { getCatalogObj: function XRef_getCatalogObj() {
@ -6849,12 +6840,12 @@ var ObjectLoader = (function() {
ObjectLoader.prototype = { ObjectLoader.prototype = {
load: function ObjectLoader_load() { load: function ObjectLoader_load() {
var keys = this.keys; var keys = this.keys;
this.promise = new LegacyPromise(); this.capability = createPromiseCapability();
// Don't walk the graph if all the data is already loaded. // Don't walk the graph if all the data is already loaded.
if (!(this.xref.stream instanceof ChunkedStream) || if (!(this.xref.stream instanceof ChunkedStream) ||
this.xref.stream.getMissingChunks().length === 0) { this.xref.stream.getMissingChunks().length === 0) {
this.promise.resolve(); this.capability.resolve();
return this.promise; return this.capability.promise;
} }
this.refSet = new RefSet(); this.refSet = new RefSet();
@ -6865,7 +6856,7 @@ var ObjectLoader = (function() {
} }
this.walk(nodesToVisit); this.walk(nodesToVisit);
return this.promise; return this.capability.promise;
}, },
walk: function ObjectLoader_walk(nodesToVisit) { walk: function ObjectLoader_walk(nodesToVisit) {
@ -6932,7 +6923,7 @@ var ObjectLoader = (function() {
} }
// Everything is loaded. // Everything is loaded.
this.refSet = null; this.refSet = null;
this.promise.resolve(); this.capability.resolve();
} }
}; };

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.0.119", "version": "1.0.122",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",

Loading…
Cancel
Save