Skip to content

Commit

Permalink
Merge pull request mozilla#8357 from Snuffleupagus/core-rm-bind
Browse files Browse the repository at this point in the history
Replace unnecessary `bind(this)` and `var self = this` statements with arrow functions in remaining `src/core/` files
  • Loading branch information
yurydelendik authored May 2, 2017
2 parents b159531 + 0cc022b commit a8ed6d2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 68 deletions.
34 changes: 15 additions & 19 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,17 @@ var Annotation = (function AnnotationClosure() {
},

loadResources: function Annotation_loadResources(keys) {
return new Promise(function (resolve, reject) {
this.appearance.dict.getAsync('Resources').then(function (resources) {
if (!resources) {
resolve();
return;
}
var objectLoader = new ObjectLoader(resources.map,
keys,
resources.xref);
objectLoader.load().then(function() {
resolve(resources);
}, reject);
}, reject);
}.bind(this));
return this.appearance.dict.getAsync('Resources').then((resources) => {
if (!resources) {
return;
}
var objectLoader = new ObjectLoader(resources.map,
keys,
resources.xref);
return objectLoader.load().then(function() {
return resources;
});
});
},

getOperatorList: function Annotation_getOperatorList(evaluator, task,
Expand All @@ -454,15 +451,14 @@ var Annotation = (function AnnotationClosure() {
var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0];
var transform = getTransformMatrix(data.rect, bbox, matrix);
var self = this;

return resourcesPromise.then(function(resources) {
return resourcesPromise.then((resources) => {
var opList = new OperatorList();
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
return evaluator.getOperatorList(self.appearance, task,
resources, opList).then(function () {
return evaluator.getOperatorList(this.appearance, task,
resources, opList).then(() => {
opList.addOp(OPS.endAnnotation, []);
self.appearance.reset();
this.appearance.reset();
return opList;
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/core/chunked_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
};
rangeReader.read().then(readChunk, reject);
});
promise.then(function (data) {
promise.then((data) => {
if (this.aborted) {
return; // ignoring any data after abort
}
this.onReceiveData({ chunk: data, begin, });
}.bind(this));
});
// TODO check errors
},

Expand Down
51 changes: 19 additions & 32 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,15 @@ var Page = (function PageClosure() {
// TODO: add async getInheritedPageProp and remove this.
this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
}
return this.resourcesPromise.then(function resourceSuccess() {
return this.resourcesPromise.then(() => {
var objectLoader = new ObjectLoader(this.resources.map,
keys,
this.xref);
return objectLoader.load();
}.bind(this));
});
},

getOperatorList: function Page_getOperatorList(handler, task, intent,
renderInteractiveForms) {
var self = this;

getOperatorList(handler, task, intent, renderInteractiveForms) {
var pdfManager = this.pdfManager;
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
[]);
Expand All @@ -259,17 +256,16 @@ var Page = (function PageClosure() {
this.evaluatorOptions);

var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
var pageListPromise = dataPromises.then(function(data) {
var contentStream = data[0];
var opList = new OperatorList(intent, handler, self.pageIndex);
var pageListPromise = dataPromises.then(([contentStream]) => {
var opList = new OperatorList(intent, handler, this.pageIndex);

handler.send('StartRenderPage', {
transparency: partialEvaluator.hasBlendModes(self.resources),
pageIndex: self.pageIndex,
transparency: partialEvaluator.hasBlendModes(this.resources),
pageIndex: this.pageIndex,
intent,
});
return partialEvaluator.getOperatorList(contentStream, task,
self.resources, opList).then(function () {
this.resources, opList).then(function () {
return opList;
});
});
Expand All @@ -278,10 +274,7 @@ var Page = (function PageClosure() {
// page's operator list to render them.
var annotationsPromise = pdfManager.ensure(this, 'annotations');
return Promise.all([pageListPromise, annotationsPromise]).then(
function(datas) {
var pageOpList = datas[0];
var annotations = datas[1];

function ([pageOpList, annotations]) {
if (annotations.length === 0) {
pageOpList.flush(true);
return pageOpList;
Expand Down Expand Up @@ -310,11 +303,7 @@ var Page = (function PageClosure() {
});
},

extractTextContent: function Page_extractTextContent(handler, task,
normalizeWhitespace,
combineTextItems) {
var self = this;

extractTextContent(handler, task, normalizeWhitespace, combineTextItems) {
var pdfManager = this.pdfManager;
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
[]);
Expand All @@ -325,20 +314,18 @@ var Page = (function PageClosure() {
'Font'
]);

var dataPromises = Promise.all([contentStreamPromise,
resourcesPromise]);
return dataPromises.then(function(data) {
var contentStream = data[0];
var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
handler, self.pageIndex,
self.idFactory,
self.fontCache,
self.builtInCMapCache,
self.evaluatorOptions);
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
return dataPromises.then(([contentStream]) => {
var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
handler, this.pageIndex,
this.idFactory,
this.fontCache,
this.builtInCMapCache,
this.evaluatorOptions);

return partialEvaluator.getTextContent(contentStream,
task,
self.resources,
this.resources,
/* stateManager = */ null,
normalizeWhitespace,
combineTextItems);
Expand Down
4 changes: 2 additions & 2 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ var Font = (function FontClosure() {
properties.differences);
} else {
glyphsUnicodeMap = getGlyphsUnicode();
this.toUnicode.forEach(function(charCode, unicodeCharCode) {
this.toUnicode.forEach((charCode, unicodeCharCode) => {
if (!this.composite) {
glyphName = (properties.differences[charCode] ||
properties.defaultEncoding[charCode]);
Expand All @@ -643,7 +643,7 @@ var Font = (function FontClosure() {
}
}
this.toFontChar[charCode] = unicodeCharCode;
}.bind(this));
});
}
this.loadedName = fontName.split('-')[0];
this.loading = false;
Expand Down
22 changes: 9 additions & 13 deletions src/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,27 +429,24 @@ var Catalog = (function CatalogClosure() {
this.fontCache.forEach(function (promise) {
promises.push(promise);
});
return Promise.all(promises).then(function (translatedFonts) {
return Promise.all(promises).then((translatedFonts) => {
for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
var font = translatedFonts[i].dict;
delete font.translated;
}
this.fontCache.clear();
this.builtInCMapCache = Object.create(null);
}.bind(this));
});
},

getPage: function Catalog_getPage(pageIndex) {
if (!(pageIndex in this.pagePromises)) {
this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
function (a) {
var dict = a[0];
var ref = a[1];
return this.pageFactory.createPage(pageIndex, dict, ref,
this.fontCache,
this.builtInCMapCache);
}.bind(this)
);
([dict, ref]) => {
return this.pageFactory.createPage(pageIndex, dict, ref,
this.fontCache,
this.builtInCMapCache);
});
}
return this.pagePromises[pageIndex];
},
Expand Down Expand Up @@ -1772,8 +1769,7 @@ var ObjectLoader = (function() {
}

if (pendingRequests.length) {
this.xref.stream.manager.requestRanges(pendingRequests).then(
function pendingRequestCallback() {
this.xref.stream.manager.requestRanges(pendingRequests).then(() => {
nodesToVisit = nodesToRevisit;
for (var i = 0; i < nodesToRevisit.length; i++) {
var node = nodesToRevisit[i];
Expand All @@ -1784,7 +1780,7 @@ var ObjectLoader = (function() {
}
}
this._walk(nodesToVisit);
}.bind(this), this.capability.reject);
}, this.capability.reject);
return;
}
// Everything is loaded.
Expand Down

0 comments on commit a8ed6d2

Please sign in to comment.