Replace the remaining occurences, in src/display/api.js, of var with let/const

This commit is contained in:
Jonas Jenwald 2018-11-08 16:24:20 +01:00
parent 061f7bd2f3
commit ac6b94c9dd

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
/* globals requirejs, __non_webpack_require__ */ /* globals requirejs, __non_webpack_require__ */
/* eslint no-var: error */
import { import {
assert, createPromiseCapability, deprecated, getVerbosityLevel, info, assert, createPromiseCapability, deprecated, getVerbosityLevel, info,
@ -106,7 +107,7 @@ if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
*/ */
/** @type IPDFStreamFactory */ /** @type IPDFStreamFactory */
var createPDFNetworkStream; let createPDFNetworkStream;
/** /**
* Sets the function that instantiates a IPDFStream as an alternative PDF data * Sets the function that instantiates a IPDFStream as an alternative PDF data
@ -221,9 +222,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
* @return {PDFDocumentLoadingTask} * @return {PDFDocumentLoadingTask}
*/ */
function getDocument(src) { function getDocument(src) {
var task = new PDFDocumentLoadingTask(); const task = new PDFDocumentLoadingTask();
var source; let source;
if (typeof src === 'string') { if (typeof src === 'string') {
source = { url: src, }; source = { url: src, };
} else if (isArrayBuffer(src)) { } else if (isArrayBuffer(src)) {
@ -239,15 +240,12 @@ function getDocument(src) {
throw new Error( throw new Error(
'Invalid parameter object: need either .data, .range or .url'); 'Invalid parameter object: need either .data, .range or .url');
} }
source = src; source = src;
} }
const params = Object.create(null);
let rangeTransport = null, worker = null;
let params = Object.create(null); for (const key in source) {
var rangeTransport = null;
let worker = null;
for (var key in source) {
if (key === 'url' && typeof window !== 'undefined') { if (key === 'url' && typeof window !== 'undefined') {
// The full path is required in the 'url' field. // The full path is required in the 'url' field.
params[key] = new URL(source[key], window.location).href; params[key] = new URL(source[key], window.location).href;
@ -260,7 +258,7 @@ function getDocument(src) {
continue; continue;
} else if (key === 'data' && !(source[key] instanceof Uint8Array)) { } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
// Converting string or array-like data to Uint8Array. // Converting string or array-like data to Uint8Array.
var pdfBytes = source[key]; const pdfBytes = source[key];
if (typeof pdfBytes === 'string') { if (typeof pdfBytes === 'string') {
params[key] = stringToBytes(pdfBytes); params[key] = stringToBytes(pdfBytes);
} else if (typeof pdfBytes === 'object' && pdfBytes !== null && } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
@ -329,13 +327,13 @@ function getDocument(src) {
new PDFWorker(workerParams); new PDFWorker(workerParams);
task._worker = worker; task._worker = worker;
} }
var docId = task.docId; const docId = task.docId;
worker.promise.then(function () { worker.promise.then(function() {
if (task.destroyed) { if (task.destroyed) {
throw new Error('Loading aborted'); throw new Error('Loading aborted');
} }
return _fetchDocument(worker, params, rangeTransport, docId).then( return _fetchDocument(worker, params, rangeTransport, docId).then(
function (workerId) { function(workerId) {
if (task.destroyed) { if (task.destroyed) {
throw new Error('Loading aborted'); throw new Error('Loading aborted');
} }
@ -360,10 +358,10 @@ function getDocument(src) {
}); });
} }
var messageHandler = new MessageHandler(docId, workerId, worker.port); const messageHandler = new MessageHandler(docId, workerId, worker.port);
messageHandler.postMessageTransfers = worker.postMessageTransfers; messageHandler.postMessageTransfers = worker.postMessageTransfers;
var transport = new WorkerTransport(messageHandler, task, networkStream, const transport = new WorkerTransport(messageHandler, task, networkStream,
params); params);
task._transport = transport; task._transport = transport;
messageHandler.send('Ready', null); messageHandler.send('Ready', null);
}); });
@ -411,7 +409,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
nativeImageDecoderSupport: source.nativeImageDecoderSupport, nativeImageDecoderSupport: source.nativeImageDecoderSupport,
ignoreErrors: source.ignoreErrors, ignoreErrors: source.ignoreErrors,
isEvalSupported: source.isEvalSupported, isEvalSupported: source.isEvalSupported,
}).then(function (workerId) { }).then(function(workerId) {
if (worker.destroyed) { if (worker.destroyed) {
throw new Error('Worker was destroyed'); throw new Error('Worker was destroyed');
} }
@ -1257,11 +1255,10 @@ class LoopbackPort {
if (cloned.has(value)) { // already cloned the object if (cloned.has(value)) { // already cloned the object
return cloned.get(value); return cloned.get(value);
} }
var result; let buffer, result;
var buffer;
if ((buffer = value.buffer) && isArrayBuffer(buffer)) { if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
// We found object with ArrayBuffer (typed array). // We found object with ArrayBuffer (typed array).
var transferable = transfers && transfers.includes(buffer); const transferable = transfers && transfers.includes(buffer);
if (value === buffer) { if (value === buffer) {
// Special case when we are faking typed arrays in compatibility.js. // Special case when we are faking typed arrays in compatibility.js.
result = value; result = value;
@ -1278,8 +1275,8 @@ class LoopbackPort {
cloned.set(value, result); // adding to cache now for cyclic references cloned.set(value, result); // adding to cache now for cyclic references
// Cloning all value and object properties, however ignoring properties // Cloning all value and object properties, however ignoring properties
// defined via getter. // defined via getter.
for (var i in value) { for (const i in value) {
var desc, p = value; let desc, p = value;
while (!(desc = Object.getOwnPropertyDescriptor(p, i))) { while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
p = Object.getPrototypeOf(p); p = Object.getPrototypeOf(p);
} }
@ -1293,16 +1290,16 @@ class LoopbackPort {
} }
if (!this._defer) { if (!this._defer) {
this._listeners.forEach(function (listener) { this._listeners.forEach(function(listener) {
listener.call(this, { data: obj, }); listener.call(this, { data: obj, });
}, this); }, this);
return; return;
} }
var cloned = new WeakMap(); const cloned = new WeakMap();
var e = { data: cloneValue(obj), }; const e = { data: cloneValue(obj), };
this._deferred.then(() => { this._deferred.then(() => {
this._listeners.forEach(function (listener) { this._listeners.forEach(function(listener) {
listener.call(this, e); listener.call(this, e);
}, this); }, this);
}); });
@ -1313,7 +1310,7 @@ class LoopbackPort {
} }
removeEventListener(name, listener) { removeEventListener(name, listener) {
var i = this._listeners.indexOf(listener); const i = this._listeners.indexOf(listener);
this._listeners.splice(i, 1); this._listeners.splice(i, 1);
} }
@ -2036,9 +2033,9 @@ class WorkerTransport {
new Error('Only 3 components or 1 component can be returned')); new Error('Only 3 components or 1 component can be returned'));
} }
return new Promise(function (resolve, reject) { return new Promise(function(resolve, reject) {
const img = new Image(); const img = new Image();
img.onload = function () { img.onload = function() {
const width = img.width; const width = img.width;
const height = img.height; const height = img.height;
const size = width * height; const size = width * height;
@ -2064,7 +2061,7 @@ class WorkerTransport {
} }
resolve({ data: buf, width, height, }); resolve({ data: buf, width, height, });
}; };
img.onerror = function () { img.onerror = function() {
reject(new Error('JpegDecode failed to load image')); reject(new Error('JpegDecode failed to load image'));
}; };
img.src = imageUrl; img.src = imageUrl;
@ -2485,11 +2482,10 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
return InternalRenderTask; return InternalRenderTask;
})(); })();
var version, build; const version = (typeof PDFJSDev !== 'undefined' ?
if (typeof PDFJSDev !== 'undefined') { PDFJSDev.eval('BUNDLE_VERSION') : null);
version = PDFJSDev.eval('BUNDLE_VERSION'); const build = (typeof PDFJSDev !== 'undefined' ?
build = PDFJSDev.eval('BUNDLE_BUILD'); PDFJSDev.eval('BUNDLE_BUILD') : null);
}
export { export {
getDocument, getDocument,