1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 15:48:06 +02:00

Enable the ESLint prefer-const rule globally (PR 11450 follow-up)

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/prefer-const

With the recent introduction of Prettier this sort of mass enabling of ESLint rules becomes a lot easier, since the code will be automatically reformatted as necessary to account for e.g. changed line lengths.

Note that this patch is generated automatically, by using the ESLint `--fix` argument, and will thus require some additional clean-up (which is done separately).
This commit is contained in:
Jonas Jenwald 2020-01-24 09:48:21 +01:00
parent d2d9441373
commit 9e262ae7fa
54 changed files with 676 additions and 661 deletions

View file

@ -14,7 +14,7 @@ if (process.argv.length < 3) {
process.exit(1);
}
let file = process.argv[2];
const file = process.argv[2];
if (!file.startsWith(pdfFolder)) {
throw new Error(`PDF file must be in '${pdfFolder}' directory.`);
}
@ -46,7 +46,7 @@ calculateMD5(file, (err, md5) => {
throw new Error(err);
}
let contents = fs.readFileSync(gitIgnore, "utf8").split("\n");
let randomLine = getRandomArbitrary(10, contents.length - 2);
const randomLine = getRandomArbitrary(10, contents.length - 2);
contents.splice(
randomLine,
0,
@ -55,10 +55,10 @@ calculateMD5(file, (err, md5) => {
fs.writeFileSync("test/pdfs/.gitignore", contents.join("\n"));
contents = fs.readFileSync(testManifest, "utf8");
let pdf = file.substring(file.lastIndexOf("/") + 1, file.length - 4);
let randomPoint = getRandomArbitrary(100, contents.length - 20);
let bracket = contents.indexOf("},\n", randomPoint);
let out =
const pdf = file.substring(file.lastIndexOf("/") + 1, file.length - 4);
const randomPoint = getRandomArbitrary(100, contents.length - 20);
const bracket = contents.indexOf("},\n", randomPoint);
const out =
contents.substring(0, bracket) +
"},\n" +
` { "id": "${pdf}",\n` +

View file

@ -119,7 +119,7 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
* the overrides file because the browser does not resolve that when the
* styles are inserted via XHR. Therefore, we load and combine them here.
*/
let styles = {
const styles = {
common: {
file: "../web/annotation_layer_builder.css",
promise: null,
@ -137,9 +137,9 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
}
// Load the style files and cache the results.
for (let key in styles) {
for (const key in styles) {
styles[key].promise = new Promise(function(resolve, reject) {
let xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.open("GET", styles[key].file);
xhr.onload = function() {
resolve(xhr.responseText);
@ -379,14 +379,14 @@ var Driver = (function DriverClosure() {
this._done();
return;
}
let task = this.manifest[this.currentTask];
const task = this.manifest[this.currentTask];
task.round = 0;
task.pageNum = task.firstPage || 1;
task.stats = { times: [] };
this._log('Loading file "' + task.file + '"\n');
let absoluteUrl = new URL(task.file, window.location).href;
const absoluteUrl = new URL(task.file, window.location).href;
try {
const loadingTask = pdfjsLib.getDocument({
url: absoluteUrl,
@ -419,18 +419,18 @@ var Driver = (function DriverClosure() {
_cleanup() {
// Clear out all the stylesheets since a new one is created for each font.
while (document.styleSheets.length > 0) {
let styleSheet = document.styleSheets[0];
const styleSheet = document.styleSheets[0];
while (styleSheet.cssRules.length > 0) {
styleSheet.deleteRule(0);
}
styleSheet.ownerNode.remove();
}
let body = document.body;
const body = document.body;
while (body.lastChild !== this.end) {
body.removeChild(body.lastChild);
}
let destroyedPromises = [];
const destroyedPromises = [];
// Wipe out the link to the pdfdoc so it can be GC'ed.
for (let i = 0; i < this.manifest.length; i++) {
if (this.manifest[i].pdfDoc) {

View file

@ -1174,20 +1174,22 @@ describe("annotation", function() {
"should correctly parse a Dest, which violates the specification " +
"by containing a dictionary",
function(done) {
let destDict = new Dict();
const destDict = new Dict();
destDict.set("Type", Name.get("Action"));
destDict.set("S", Name.get("GoTo"));
destDict.set("D", "page.157");
let annotationDict = new Dict();
const annotationDict = new Dict();
annotationDict.set("Type", Name.get("Annot"));
annotationDict.set("Subtype", Name.get("Link"));
// The /Dest must be a Name or an Array, refer to ISO 32000-1:2008
// section 12.3.3, but there are PDF files where it's a dictionary.
annotationDict.set("Dest", destDict);
let annotationRef = Ref.get(798, 0);
let xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
const annotationRef = Ref.get(798, 0);
const xref = new XRefMock([
{ ref: annotationRef, data: annotationDict },
]);
AnnotationFactory.create(
xref,
@ -1479,7 +1481,7 @@ describe("annotation", function() {
});
it("should only accept comb fields when the flags are valid", function(done) {
let invalidFieldFlags = [
const invalidFieldFlags = [
AnnotationFieldFlag.MULTILINE,
AnnotationFieldFlag.PASSWORD,
AnnotationFieldFlag.FILESELECT,

View file

@ -50,9 +50,9 @@ import { isNodeJS } from "../../src/shared/is_node.js";
import { Metadata } from "../../src/display/metadata.js";
describe("api", function() {
let basicApiFileName = "basicapi.pdf";
let basicApiFileLength = 105779; // bytes
let basicApiGetDocumentParams = buildGetDocumentParams(basicApiFileName);
const basicApiFileName = "basicapi.pdf";
const basicApiFileLength = 105779; // bytes
const basicApiGetDocumentParams = buildGetDocumentParams(basicApiFileName);
let CanvasFactory;
@ -102,7 +102,7 @@ describe("api", function() {
});
it("creates pdf doc from URL and aborts before worker initialized", function(done) {
var loadingTask = getDocument(basicApiGetDocumentParams);
let destroyed = loadingTask.destroy();
const destroyed = loadingTask.destroy();
loadingTask.promise
.then(function(reason) {
@ -473,7 +473,7 @@ describe("api", function() {
pending("Worker is not supported in Node.js.");
}
let workerSrc = PDFWorker.getWorkerSrc();
const workerSrc = PDFWorker.getWorkerSrc();
expect(typeof workerSrc).toEqual("string");
expect(workerSrc).toEqual(GlobalWorkerOptions.workerSrc);
});
@ -1339,8 +1339,8 @@ describe("api", function() {
it('gets viewport respecting "dontFlip" argument', function() {
const scale = 1,
rotation = 0;
let viewport = page.getViewport({ scale, rotation });
let dontFlipViewport = page.getViewport({
const viewport = page.getViewport({ scale, rotation });
const dontFlipViewport = page.getViewport({
scale,
rotation,
dontFlip: true,
@ -1511,15 +1511,15 @@ describe("api", function() {
});
it("gets operatorList with JPEG image (issue 4888)", function(done) {
let loadingTask = getDocument(buildGetDocumentParams("cmykjpeg.pdf"));
const loadingTask = getDocument(buildGetDocumentParams("cmykjpeg.pdf"));
loadingTask.promise
.then(pdfDoc => {
pdfDoc.getPage(1).then(pdfPage => {
pdfPage.getOperatorList().then(opList => {
let imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
let imgArgs = opList.argsArray[imgIndex];
let { data } = pdfPage.objs.get(imgArgs[0]);
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
const imgArgs = opList.argsArray[imgIndex];
const { data } = pdfPage.objs.get(imgArgs[0]);
expect(data instanceof Uint8ClampedArray).toEqual(true);
expect(data.length).toEqual(90000);
@ -1607,7 +1607,7 @@ describe("api", function() {
}, done.fail);
});
it("gets page stats after parsing page, with `pdfBug` set", function(done) {
let loadingTask = getDocument(
const loadingTask = getDocument(
buildGetDocumentParams(basicApiFileName, { pdfBug: true })
);
@ -1623,7 +1623,7 @@ describe("api", function() {
expect(stats instanceof StatTimer).toEqual(true);
expect(stats.times.length).toEqual(1);
let [statEntry] = stats.times;
const [statEntry] = stats.times;
expect(statEntry.name).toEqual("Page Request");
expect(statEntry.end - statEntry.start).toBeGreaterThanOrEqual(0);
@ -1631,7 +1631,7 @@ describe("api", function() {
}, done.fail);
});
it("gets page stats after rendering page, with `pdfBug` set", function(done) {
let loadingTask = getDocument(
const loadingTask = getDocument(
buildGetDocumentParams(basicApiFileName, { pdfBug: true })
);
let canvasAndCtx;
@ -1639,13 +1639,13 @@ describe("api", function() {
loadingTask.promise
.then(pdfDoc => {
return pdfDoc.getPage(1).then(pdfPage => {
let viewport = pdfPage.getViewport({ scale: 1 });
const viewport = pdfPage.getViewport({ scale: 1 });
canvasAndCtx = CanvasFactory.create(
viewport.width,
viewport.height
);
let renderTask = pdfPage.render({
const renderTask = pdfPage.render({
canvasContext: canvasAndCtx.context,
canvasFactory: CanvasFactory,
viewport,
@ -1659,7 +1659,7 @@ describe("api", function() {
expect(stats instanceof StatTimer).toEqual(true);
expect(stats.times.length).toEqual(3);
let [statEntryOne, statEntryTwo, statEntryThree] = stats.times;
const [statEntryOne, statEntryTwo, statEntryThree] = stats.times;
expect(statEntryOne.name).toEqual("Page Request");
expect(statEntryOne.end - statEntryOne.start).toBeGreaterThanOrEqual(
0
@ -1700,10 +1700,13 @@ describe("api", function() {
});
it("re-render page, using the same canvas, after cancelling rendering", function(done) {
let viewport = page.getViewport({ scale: 1 });
let canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
const viewport = page.getViewport({ scale: 1 });
const canvasAndCtx = CanvasFactory.create(
viewport.width,
viewport.height
);
let renderTask = page.render({
const renderTask = page.render({
canvasContext: canvasAndCtx.context,
canvasFactory: CanvasFactory,
viewport,
@ -1720,7 +1723,7 @@ describe("api", function() {
}
)
.then(() => {
let reRenderTask = page.render({
const reRenderTask = page.render({
canvasContext: canvasAndCtx.context,
canvasFactory: CanvasFactory,
viewport,

View file

@ -345,7 +345,7 @@ describe("cmap", function() {
});
}
let cmapPromise = CMapFactory.create({
const cmapPromise = CMapFactory.create({
encoding: Name.get("Adobe-Japan1-1"),
fetchBuiltInCMap: tmpFetchBuiltInCMap,
useCMap: null,
@ -356,7 +356,7 @@ describe("cmap", function() {
},
function(reason) {
expect(reason instanceof Error).toEqual(true);
let message = reason.message;
const message = reason.message;
expect(message.startsWith("Unable to load CMap at: ")).toEqual(true);
expect(message.endsWith("/external/bcmaps/Adobe-Japan1-1")).toEqual(
true

View file

@ -48,24 +48,24 @@ describe("colorspace", function() {
describe("DeviceGrayCS", function() {
it("should handle the case when cs is a Name object", function() {
let cs = Name.get("DeviceGray");
let xref = new XRefMock([
const cs = Name.get("DeviceGray");
const xref = new XRefMock([
{
ref: Ref.get(10, 0),
data: new Dict(),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
let testSrc = new Uint8Array([27, 125, 250, 131]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
const testSrc = new Uint8Array([27, 125, 250, 131]);
const testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
27, 27, 27,
27, 27, 27,
125, 125, 125,
@ -93,24 +93,24 @@ describe("colorspace", function() {
expect(testDest).toEqual(expectedDest);
});
it("should handle the case when cs is an indirect object", function() {
let cs = Ref.get(10, 0);
let xref = new XRefMock([
const cs = Ref.get(10, 0);
const xref = new XRefMock([
{
ref: cs,
data: Name.get("DeviceGray"),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
let testSrc = new Uint8Array([27, 125, 250, 131]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
const testSrc = new Uint8Array([27, 125, 250, 131]);
const testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
27, 27, 27,
27, 27, 27,
125, 125, 125,
@ -134,30 +134,30 @@ describe("colorspace", function() {
describe("DeviceRgbCS", function() {
it("should handle the case when cs is a Name object", function() {
let cs = Name.get("DeviceRGB");
let xref = new XRefMock([
const cs = Name.get("DeviceRGB");
const xref = new XRefMock([
{
ref: Ref.get(10, 0),
data: new Dict(),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
const testSrc = new Uint8Array([
27, 125, 250,
131, 139, 140,
111, 25, 198,
21, 147, 255
]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
const testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
27, 125, 250,
27, 125, 250,
131, 139, 140,
@ -185,30 +185,30 @@ describe("colorspace", function() {
expect(testDest).toEqual(expectedDest);
});
it("should handle the case when cs is an indirect object", function() {
let cs = Ref.get(10, 0);
let xref = new XRefMock([
const cs = Ref.get(10, 0);
const xref = new XRefMock([
{
ref: cs,
data: Name.get("DeviceRGB"),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
const testSrc = new Uint8Array([
27, 125, 250,
131, 139, 140,
111, 25, 198,
21, 147, 255
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
const testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
27, 125, 250,
27, 125, 250,
131, 139, 140,
@ -232,30 +232,30 @@ describe("colorspace", function() {
describe("DeviceCmykCS", function() {
it("should handle the case when cs is a Name object", function() {
let cs = Name.get("DeviceCMYK");
let xref = new XRefMock([
const cs = Name.get("DeviceCMYK");
const xref = new XRefMock([
{
ref: Ref.get(10, 0),
data: new Dict(),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
const testSrc = new Uint8Array([
27, 125, 250, 128,
131, 139, 140, 45,
111, 25, 198, 78,
21, 147, 255, 69
]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
const testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
135, 81, 18,
135, 81, 18,
114, 102, 97,
@ -283,30 +283,30 @@ describe("colorspace", function() {
expect(testDest).toEqual(expectedDest);
});
it("should handle the case when cs is an indirect object", function() {
let cs = Ref.get(10, 0);
let xref = new XRefMock([
const cs = Ref.get(10, 0);
const xref = new XRefMock([
{
ref: cs,
data: Name.get("DeviceCMYK"),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
const testSrc = new Uint8Array([
27, 125, 250, 128,
131, 139, 140, 45,
111, 25, 198, 78,
21, 147, 255, 69
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
const testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
135, 81, 18,
135, 81, 18,
114, 102, 97,
@ -330,29 +330,29 @@ describe("colorspace", function() {
describe("CalGrayCS", function() {
it("should handle the case when cs is an array", function() {
let params = new Dict();
const params = new Dict();
params.set("WhitePoint", [1, 1, 1]);
params.set("BlackPoint", [0, 0, 0]);
params.set("Gamma", 2.0);
let cs = [Name.get("CalGray"), params];
let xref = new XRefMock([
const cs = [Name.get("CalGray"), params];
const xref = new XRefMock([
{
ref: Ref.get(10, 0),
data: new Dict(),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
let testSrc = new Uint8Array([27, 125, 250, 131]);
let testDest = new Uint8ClampedArray(4 * 4 * 3);
const testSrc = new Uint8Array([27, 125, 250, 131]);
const testDest = new Uint8ClampedArray(4 * 4 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
25, 25, 25,
25, 25, 25,
143, 143, 143,
@ -383,36 +383,36 @@ describe("colorspace", function() {
describe("CalRGBCS", function() {
it("should handle the case when cs is an array", function() {
let params = new Dict();
const params = new Dict();
params.set("WhitePoint", [1, 1, 1]);
params.set("BlackPoint", [0, 0, 0]);
params.set("Gamma", [1, 1, 1]);
params.set("Matrix", [1, 0, 0, 0, 1, 0, 0, 0, 1]);
let cs = [Name.get("CalRGB"), params];
let xref = new XRefMock([
const cs = [Name.get("CalRGB"), params];
const xref = new XRefMock([
{
ref: Ref.get(10, 0),
data: new Dict(),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
const testSrc = new Uint8Array([
27, 125, 250,
131, 139, 140,
111, 25, 198,
21, 147, 255
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
const testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
0, 238, 255,
0, 238, 255,
185, 196, 195,
@ -436,35 +436,35 @@ describe("colorspace", function() {
describe("LabCS", function() {
it("should handle the case when cs is an array", function() {
let params = new Dict();
const params = new Dict();
params.set("WhitePoint", [1, 1, 1]);
params.set("BlackPoint", [0, 0, 0]);
params.set("Range", [-100, 100, -100, 100]);
let cs = [Name.get("Lab"), params];
let xref = new XRefMock([
const cs = [Name.get("Lab"), params];
const xref = new XRefMock([
{
ref: Ref.get(10, 0),
data: new Dict(),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
// prettier-ignore
let testSrc = new Uint8Array([
const testSrc = new Uint8Array([
27, 25, 50,
31, 19, 40,
11, 25, 98,
21, 47, 55
]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
const testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
0, 49, 101,
0, 49, 101,
0, 53, 117,
@ -490,29 +490,29 @@ describe("colorspace", function() {
describe("IndexedCS", function() {
it("should handle the case when cs is an array", function() {
// prettier-ignore
let lookup = new Uint8Array([
const lookup = new Uint8Array([
23, 155, 35,
147, 69, 93,
255, 109, 70
]);
let cs = [Name.get("Indexed"), Name.get("DeviceRGB"), 2, lookup];
let xref = new XRefMock([
const cs = [Name.get("Indexed"), Name.get("DeviceRGB"), 2, lookup];
const xref = new XRefMock([
{
ref: Ref.get(10, 0),
data: new Dict(),
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
let testSrc = new Uint8Array([2, 2, 0, 1]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
const testSrc = new Uint8Array([2, 2, 0, 1]);
const testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
255, 109, 70,
255, 109, 70,
255, 109, 70,
@ -536,7 +536,7 @@ describe("colorspace", function() {
describe("AlternateCS", function() {
it("should handle the case when cs is an array", function() {
let fnDict = new Dict();
const fnDict = new Dict();
fnDict.set("FunctionType", 4);
fnDict.set("Domain", [0.0, 1.0]);
fnDict.set("Range", [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);
@ -550,31 +550,31 @@ describe("colorspace", function() {
);
fn = new Stream(fn.bytes, 0, 58, fnDict);
let fnRef = Ref.get(10, 0);
const fnRef = Ref.get(10, 0);
let cs = [
const cs = [
Name.get("Separation"),
Name.get("LogoGreen"),
Name.get("DeviceCMYK"),
fnRef,
];
let xref = new XRefMock([
const xref = new XRefMock([
{
ref: fnRef,
data: fn,
},
]);
let res = new Dict();
const res = new Dict();
let pdfFunctionFactory = new PDFFunctionFactory({
const pdfFunctionFactory = new PDFFunctionFactory({
xref,
});
let colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
const colorSpace = ColorSpace.parse(cs, xref, res, pdfFunctionFactory);
let testSrc = new Uint8Array([27, 25, 50, 31]);
let testDest = new Uint8ClampedArray(3 * 3 * 3);
const testSrc = new Uint8Array([27, 25, 50, 31]);
const testDest = new Uint8ClampedArray(3 * 3 * 3);
// prettier-ignore
let expectedDest = new Uint8ClampedArray([
const expectedDest = new Uint8ClampedArray([
226, 242, 241,
226, 242, 241,
229, 244, 242,

View file

@ -19,7 +19,7 @@ import { getDocument } from "../../src/display/api.js";
import { isNodeJS } from "../../src/shared/is_node.js";
function getTopLeftPixel(canvasContext) {
let imgData = canvasContext.getImageData(0, 0, 1, 1);
const imgData = canvasContext.getImageData(0, 0, 1, 1);
return {
r: imgData.data[0],
g: imgData.data[1],
@ -29,7 +29,9 @@ function getTopLeftPixel(canvasContext) {
}
describe("custom canvas rendering", function() {
let transparentGetDocumentParams = buildGetDocumentParams("transparent.pdf");
const transparentGetDocumentParams = buildGetDocumentParams(
"transparent.pdf"
);
let CanvasFactory;
let loadingTask;

View file

@ -86,7 +86,7 @@ describe("fetch_stream", function() {
);
const rangeReader2 = stream.getRangeReader(pdfLength - tailSize, pdfLength);
let result1 = { value: 0 },
const result1 = { value: 0 },
result2 = { value: 0 };
const read = function(reader, lenResult) {
return reader.read().then(function(result) {

View file

@ -31,9 +31,9 @@ describe("message_handler", function() {
describe("sendWithStream", function() {
it("should return a ReadableStream", function() {
let port = new LoopbackPort();
let messageHandler1 = new MessageHandler("main", "worker", port);
let readable = messageHandler1.sendWithStream("fakeHandler");
const port = new LoopbackPort();
const messageHandler1 = new MessageHandler("main", "worker", port);
const readable = messageHandler1.sendWithStream("fakeHandler");
// Check if readable is an instance of ReadableStream.
expect(typeof readable).toEqual("object");
expect(typeof readable.getReader).toEqual("function");
@ -41,9 +41,9 @@ describe("message_handler", function() {
it("should read using a reader", function(done) {
let log = "";
let port = new LoopbackPort();
let messageHandler1 = new MessageHandler("main", "worker", port);
let messageHandler2 = new MessageHandler("worker", "main", port);
const port = new LoopbackPort();
const messageHandler1 = new MessageHandler("main", "worker", port);
const messageHandler2 = new MessageHandler("worker", "main", port);
messageHandler2.on("fakeHandler", (data, sink) => {
sink.onPull = function() {
log += "p";
@ -61,7 +61,7 @@ describe("message_handler", function() {
});
return sleep(5);
});
let readable = messageHandler1.sendWithStream(
const readable = messageHandler1.sendWithStream(
"fakeHandler",
{},
{
@ -71,7 +71,7 @@ describe("message_handler", function() {
},
}
);
let reader = readable.getReader();
const reader = readable.getReader();
sleep(10)
.then(() => {
expect(log).toEqual("");
@ -95,8 +95,8 @@ describe("message_handler", function() {
it("should not read any data when cancelled", function(done) {
let log = "";
let port = new LoopbackPort();
let messageHandler2 = new MessageHandler("worker", "main", port);
const port = new LoopbackPort();
const messageHandler2 = new MessageHandler("worker", "main", port);
messageHandler2.on("fakeHandler", (data, sink) => {
sink.onPull = function() {
log += "p";
@ -126,8 +126,8 @@ describe("message_handler", function() {
}
);
});
let messageHandler1 = new MessageHandler("main", "worker", port);
let readable = messageHandler1.sendWithStream(
const messageHandler1 = new MessageHandler("main", "worker", port);
const readable = messageHandler1.sendWithStream(
"fakeHandler",
{},
{
@ -138,7 +138,7 @@ describe("message_handler", function() {
}
);
let reader = readable.getReader();
const reader = readable.getReader();
sleep(10)
.then(() => {
expect(log).toEqual("01");
@ -161,8 +161,8 @@ describe("message_handler", function() {
it("should not read when errored", function(done) {
let log = "";
let port = new LoopbackPort();
let messageHandler2 = new MessageHandler("worker", "main", port);
const port = new LoopbackPort();
const messageHandler2 = new MessageHandler("worker", "main", port);
messageHandler2.on("fakeHandler", (data, sink) => {
sink.onPull = function() {
log += "p";
@ -182,8 +182,8 @@ describe("message_handler", function() {
sink.error(new Error("should not read when errored"));
});
});
let messageHandler1 = new MessageHandler("main", "worker", port);
let readable = messageHandler1.sendWithStream(
const messageHandler1 = new MessageHandler("main", "worker", port);
const readable = messageHandler1.sendWithStream(
"fakeHandler",
{},
{
@ -194,7 +194,7 @@ describe("message_handler", function() {
}
);
let reader = readable.getReader();
const reader = readable.getReader();
sleep(10)
.then(() => {
@ -216,8 +216,8 @@ describe("message_handler", function() {
it("should read data with blocking promise", function(done) {
let log = "";
let port = new LoopbackPort();
let messageHandler2 = new MessageHandler("worker", "main", port);
const port = new LoopbackPort();
const messageHandler2 = new MessageHandler("worker", "main", port);
messageHandler2.on("fakeHandler", (data, sink) => {
sink.onPull = function() {
log += "p";
@ -242,8 +242,8 @@ describe("message_handler", function() {
});
});
let messageHandler1 = new MessageHandler("main", "worker", port);
let readable = messageHandler1.sendWithStream(
const messageHandler1 = new MessageHandler("main", "worker", port);
const readable = messageHandler1.sendWithStream(
"fakeHandler",
{},
{
@ -254,7 +254,7 @@ describe("message_handler", function() {
}
);
let reader = readable.getReader();
const reader = readable.getReader();
// Sleep for 10ms, so that read() is not unblocking the ready promise.
// Chain all read() to stream in sequence.
sleep(10)
@ -292,8 +292,8 @@ describe("message_handler", function() {
" into stream",
function(done) {
let log = "";
let port = new LoopbackPort();
let messageHandler2 = new MessageHandler("worker", "main", port);
const port = new LoopbackPort();
const messageHandler2 = new MessageHandler("worker", "main", port);
messageHandler2.on("fakeHandler", (data, sink) => {
sink.onPull = function() {
log += "p";
@ -319,8 +319,8 @@ describe("message_handler", function() {
return sleep(10);
});
let messageHandler1 = new MessageHandler("main", "worker", port);
let readable = messageHandler1.sendWithStream(
const messageHandler1 = new MessageHandler("main", "worker", port);
const readable = messageHandler1.sendWithStream(
"fakeHandler",
{},
{
@ -331,7 +331,7 @@ describe("message_handler", function() {
}
);
let reader = readable.getReader();
const reader = readable.getReader();
sleep(10)
.then(() => {
@ -366,9 +366,9 @@ describe("message_handler", function() {
it("should ignore any pull after close is called", function(done) {
let log = "";
let port = new LoopbackPort();
let capability = createPromiseCapability();
let messageHandler2 = new MessageHandler("worker", "main", port);
const port = new LoopbackPort();
const capability = createPromiseCapability();
const messageHandler2 = new MessageHandler("worker", "main", port);
messageHandler2.on("fakeHandler", (data, sink) => {
sink.onPull = function() {
log += "p";
@ -386,8 +386,8 @@ describe("message_handler", function() {
});
});
let messageHandler1 = new MessageHandler("main", "worker", port);
let readable = messageHandler1.sendWithStream(
const messageHandler1 = new MessageHandler("main", "worker", port);
const readable = messageHandler1.sendWithStream(
"fakeHandler",
{},
{
@ -398,7 +398,7 @@ describe("message_handler", function() {
}
);
let reader = readable.getReader();
const reader = readable.getReader();
sleep(10)
.then(() => {

View file

@ -21,26 +21,26 @@ import { PDFNodeStream } from "../../src/display/node_stream.js";
// Make sure that we only running this script is Node.js environments.
assert(isNodeJS);
let path = __non_webpack_require__("path");
let url = __non_webpack_require__("url");
let http = __non_webpack_require__("http");
let fs = __non_webpack_require__("fs");
const path = __non_webpack_require__("path");
const url = __non_webpack_require__("url");
const http = __non_webpack_require__("http");
const fs = __non_webpack_require__("fs");
describe("node_stream", function() {
let server = null;
let port = null;
let pdf = url.parse(
const pdf = url.parse(
encodeURI(
"file://" + path.join(process.cwd(), "./test/pdfs/tracemonkey.pdf")
)
).href;
let pdfLength = 1016315;
const pdfLength = 1016315;
beforeAll(done => {
// Create http server to serve pdf data for tests.
server = http
.createServer((request, response) => {
let filePath = process.cwd() + "/test/pdfs" + request.url;
const filePath = process.cwd() + "/test/pdfs" + request.url;
fs.lstat(filePath, (error, stat) => {
if (error) {
response.writeHead(404);
@ -48,8 +48,8 @@ describe("node_stream", function() {
return;
}
if (!request.headers["range"]) {
let contentLength = stat.size;
let stream = fs.createReadStream(filePath);
const contentLength = stat.size;
const stream = fs.createReadStream(filePath);
response.writeHead(200, {
"Content-Type": "application/pdf",
"Content-Length": contentLength,
@ -57,13 +57,13 @@ describe("node_stream", function() {
});
stream.pipe(response);
} else {
let [start, end] = request.headers["range"]
const [start, end] = request.headers["range"]
.split("=")[1]
.split("-")
.map(x => {
return Number(x);
});
let stream = fs.createReadStream(filePath, { start, end });
const stream = fs.createReadStream(filePath, { start, end });
response.writeHead(206, {
"Content-Type": "application/pdf",
});
@ -83,38 +83,38 @@ describe("node_stream", function() {
});
it("read both http(s) and filesystem pdf files", function(done) {
let stream1 = new PDFNodeStream({
const stream1 = new PDFNodeStream({
url: `http://127.0.0.1:${port}/tracemonkey.pdf`,
rangeChunkSize: 65536,
disableStream: true,
disableRange: true,
});
let stream2 = new PDFNodeStream({
const stream2 = new PDFNodeStream({
url: pdf,
rangeChunkSize: 65536,
disableStream: true,
disableRange: true,
});
let fullReader1 = stream1.getFullReader();
let fullReader2 = stream2.getFullReader();
const fullReader1 = stream1.getFullReader();
const fullReader2 = stream2.getFullReader();
let isStreamingSupported1, isRangeSupported1;
let promise1 = fullReader1.headersReady.then(() => {
const promise1 = fullReader1.headersReady.then(() => {
isStreamingSupported1 = fullReader1.isStreamingSupported;
isRangeSupported1 = fullReader1.isRangeSupported;
});
let isStreamingSupported2, isRangeSupported2;
let promise2 = fullReader2.headersReady.then(() => {
const promise2 = fullReader2.headersReady.then(() => {
isStreamingSupported2 = fullReader2.isStreamingSupported;
isRangeSupported2 = fullReader2.isRangeSupported;
});
let len1 = 0,
len2 = 0;
let read1 = function() {
const read1 = function() {
return fullReader1.read().then(function(result) {
if (result.done) {
return undefined;
@ -123,7 +123,7 @@ describe("node_stream", function() {
return read1();
});
};
let read2 = function() {
const read2 = function() {
return fullReader2.read().then(function(result) {
if (result.done) {
return undefined;
@ -133,7 +133,7 @@ describe("node_stream", function() {
});
};
let readPromise = Promise.all([read1(), read2(), promise1, promise2]);
const readPromise = Promise.all([read1(), read2(), promise1, promise2]);
readPromise
.then(result => {
expect(isStreamingSupported1).toEqual(false);
@ -150,15 +150,15 @@ describe("node_stream", function() {
});
it("read custom ranges for both http(s) and filesystem urls", function(done) {
let rangeSize = 32768;
let stream1 = new PDFNodeStream({
const rangeSize = 32768;
const stream1 = new PDFNodeStream({
url: `http://127.0.0.1:${port}/tracemonkey.pdf`,
length: pdfLength,
rangeChunkSize: rangeSize,
disableStream: true,
disableRange: false,
});
let stream2 = new PDFNodeStream({
const stream2 = new PDFNodeStream({
url: pdf,
length: pdfLength,
rangeChunkSize: rangeSize,
@ -166,13 +166,13 @@ describe("node_stream", function() {
disableRange: false,
});
let fullReader1 = stream1.getFullReader();
let fullReader2 = stream2.getFullReader();
const fullReader1 = stream1.getFullReader();
const fullReader2 = stream2.getFullReader();
let isStreamingSupported1, isRangeSupported1, fullReaderCancelled1;
let isStreamingSupported2, isRangeSupported2, fullReaderCancelled2;
let promise1 = fullReader1.headersReady.then(function() {
const promise1 = fullReader1.headersReady.then(function() {
isStreamingSupported1 = fullReader1.isStreamingSupported;
isRangeSupported1 = fullReader1.isRangeSupported;
// we shall be able to close the full reader without issues
@ -180,7 +180,7 @@ describe("node_stream", function() {
fullReaderCancelled1 = true;
});
let promise2 = fullReader2.headersReady.then(function() {
const promise2 = fullReader2.headersReady.then(function() {
isStreamingSupported2 = fullReader2.isStreamingSupported;
isRangeSupported2 = fullReader2.isRangeSupported;
fullReader2.cancel(new AbortException("Don't need fullReader2."));
@ -188,26 +188,32 @@ describe("node_stream", function() {
});
// Skipping fullReader results, requesting something from the PDF end.
let tailSize = pdfLength % rangeSize || rangeSize;
const tailSize = pdfLength % rangeSize || rangeSize;
let range11Reader = stream1.getRangeReader(
const range11Reader = stream1.getRangeReader(
pdfLength - tailSize - rangeSize,
pdfLength - tailSize
);
let range12Reader = stream1.getRangeReader(pdfLength - tailSize, pdfLength);
const range12Reader = stream1.getRangeReader(
pdfLength - tailSize,
pdfLength
);
let range21Reader = stream2.getRangeReader(
const range21Reader = stream2.getRangeReader(
pdfLength - tailSize - rangeSize,
pdfLength - tailSize
);
let range22Reader = stream2.getRangeReader(pdfLength - tailSize, pdfLength);
const range22Reader = stream2.getRangeReader(
pdfLength - tailSize,
pdfLength
);
let result11 = { value: 0 },
const result11 = { value: 0 },
result12 = { value: 0 };
let result21 = { value: 0 },
const result21 = { value: 0 },
result22 = { value: 0 };
let read = function(reader, lenResult) {
const read = function(reader, lenResult) {
return reader.read().then(function(result) {
if (result.done) {
return undefined;
@ -217,7 +223,7 @@ describe("node_stream", function() {
});
};
let readPromises = Promise.all([
const readPromises = Promise.all([
read(range11Reader, result11),
read(range12Reader, result12),
read(range21Reader, result21),

View file

@ -29,7 +29,7 @@ describe("pdf_history", function() {
false
);
let destArrayString = JSON.stringify([
const destArrayString = JSON.stringify([
{ num: 3757, gen: 0 },
{ name: "XYZ" },
92.918,
@ -51,11 +51,11 @@ describe("pdf_history", function() {
});
describe("isDestArraysEqual", function() {
let firstDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 0, 375, null];
let secondDest = [{ num: 5, gen: 0 }, { name: "XYZ" }, 0, 375, null];
let thirdDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 750, 0, null];
let fourthDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 0, 375, 1.0];
let fifthDest = [{ gen: 0, num: 1 }, { name: "XYZ" }, 0, 375, null];
const firstDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 0, 375, null];
const secondDest = [{ num: 5, gen: 0 }, { name: "XYZ" }, 0, 375, null];
const thirdDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 750, 0, null];
const fourthDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 0, 375, 1.0];
const fifthDest = [{ gen: 0, num: 1 }, { name: "XYZ" }, 0, 375, null];
it("should reject non-equal destination arrays", function() {
expect(isDestArraysEqual(firstDest, undefined)).toEqual(false);
@ -70,7 +70,7 @@ describe("pdf_history", function() {
expect(isDestArraysEqual(firstDest, firstDest)).toEqual(true);
expect(isDestArraysEqual(firstDest, fifthDest)).toEqual(true);
let firstDestCopy = firstDest.slice();
const firstDestCopy = firstDest.slice();
expect(firstDest).not.toBe(firstDestCopy);
expect(isDestArraysEqual(firstDest, firstDestCopy)).toEqual(true);

View file

@ -69,7 +69,7 @@ describe("stream", function() {
);
predictor.reset();
let clampedResult = predictor.getBytes(6, /* forceClamped = */ true);
const clampedResult = predictor.getBytes(6, /* forceClamped = */ true);
expect(clampedResult).toEqual(
new Uint8ClampedArray([100, 3, 101, 2, 102, 1])
);

View file

@ -50,13 +50,13 @@ const TEST_PDFS_PATH = {
};
function buildGetDocumentParams(filename, options) {
let params = Object.create(null);
const params = Object.create(null);
if (isNodeJS) {
params.url = TEST_PDFS_PATH.node + filename;
} else {
params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
}
for (let option in options) {
for (const option in options) {
params[option] = options[option];
}
return params;
@ -137,8 +137,8 @@ class XRefMock {
constructor(array) {
this._map = Object.create(null);
for (let key in array) {
let obj = array[key];
for (const key in array) {
const obj = array[key];
this._map[obj.ref.toString()] = obj.data;
}
}

View file

@ -449,7 +449,7 @@ describe("ui_utils", function() {
});
it("should reject invalid parameters", function(done) {
let invalidTarget = waitOnEventOrTimeout({
const invalidTarget = waitOnEventOrTimeout({
target: "window",
name: "DOMContentLoaded",
}).then(
@ -461,7 +461,7 @@ describe("ui_utils", function() {
}
);
let invalidName = waitOnEventOrTimeout({
const invalidName = waitOnEventOrTimeout({
target: eventBus,
name: "",
}).then(
@ -473,7 +473,7 @@ describe("ui_utils", function() {
}
);
let invalidDelay = waitOnEventOrTimeout({
const invalidDelay = waitOnEventOrTimeout({
target: eventBus,
name: "pagerendered",
delay: -1000,
@ -496,9 +496,9 @@ describe("ui_utils", function() {
if (isNodeJS) {
pending("Document in not supported in Node.js.");
}
let button = document.createElement("button");
const button = document.createElement("button");
let buttonClicked = waitOnEventOrTimeout({
const buttonClicked = waitOnEventOrTimeout({
target: button,
name: "click",
delay: 10000,
@ -516,9 +516,9 @@ describe("ui_utils", function() {
if (isNodeJS) {
pending("Document in not supported in Node.js.");
}
let button = document.createElement("button");
const button = document.createElement("button");
let buttonClicked = waitOnEventOrTimeout({
const buttonClicked = waitOnEventOrTimeout({
target: button,
name: "click",
delay: 10,
@ -532,7 +532,7 @@ describe("ui_utils", function() {
});
it("should resolve on event, using the EventBus", function(done) {
let pageRendered = waitOnEventOrTimeout({
const pageRendered = waitOnEventOrTimeout({
target: eventBus,
name: "pagerendered",
delay: 10000,
@ -547,7 +547,7 @@ describe("ui_utils", function() {
});
it("should resolve on timeout, using the EventBus", function(done) {
let pageRendered = waitOnEventOrTimeout({
const pageRendered = waitOnEventOrTimeout({
target: eventBus,
name: "pagerendered",
delay: 10,

View file

@ -48,14 +48,14 @@ describe("util", function() {
const length = 10000; // Larger than MAX_ARGUMENT_COUNT = 8192.
// Create an array with `length` 'a' character codes.
let bytes = new Uint8Array(length);
const bytes = new Uint8Array(length);
for (let i = 0; i < length; i++) {
bytes[i] = "a".charCodeAt(0);
}
// Create a string with `length` 'a' characters. We need an array of size
// `length + 1` since `join` puts the argument between the array elements.
let string = Array(length + 1).join("a");
const string = Array(length + 1).join("a");
expect(bytesToString(bytes)).toEqual(string);
});
@ -184,55 +184,55 @@ describe("util", function() {
describe("stringToPDFString", function() {
it("handles ISO Latin 1 strings", function() {
let str = "\x8Dstring\x8E";
const str = "\x8Dstring\x8E";
expect(stringToPDFString(str)).toEqual("\u201Cstring\u201D");
});
it("handles UTF-16 big-endian strings", function() {
let str = "\xFE\xFF\x00\x73\x00\x74\x00\x72\x00\x69\x00\x6E\x00\x67";
const str = "\xFE\xFF\x00\x73\x00\x74\x00\x72\x00\x69\x00\x6E\x00\x67";
expect(stringToPDFString(str)).toEqual("string");
});
it("handles UTF-16 little-endian strings", function() {
let str = "\xFF\xFE\x73\x00\x74\x00\x72\x00\x69\x00\x6E\x00\x67\x00";
const str = "\xFF\xFE\x73\x00\x74\x00\x72\x00\x69\x00\x6E\x00\x67\x00";
expect(stringToPDFString(str)).toEqual("string");
});
it("handles empty strings", function() {
// ISO Latin 1
let str1 = "";
const str1 = "";
expect(stringToPDFString(str1)).toEqual("");
// UTF-16BE
let str2 = "\xFE\xFF";
const str2 = "\xFE\xFF";
expect(stringToPDFString(str2)).toEqual("");
// UTF-16LE
let str3 = "\xFF\xFE";
const str3 = "\xFF\xFE";
expect(stringToPDFString(str3)).toEqual("");
});
});
describe("removeNullCharacters", function() {
it("should not modify string without null characters", function() {
let str = "string without null chars";
const str = "string without null chars";
expect(removeNullCharacters(str)).toEqual("string without null chars");
});
it("should modify string with null characters", function() {
let str = "string\x00With\x00Null\x00Chars";
const str = "string\x00With\x00Null\x00Chars";
expect(removeNullCharacters(str)).toEqual("stringWithNullChars");
});
});
describe("ReadableStream", function() {
it("should return an Object", function() {
let readable = new ReadableStream();
const readable = new ReadableStream();
expect(typeof readable).toEqual("object");
});
it("should have property getReader", function() {
let readable = new ReadableStream();
const readable = new ReadableStream();
expect(typeof readable.getReader).toEqual("function");
});
});