]> git.parisson.com Git - pdf.js.git/commitdiff
fetch/getEntry returns null if the entry is free
authornotmasteryet <async.processingjs@yahoo.com>
Sun, 8 Jan 2012 20:03:00 +0000 (14:03 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Sun, 8 Jan 2012 20:03:00 +0000 (14:03 -0600)
src/obj.js

index a0c1fdc8a3163a6787e30e39ed071bbeb06357a9..ef79325469baf56ac58193edfffe9c58aff30ec9 100644 (file)
@@ -120,11 +120,11 @@ var Catalog = (function CatalogClosure() {
       return shadow(this, 'toplevelPagesDict', xrefObj);
     },
     get documentOutline() {
-      var obj = this.catDict.get('Outlines');
       var xref = this.xref;
+      var obj = xref.fetchIfRef(this.catDict.get('Outlines'));
       var root = { items: [] };
-      if (isRef(obj)) {
-        obj = xref.fetch(obj).get('First');
+      if (isDict(obj)) {
+        obj = obj.get('First');
         var processed = new RefSet();
         if (isRef(obj)) {
           var queue = [{obj: obj, parent: root}];
@@ -552,9 +552,7 @@ var XRef = (function XRefClosure() {
     },
     getEntry: function xRefGetEntry(i) {
       var e = this.entries[i];
-      if (e.free)
-        error('reading an XRef stream not implemented yet');
-      return e;
+      return e.free ? null : e; // returns null is the entry is free
     },
     fetchIfRef: function xRefFetchIfRef(obj) {
       if (!isRef(obj))
@@ -563,11 +561,15 @@ var XRef = (function XRefClosure() {
     },
     fetch: function xRefFetch(ref, suppressEncryption) {
       var num = ref.num;
-      var e = this.cache[num];
-      if (e)
-        return e;
+      if (num in this.cache)
+        return this.cache[num];
+
+      var e = this.getEntry(num);
+
+      // the referenced entry can be free
+      if (e === null)
+        return (this.cache[num] = e);
 
-      e = this.getEntry(num);
       var gen = ref.gen;
       var stream, parser;
       if (e.uncompressed) {