]> git.parisson.com Git - pdf.js.git/commitdiff
Small refactoring of fallback code to fake worker.
authorSteffen Märcker <merkste@web.de>
Wed, 28 Dec 2011 14:21:32 +0000 (15:21 +0100)
committerSteffen Märcker <merkste@web.de>
Wed, 28 Dec 2011 14:21:32 +0000 (15:21 +0100)
src/core.js

index bf221b4b184f8e0fbb14897e1606bacdd5312a18..be8b6ba27a3fe797e188a755a2ded8de84ec9683 100644 (file)
@@ -579,42 +579,34 @@ var PDFDoc = (function PDFDocClosure() {
         throw 'No PDFJS.workerSrc specified';
       }
 
-      var worker;
       try {
-        worker = new Worker(workerSrc);
-      } catch (e) {
         // Some versions of FF can't create a worker on localhost, see:
         // https://bugzilla.mozilla.org/show_bug.cgi?id=683280
-        globalScope.PDFJS.disableWorker = true;
-        this.setupFakeWorker();
-        return;
-      }
-
-      var messageHandler = new MessageHandler('main', worker);
-
-      // Tell the worker the file it was created from.
-      messageHandler.send('workerSrc', workerSrc);
-
-      messageHandler.on('test', function pdfDocTest(supportTypedArray) {
-        if (supportTypedArray) {
-          this.worker = worker;
-          this.setupMessageHandler(messageHandler);
-        } else {
-          this.setupFakeWorker();
-        }
-      }.bind(this));
+        var worker = new Worker(workerSrc);
+        
+        var messageHandler = new MessageHandler('main', worker);
+        // Tell the worker the file it was created from.
+        messageHandler.send('workerSrc', workerSrc);
+        messageHandler.on('test', function pdfDocTest(supportTypedArray) {
+          if (supportTypedArray) {
+            this.worker = worker;
+            this.setupMessageHandler(messageHandler);
+          } else {
+            globalScope.PDFJS.disableWorker = true;
+            this.setupFakeWorker();
+          }
+        }.bind(this));
 
-      var testObj = new Uint8Array(1);
-      // Some versions of Opera throw a DATA_CLONE_ERR on serializing the typed array.
-      // If such an error occurs, we fallback to a faked worker.
-      try {
+        var testObj = new Uint8Array(1);
+        // Some versions of Opera throw a DATA_CLONE_ERR on serializing the typed array.
         messageHandler.send('test', testObj);
-      } catch (e) {
-        this.setupFakeWorker();
-      }
-    } else {
-      this.setupFakeWorker();
+        return;
+      } catch (e) {}
     }
+    // Either workers are disabled, not suppored or have thrown an exception.
+    // Thus, we fallback to a faked worker.
+    globalScope.PDFJS.disableWorker = true;
+    this.setupFakeWorker();
   }
 
   PDFDoc.prototype = {