]> git.parisson.com Git - pdf.js.git/commitdiff
Zero gjslint warnings mark
authornotmasteryet <async.processingjs@yahoo.com>
Sun, 18 Sep 2011 19:44:57 +0000 (14:44 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Sun, 18 Sep 2011 19:44:57 +0000 (14:44 -0500)
pdf.js
test/driver.js
worker/client.js
worker/font.js
worker/pdf.js

diff --git a/pdf.js b/pdf.js
index 1ee56e7ed7e7b150595c872f7dda2a286c7d0679..6ce70215f7fc387cb02dddc0adaef1cda5f45917 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -3226,8 +3226,8 @@ var XRef = (function() {
         if (this.encrypt && !suppressEncryption) {
           try {
             e = parser.getObj(this.encrypt.createCipherTransform(num, gen));
-          } catch(ex) {
-            // almost all streams must to encrypted, but sometimes
+          } catch (ex) {
+            // almost all streams must be encrypted, but sometimes
             // they are not probably due to some broken generators
             // re-trying without encryption
             return this.fetch(ref, true);
index 14f1280a6678314874f14885dd3ab8af0d630020..92beaf78fb038564a5ae58c28a3f9ef45ee9fdcb 100644 (file)
@@ -49,7 +49,7 @@ function load() {
   };
   r.send(null);
 }
-window.onload = load;
+documet.addEventListener('DOMContentLoaded', load);
 
 function nextTask() {
   if (currentTaskIdx == manifest.length) {
index 36a0ae03a7dd07c23f6c784a0290ff88fe3b69f0..a51484c64345cef7a0009eabfb17468a3886803f 100644 (file)
@@ -3,23 +3,26 @@
 
 'use strict';
 
-if (typeof console.time == 'undefined') {
+var consoleUtils = (function() {
   var consoleTimer = {};
-  console.time = function(name) {
+
+  var obj = {};
+  obj.time = function(name) {
     consoleTimer[name] = Date.now();
   };
-
-  console.timeEnd = function(name) {
+  obj.timeEnd = function(name) {
     var time = consoleTimer[name];
     if (time == null) {
       throw 'Unkown timer name ' + name;
     }
-    this.log('Timer:', name, Date.now() - time);
+    console.log('Timer:', name, Date.now() - time);
   };
-}
+
+  return obj;
+})();
 
 function FontWorker() {
-  this.worker = new Worker('worker/font.js');
+  this.worker = new Worker('../worker/font.js');
   this.fontsWaiting = 0;
   this.fontsWaitingCallbacks = [];
 
@@ -96,7 +99,7 @@ FontWorker.prototype = {
       this.fontsWaiting++;
     }
 
-    console.time('ensureFonts');
+    consoleUtils.time('ensureFonts');
     // If there are fonts, that need to get loaded, tell the FontWorker to get
     // started and push the callback on the waiting-callback-stack.
     if (notLoaded.length != 0) {
@@ -124,7 +127,7 @@ function WorkerPDFDoc(canvas) {
 
   this.ctx = canvas.getContext('2d');
   this.canvas = canvas;
-  this.worker = new Worker('worker/pdf.js');
+  this.worker = new Worker('../worker/pdf.js');
   this.fontWorker = new FontWorker();
   this.waitingForFonts = false;
   this.waitingForFontsCallback = [];
@@ -167,7 +170,8 @@ function WorkerPDFDoc(canvas) {
     },
 
     '$putImageData': function(imageData, x, y) {
-      var imgData = this.getImageData(0, 0, imageData.width, imageData.height);
+      var imgData = this.getImageData(0, 0,
+        imageData.width, imageData.height);
 
       // Store the .data property to avaid property lookups.
       var imageRealData = imageData.data;
@@ -339,7 +343,7 @@ function WorkerPDFDoc(canvas) {
 
         var renderData = function() {
           if (id == 0) {
-            console.time('main canvas rendering');
+            consoleUtils.time('main canvas rendering');
             var ctx = this.ctx;
             ctx.save();
             ctx.fillStyle = 'rgb(255, 255, 255)';
@@ -348,8 +352,8 @@ function WorkerPDFDoc(canvas) {
           }
           renderProxyCanvas(canvasList[id], cmdQueue);
           if (id == 0) {
-            console.timeEnd('main canvas rendering');
-            console.timeEnd('>>> total page display time:');
+            consoleUtils.timeEnd('main canvas rendering');
+            consoleUtils.timeEnd('>>> total page display time:');
           }
         }.bind(this);
 
@@ -368,51 +372,52 @@ function WorkerPDFDoc(canvas) {
   };
 
   // Listen to the WebWorker for data and call actionHandler on it.
-  this.worker.onmessage = function(event) {
+  this.worker.addEventListener('message', function(event) {
     var data = event.data;
     if (data.action in actionHandler) {
       actionHandler[data.action].call(this, data.data);
     } else {
       throw 'Unkown action from worker: ' + data.action;
     }
-  }.bind(this);
+  }.bind(this));
 }
 
-WorkerPDFDoc.prototype.open = function(url, callback) {
-  var req = new XMLHttpRequest();
-  req.open('GET', url);
-  req.mozResponseType = req.responseType = 'arraybuffer';
-  req.expected = (document.URL.indexOf('file:') == 0) ? 0 : 200;
-  req.onreadystatechange = function() {
-    if (req.readyState == 4 && req.status == req.expected) {
-      var data = req.mozResponseArrayBuffer || req.mozResponse ||
-      req.responseArrayBuffer || req.response;
-
-      this.loadCallback = callback;
-      this.worker.postMessage(data);
-      this.showPage(this.numPage);
-    }
-  }.bind(this);
-  req.send(null);
-};
+WorkerPDFDoc.prototype = {
+  open: function(url, callback) {
+    var req = new XMLHttpRequest();
+    req.open('GET', url);
+    req.mozResponseType = req.responseType = 'arraybuffer';
+    req.expected = (document.URL.indexOf('file:') == 0) ? 0 : 200;
+    req.onreadystatechange = function() {
+      if (req.readyState == 4 && req.status == req.expected) {
+        var data = req.mozResponseArrayBuffer || req.mozResponse ||
+        req.responseArrayBuffer || req.response;
+
+        this.loadCallback = callback;
+        this.worker.postMessage(data);
+        this.showPage(this.numPage);
+      }
+    }.bind(this);
+    req.send(null);
+  },
 
-WorkerPDFDoc.prototype.showPage = function(numPage) {
-  this.numPage = parseInt(numPage, 10);
-  console.log('=== start rendering page ' + numPage + ' ===');
-  console.time('>>> total page display time:');
-  this.worker.postMessage(numPage);
-  if (this.onChangePage) {
-    this.onChangePage(numPage);
-  }
-};
+  showPage: function(numPage) {
+    this.numPage = parseInt(numPage, 10);
+    console.log('=== start rendering page ' + numPage + ' ===');
+    consoleUtils.time('>>> total page display time:');
+    this.worker.postMessage(numPage);
+    if (this.onChangePage) {
+      this.onChangePage(numPage);
+    }
+  },
 
-WorkerPDFDoc.prototype.nextPage = function() {
-  if (this.numPage != this.numPages)
-    this.showPage(++this.numPage);
-};
+  nextPage: function() {
+    if (this.numPage != this.numPages)
+      this.showPage(++this.numPage);
+  },
 
-WorkerPDFDoc.prototype.prevPage = function() {
-  if (this.numPage != 1)
-    this.showPage(--this.numPage);
+  prevPage: function() {
+    if (this.numPage != 1)
+      this.showPage(--this.numPage);
+  }
 };
-
index 44a4782f0d2a2b8c09e506690425a384bf864490..4319de7b944e0fa9de6cb3486c037060a31b1da5 100644 (file)
@@ -56,12 +56,12 @@ var actionHandler = {
 };
 
 // Listen to the MainThread for data and call actionHandler on it.
-this.onmessage = function(event) {
+addEventListener('message', function(event) {
   var data = event.data;
   if (data.action in actionHandler) {
     actionHandler[data.action].call(this, data.data);
   } else {
     throw 'Unkown action from worker: ' + data.action;
   }
-};
+});
 
index 7a72ac824c9da8f6ae6d9f2e5e2809c691307c82..f205547abecfc1401fc52bb829f5ece1f40e85ec 100644 (file)
@@ -11,8 +11,10 @@ var console = {
       action: 'log',
       data: args
     });
-  },
+  }
+};
 
+var consoleUtils = {
   time: function(name) {
     consoleTimer[name] = Date.now();
   },
@@ -22,7 +24,7 @@ var console = {
     if (time == null) {
       throw 'Unkown timer name ' + name;
     }
-    this.log('Timer:', name, Date.now() - time);
+    console.log('Timer:', name, Date.now() - time);
   }
 };
 
@@ -42,7 +44,7 @@ var canvas = new CanvasProxy(1224, 1584);
 
 // Listen for messages from the main thread.
 var pdfDocument = null;
-onmessage = function(event) {
+addEventListener('message', function(event) {
   var data = event.data;
   // If there is no pdfDocument yet, then the sent data is the PDFDocument.
   if (!pdfDocument) {
@@ -55,7 +57,7 @@ onmessage = function(event) {
   }
   // User requested to render a certain page.
   else {
-    console.time('compile');
+    consoleUtils.time('compile');
 
     // Let's try to render the first page...
     var page = pdfDocument.getPage(parseInt(data, 10));
@@ -77,19 +79,19 @@ onmessage = function(event) {
     var fonts = [];
     var gfx = new CanvasGraphics(canvas.getContext('2d'), CanvasProxy);
     page.compile(gfx, fonts);
-    console.timeEnd('compile');
+    consoleUtils.timeEnd('compile');
 
     // Send fonts to the main thread.
-    console.time('fonts');
+    consoleUtils.time('fonts');
     postMessage({
       action: 'fonts',
       data: fonts
     });
-    console.timeEnd('fonts');
+    consoleUtils.timeEnd('fonts');
 
-    console.time('display');
+    consoleUtils.time('display');
     page.display(gfx);
     canvas.flush();
-    console.timeEnd('display');
+    consoleUtils.timeEnd('display');
   }
-};
+});