[Pkg-javascript-commits] [pdf.js] 292/414: Makes WorkerMessageHandler non-global.
David Prévot
taffit at moszumanska.debian.org
Tue Jun 28 17:12:32 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit e372f3608b12ec8adf31f1264fa73e52a556bb3c
Author: Yury Delendik <ydelendik at mozilla.com>
Date: Wed Mar 2 19:16:38 2016 -0600
Makes WorkerMessageHandler non-global.
---
src/core/worker.js | 5 -----
src/display/api.js | 35 +++++++++++++++++++++--------------
src/frameworks.js | 6 +++---
src/pdf.js | 2 ++
4 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/src/core/worker.js b/src/core/worker.js
index e55dbf8..94e362b 100644
--- a/src/core/worker.js
+++ b/src/core/worker.js
@@ -994,11 +994,6 @@ function initializeWorker() {
handler.send('ready', null);
}
-if (globalScope.PDFJS) {
- // TODO properly handle WorkerMessageHandler as a module export at api.js.
- globalScope.PDFJS.WorkerMessageHandler = WorkerMessageHandler;
-}
-
// Worker thread (and not node.js)?
if (typeof window === 'undefined' &&
!(typeof module !== 'undefined' && module.require)) {
diff --git a/src/display/api.js b/src/display/api.js
index 24a94b4..e7ad3dd 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -1215,38 +1215,45 @@ var PDFWorker = (function PDFWorkerClosure() {
error('No PDFJS.workerSrc specified');
}
+ var fakeWorkerFilesLoadedCapability;
+
// Loads worker code into main thread.
function setupFakeWorkerGlobal() {
- if (!PDFJS.fakeWorkerFilesLoadedCapability) {
- PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
+ var WorkerMessageHandler;
+ if (!fakeWorkerFilesLoadedCapability) {
+ fakeWorkerFilesLoadedCapability = createPromiseCapability();
// In the developer build load worker_loader which in turn loads all the
// other files and resolves the promise. In production only the
// pdf.worker.js file is needed.
//#if !PRODUCTION
if (typeof amdRequire === 'function') {
- amdRequire(['pdfjs/core/network', 'pdfjs/core/worker'], function () {
- PDFJS.fakeWorkerFilesLoadedCapability.resolve();
+ amdRequire(['pdfjs/core/network', 'pdfjs/core/worker'],
+ function (network, worker) {
+ WorkerMessageHandler = worker.WorkerMessageHandler;
+ fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
});
} else if (typeof require === 'function') {
- require('../core/worker.js');
- PDFJS.fakeWorkerFilesLoadedCapability.resolve();
+ var worker = require('../core/worker.js');
+ WorkerMessageHandler = worker.WorkerMessageHandler;
+ fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
} else {
throw new Error('AMD or CommonJS must be used to load fake worker.');
}
//#endif
//#if PRODUCTION && SINGLE_FILE
-// PDFJS.fakeWorkerFilesLoadedCapability.resolve();
+// WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
+// fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
//#endif
//#if PRODUCTION && !SINGLE_FILE
// var loader = fakeWorkerFilesLoader || function (callback) {
-// Util.loadScript(getWorkerSrc(), callback);
+// Util.loadScript(getWorkerSrc(), function () {
+// callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
+// });
// };
-// loader(function () {
-// PDFJS.fakeWorkerFilesLoadedCapability.resolve();
-// });
+// loader(fakeWorkerFilesLoadedCapability.resolve);
//#endif
}
- return PDFJS.fakeWorkerFilesLoadedCapability.promise;
+ return fakeWorkerFilesLoadedCapability.promise;
}
function createCDNWrapper(url) {
@@ -1385,7 +1392,7 @@ var PDFWorker = (function PDFWorkerClosure() {
globalScope.PDFJS.disableWorker = true;
}
- setupFakeWorkerGlobal().then(function () {
+ setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
if (this.destroyed) {
this._readyCapability.reject(new Error('Worker was destroyed'));
return;
@@ -1417,7 +1424,7 @@ var PDFWorker = (function PDFWorkerClosure() {
// If the main thread is our worker, setup the handling for the
// messages -- the main thread sends to it self.
var workerHandler = new MessageHandler(id + '_worker', id, port);
- PDFJS.WorkerMessageHandler.setup(workerHandler, port);
+ WorkerMessageHandler.setup(workerHandler, port);
var messageHandler = new MessageHandler(id, id + '_worker', port);
this._messageHandler = messageHandler;
diff --git a/src/frameworks.js b/src/frameworks.js
index 95b4d36..0149321 100644
--- a/src/frameworks.js
+++ b/src/frameworks.js
@@ -37,11 +37,11 @@ if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
}
var fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) {
require.ensure([], function () {
- require('./pdf.worker.js');
- callback();
+ var worker = require('./pdf.worker.js');
+ callback(worker.WorkerMessageHandler);
});
}) : (typeof requirejs !== 'undefined') ? (function (callback) {
requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
- callback();
+ callback(worker.WorkerMessageHandler);
});
}) : null;
diff --git a/src/pdf.js b/src/pdf.js
index 49da559..6a5c880 100644
--- a/src/pdf.js
+++ b/src/pdf.js
@@ -57,5 +57,7 @@
exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
exports.UnexpectedResponseException =
pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
+//#else
+ exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
//#endif
}));
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list