]> git.parisson.com Git - pdf.js.git/commitdiff
use ES5 Object operations for lazy properties
authorAndreas Gal <andreas.gal@gmail.com>
Tue, 3 May 2011 00:20:08 +0000 (17:20 -0700)
committerAndreas Gal <andreas.gal@gmail.com>
Tue, 3 May 2011 00:20:08 +0000 (17:20 -0700)
pdf.js

diff --git a/pdf.js b/pdf.js
index a1facc4702d733957712f788b751a74221ba8ac1..0437816dc60cf6c973ea2dd717d3a7686e982669 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -558,16 +558,37 @@ var PDFDoc = (function () {
         this.setup(arrayBuffer);
     }
 
+    function ShadowGetter(obj, name, value) {
+        Object.defineProperty(obj, name, {
+            value: value,
+            configurable: false,
+            writable: false,
+            enumerable: true
+        });
+    }
+
     constructor.prototype = {
-        getLinearization: function() {
-            var linearization = this.linearization;
-            if (!linearization)
-                return this.linearization = new Linearization(this.stream);
+        get linearization() {
+            var length = this.stream.length;
+            var linearization = false;
+            if (length) {
+                linearization = new Linearization(this.stream);
+                if (linearization.length != length)
+                    linearization = false;
+            }
+            ShadowGetter(this, "linearization", linearization);
             return linearization;
         },
-        isLinearized: function() {
-            var length = this.stream.length;
-            return length && this.getLinearization().length == length;
+        get startXRef() {
+            var startXRef;
+            var linearization = this.linearization;
+            if (linearization) {
+                // TODO
+            } else {
+                // TODO
+            }
+            ShadowGetter(this, "startXRef", startXRef);
+            return startXRef;
         },
         // Find the header, remove leading garbage and setup the stream
         // starting from the header.