]> git.parisson.com Git - pdf.js.git/commitdiff
errors thrown by |get numPages()| were not caught. GETTERS!!!
authorChris Jones <jones.chris.g@gmail.com>
Sat, 25 Jun 2011 03:41:47 +0000 (20:41 -0700)
committerChris Jones <jones.chris.g@gmail.com>
Sat, 25 Jun 2011 03:41:47 +0000 (20:41 -0700)
test/test_slave.html

index d685eeaf233f952913e5651419401f024c68f6af..32076d075255be1ad6ded1f8b799e78d33051ee3 100644 (file)
@@ -6,7 +6,7 @@
   <script type="text/javascript" src="/fonts.js"></script>
   <script type="text/javascript" src="/glyphlist.js"></script>
   <script type="application/javascript">
-var browser, canvas, currentTask, currentTaskIdx, failure, manifest, pdfDoc, stdout;
+var browser, canvas, currentTask, currentTaskIdx, failure, manifest, numPages, pdfDoc, stdout;
 
 function queryParams() {
     var qs = window.location.search.substring(1);
@@ -66,8 +66,9 @@ function nextTask() {
 
       try {
         pdfDoc = new PDFDoc(new Stream(data));
+        numPages = pdfDoc.numPages;
       } catch(e) {
-        pdfDoc.numPages = 1;
+        numPages = 1;
         failure = 'load PDF doc: '+ e.toString();
       }
 
@@ -78,7 +79,7 @@ function nextTask() {
 }
 
 function nextPage() {
-  if (currentTask.pageNum > pdfDoc.numPages) {
+  if (currentTask.pageNum > numPages) {
     if (++currentTask.round < currentTask.rounds) {
       log("  Round "+ (1 + currentTask.round) +"\n");
       currentTask.pageNum = 1;
@@ -95,8 +96,9 @@ function nextPage() {
   clear(ctx);
 
   var fonts = [];
-  var gfx = new CanvasGraphics(ctx);
+  var gfx = null;
   try {
+    gfx = new CanvasGraphics(ctx);
     currentPage = pdfDoc.getPage(currentTask.pageNum);
     currentPage.compile(gfx, fonts);
   } catch(e) {
@@ -105,9 +107,13 @@ function nextPage() {
 
   var fontLoaderTimer = null;
   function checkFontsLoaded() {
-    if (!FontLoader.bind(fonts)) {
-      fontLoaderTimer = window.setTimeout(checkFontsLoaded, 10);
-      return;
+    try {
+      if (!FontLoader.bind(fonts)) {
+        fontLoaderTimer = window.setTimeout(checkFontsLoaded, 10);
+        return;
+      }
+    } catch(e) {
+      failure = 'fonts: '+ e.toString();
     }
     snapshotCurrentPage(gfx);
   }
@@ -166,7 +172,7 @@ var inFlightRequests = 0;
 function sendTaskResult(snapshot) {
   var result = { browser: browser,
                  id: currentTask.id,
-                 numPages: pdfDoc.numPages,
+                 numPages: numPages,
                  failure: failure,
                  file: currentTask.file,
                  round: currentTask.round,