Merge pull request #4726 from Snuffleupagus/remove-LegacyPromise-core.js

Remove LegacyPromise in src/core/core.js
This commit is contained in:
Yury Delendik 2014-05-02 17:29:28 -05:00
commit ae92b6f96f

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/* globals assert, calculateMD5, Catalog, Dict, error, info, isArray, /* globals assert, calculateMD5, Catalog, Dict, error, info, isArray,
isArrayBuffer, isName, isStream, isString, LegacyPromise, isArrayBuffer, isName, isStream, isString, createPromiseCapability,
Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer, Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer,
StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef, StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef,
MissingDataException, Promise, Annotation, ObjectLoader, OperatorList MissingDataException, Promise, Annotation, ObjectLoader, OperatorList
@ -141,32 +141,28 @@ var Page = (function PageClosure() {
return stream; return stream;
}, },
loadResources: function(keys) { loadResources: function Page_loadResources(keys) {
if (!this.resourcesPromise) { if (!this.resourcesPromise) {
// TODO: add async getInheritedPageProp and remove this. // TODO: add async getInheritedPageProp and remove this.
this.resourcesPromise = this.pdfManager.ensure(this, 'resources'); this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
} }
var promise = new LegacyPromise(); return this.resourcesPromise.then(function resourceSuccess() {
this.resourcesPromise.then(function resourceSuccess() {
var objectLoader = new ObjectLoader(this.resources.map, var objectLoader = new ObjectLoader(this.resources.map,
keys, keys,
this.xref); this.xref);
objectLoader.load().then(function objectLoaderSuccess() { return objectLoader.load();
promise.resolve();
});
}.bind(this)); }.bind(this));
return promise;
}, },
getOperatorList: function Page_getOperatorList(handler, intent) { getOperatorList: function Page_getOperatorList(handler, intent) {
var self = this; var self = this;
var promise = new LegacyPromise(); var capability = createPromiseCapability();
function reject(e) { function reject(e) {
promise.reject(e); capability.reject(e);
} }
var pageListPromise = new LegacyPromise(); var pageListCapability = createPromiseCapability();
var pdfManager = this.pdfManager; var pdfManager = this.pdfManager;
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
@ -200,17 +196,18 @@ var Page = (function PageClosure() {
intent: intent intent: intent
}); });
partialEvaluator.getOperatorList(contentStream, self.resources, opList); partialEvaluator.getOperatorList(contentStream, self.resources, opList);
pageListPromise.resolve(opList); pageListCapability.resolve(opList);
}); });
var annotationsPromise = pdfManager.ensure(this, 'annotations'); var annotationsPromise = pdfManager.ensure(this, 'annotations');
Promise.all([pageListPromise, annotationsPromise]).then(function(datas) { Promise.all([pageListCapability.promise, annotationsPromise]).then(
function(datas) {
var pageOpList = datas[0]; var pageOpList = datas[0];
var annotations = datas[1]; var annotations = datas[1];
if (annotations.length === 0) { if (annotations.length === 0) {
pageOpList.flush(true); pageOpList.flush(true);
promise.resolve(pageOpList); capability.resolve(pageOpList);
return; return;
} }
@ -218,11 +215,11 @@ var Page = (function PageClosure() {
annotations, pageOpList, pdfManager, partialEvaluator, intent); annotations, pageOpList, pdfManager, partialEvaluator, intent);
annotationsReadyPromise.then(function () { annotationsReadyPromise.then(function () {
pageOpList.flush(true); pageOpList.flush(true);
promise.resolve(pageOpList); capability.resolve(pageOpList);
}, reject); }, reject);
}, reject); }, reject);
return promise; return capability.promise;
}, },
extractTextContent: function Page_extractTextContent() { extractTextContent: function Page_extractTextContent() {