Skip to content

Commit

Permalink
Merge pull request mozilla#8959 from Snuffleupagus/api-worker-version…
Browse files Browse the repository at this point in the history
…-check

Ensure that the same exact version of PDF.js is used in both the API and the Worker
  • Loading branch information
Snuffleupagus authored Sep 27, 2017
2 parents bf254ba + 294922d commit c58b9fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ var WorkerMessageHandler = {
var cancelXHRs = null;
var WorkerTasks = [];

let apiVersion = docParams.apiVersion;
let workerVersion =
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
// The `apiVersion !== null` check is needed to avoid errors during testing.
if (apiVersion !== null && apiVersion !== workerVersion) {
throw new Error(`The API version "${apiVersion}" does not match ` +
`the Worker version "${workerVersion}".`);
}

var docId = docParams.docId;
var docBaseUrl = docParams.docBaseUrl;
var workerHandlerName = docParams.docId + '_worker';
Expand Down
3 changes: 3 additions & 0 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
if (worker.destroyed) {
return Promise.reject(new Error('Worker was destroyed'));
}
let apiVersion =
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;

source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
source.disableStream = getDefaultSetting('disableStream');
Expand All @@ -341,6 +343,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
}
return worker.messageHandler.sendWithPromise('GetDocRequest', {
docId,
apiVersion,
source: {
data: source.data,
url: source.url,
Expand Down

0 comments on commit c58b9fe

Please sign in to comment.