Reduce the overall indentation level in Catalog_readDocumentOutline
, by using early returns, in order to improve readability
This commit is contained in:
parent
e9a1a47d28
commit
98db068079
@ -128,26 +128,29 @@ var Catalog = (function CatalogClosure() {
|
|||||||
return shadow(this, 'documentOutline', obj);
|
return shadow(this, 'documentOutline', obj);
|
||||||
},
|
},
|
||||||
readDocumentOutline: function Catalog_readDocumentOutline() {
|
readDocumentOutline: function Catalog_readDocumentOutline() {
|
||||||
var xref = this.xref;
|
|
||||||
var obj = this.catDict.get('Outlines');
|
var obj = this.catDict.get('Outlines');
|
||||||
var root = { items: [] };
|
if (!isDict(obj)) {
|
||||||
if (isDict(obj)) {
|
return null;
|
||||||
|
}
|
||||||
obj = obj.getRaw('First');
|
obj = obj.getRaw('First');
|
||||||
var processed = new RefSet();
|
if (!isRef(obj)) {
|
||||||
if (isRef(obj)) {
|
return null;
|
||||||
|
}
|
||||||
|
var root = { items: [] };
|
||||||
var queue = [{obj: obj, parent: root}];
|
var queue = [{obj: obj, parent: root}];
|
||||||
// to avoid recursion keeping track of the items
|
// To avoid recursion, keep track of the already processed items.
|
||||||
// in the processed dictionary
|
var processed = new RefSet();
|
||||||
processed.put(obj);
|
processed.put(obj);
|
||||||
|
var xref = this.xref;
|
||||||
|
|
||||||
while (queue.length > 0) {
|
while (queue.length > 0) {
|
||||||
var i = queue.shift();
|
var i = queue.shift();
|
||||||
var outlineDict = xref.fetchIfRef(i.obj);
|
var outlineDict = xref.fetchIfRef(i.obj);
|
||||||
if (outlineDict === null) {
|
if (outlineDict === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!outlineDict.has('Title')) {
|
assert(outlineDict.has('Title'), 'Invalid outline item');
|
||||||
error('Invalid outline item');
|
|
||||||
}
|
|
||||||
var actionDict = outlineDict.get('A'), dest = null, url = null;
|
var actionDict = outlineDict.get('A'), dest = null, url = null;
|
||||||
if (actionDict) {
|
if (actionDict) {
|
||||||
var destEntry = actionDict.get('D');
|
var destEntry = actionDict.get('D');
|
||||||
@ -188,8 +191,6 @@ var Catalog = (function CatalogClosure() {
|
|||||||
processed.put(obj);
|
processed.put(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return (root.items.length > 0 ? root.items : null);
|
return (root.items.length > 0 ? root.items : null);
|
||||||
},
|
},
|
||||||
get numPages() {
|
get numPages() {
|
||||||
|
@ -430,6 +430,19 @@ describe('api', function() {
|
|||||||
loadingTask.destroy();
|
loadingTask.destroy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('gets non-existent outline', function() {
|
||||||
|
var url = combineUrl(window.location.href, '../pdfs/tracemonkey.pdf');
|
||||||
|
var loadingTask = PDFJS.getDocument(url);
|
||||||
|
|
||||||
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
||||||
|
return pdfDocument.getOutline();
|
||||||
|
});
|
||||||
|
waitsForPromiseResolved(promise, function (outline) {
|
||||||
|
expect(outline).toEqual(null);
|
||||||
|
|
||||||
|
loadingTask.destroy();
|
||||||
|
});
|
||||||
|
});
|
||||||
it('gets outline', function() {
|
it('gets outline', function() {
|
||||||
var promise = doc.getOutline();
|
var promise = doc.getOutline();
|
||||||
waitsForPromiseResolved(promise, function(outline) {
|
waitsForPromiseResolved(promise, function(outline) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user