Enable the no-var
rule in the src/core/xref.js
file
This commit is contained in:
parent
bc828cd41f
commit
088a55f80d
117
src/core/xref.js
117
src/core/xref.js
@ -12,7 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable no-var */
|
||||
|
||||
import {
|
||||
assert,
|
||||
@ -71,7 +70,7 @@ class XRef {
|
||||
}
|
||||
|
||||
parse(recoveryMode = false) {
|
||||
var trailerDict;
|
||||
let trailerDict;
|
||||
if (!recoveryMode) {
|
||||
trailerDict = this.readXRef();
|
||||
} else {
|
||||
@ -91,8 +90,8 @@ class XRef {
|
||||
warn(`XRef.parse - Invalid "Encrypt" reference: "${ex}".`);
|
||||
}
|
||||
if (isDict(encrypt)) {
|
||||
var ids = trailerDict.get("ID");
|
||||
var fileId = ids && ids.length ? ids[0] : "";
|
||||
const ids = trailerDict.get("ID");
|
||||
const fileId = ids && ids.length ? ids[0] : "";
|
||||
// The 'Encrypt' dictionary itself should not be encrypted, and by
|
||||
// setting `suppressEncryption` we can prevent an infinite loop inside
|
||||
// of `XRef_fetchUncompressed` if the dictionary contains indirect
|
||||
@ -137,7 +136,7 @@ class XRef {
|
||||
};
|
||||
}
|
||||
|
||||
var obj = this.readXRefTable(parser);
|
||||
const obj = this.readXRefTable(parser);
|
||||
|
||||
// Sanity check
|
||||
if (!isCmd(obj, "trailer")) {
|
||||
@ -154,7 +153,7 @@ class XRef {
|
||||
// >>
|
||||
// The parser goes through the entire stream << ... >> and provides
|
||||
// a getter interface for the key-value table
|
||||
var dict = parser.getObj();
|
||||
let dict = parser.getObj();
|
||||
|
||||
// The pdflib PDF generator can generate a nested trailer dictionary
|
||||
if (!isDict(dict) && dict.dict) {
|
||||
@ -181,14 +180,14 @@ class XRef {
|
||||
// trailer
|
||||
// ...
|
||||
|
||||
var stream = parser.lexer.stream;
|
||||
var tableState = this.tableState;
|
||||
const stream = parser.lexer.stream;
|
||||
const tableState = this.tableState;
|
||||
stream.pos = tableState.streamPos;
|
||||
parser.buf1 = tableState.parserBuf1;
|
||||
parser.buf2 = tableState.parserBuf2;
|
||||
|
||||
// Outer loop is over subsection headers
|
||||
var obj;
|
||||
let obj;
|
||||
|
||||
while (true) {
|
||||
if (!("firstEntryNum" in tableState) || !("entryCount" in tableState)) {
|
||||
@ -199,24 +198,24 @@ class XRef {
|
||||
tableState.entryCount = parser.getObj();
|
||||
}
|
||||
|
||||
var first = tableState.firstEntryNum;
|
||||
var count = tableState.entryCount;
|
||||
let first = tableState.firstEntryNum;
|
||||
const count = tableState.entryCount;
|
||||
if (!Number.isInteger(first) || !Number.isInteger(count)) {
|
||||
throw new FormatError(
|
||||
"Invalid XRef table: wrong types in subsection header"
|
||||
);
|
||||
}
|
||||
// Inner loop is over objects themselves
|
||||
for (var i = tableState.entryNum; i < count; i++) {
|
||||
for (let i = tableState.entryNum; i < count; i++) {
|
||||
tableState.streamPos = stream.pos;
|
||||
tableState.entryNum = i;
|
||||
tableState.parserBuf1 = parser.buf1;
|
||||
tableState.parserBuf2 = parser.buf2;
|
||||
|
||||
var entry = {};
|
||||
const entry = {};
|
||||
entry.offset = parser.getObj();
|
||||
entry.gen = parser.getObj();
|
||||
var type = parser.getObj();
|
||||
const type = parser.getObj();
|
||||
|
||||
if (type instanceof Cmd) {
|
||||
switch (type.cmd) {
|
||||
@ -270,9 +269,9 @@ class XRef {
|
||||
if (!("streamState" in this)) {
|
||||
// Stores state of the stream as we process it so we can resume
|
||||
// from middle of stream in case of missing data error
|
||||
var streamParameters = stream.dict;
|
||||
var byteWidths = streamParameters.get("W");
|
||||
var range = streamParameters.get("Index");
|
||||
const streamParameters = stream.dict;
|
||||
const byteWidths = streamParameters.get("W");
|
||||
let range = streamParameters.get("Index");
|
||||
if (!range) {
|
||||
range = [0, streamParameters.get("Size")];
|
||||
}
|
||||
@ -291,19 +290,19 @@ class XRef {
|
||||
}
|
||||
|
||||
readXRefStream(stream) {
|
||||
var i, j;
|
||||
var streamState = this.streamState;
|
||||
let i, j;
|
||||
const streamState = this.streamState;
|
||||
stream.pos = streamState.streamPos;
|
||||
|
||||
var byteWidths = streamState.byteWidths;
|
||||
var typeFieldWidth = byteWidths[0];
|
||||
var offsetFieldWidth = byteWidths[1];
|
||||
var generationFieldWidth = byteWidths[2];
|
||||
const byteWidths = streamState.byteWidths;
|
||||
const typeFieldWidth = byteWidths[0];
|
||||
const offsetFieldWidth = byteWidths[1];
|
||||
const generationFieldWidth = byteWidths[2];
|
||||
|
||||
var entryRanges = streamState.entryRanges;
|
||||
const entryRanges = streamState.entryRanges;
|
||||
while (entryRanges.length > 0) {
|
||||
var first = entryRanges[0];
|
||||
var n = entryRanges[1];
|
||||
const first = entryRanges[0];
|
||||
const n = entryRanges[1];
|
||||
|
||||
if (!Number.isInteger(first) || !Number.isInteger(n)) {
|
||||
throw new FormatError(`Invalid XRef range fields: ${first}, ${n}`);
|
||||
@ -321,7 +320,7 @@ class XRef {
|
||||
streamState.entryNum = i;
|
||||
streamState.streamPos = stream.pos;
|
||||
|
||||
var type = 0,
|
||||
let type = 0,
|
||||
offset = 0,
|
||||
generation = 0;
|
||||
for (j = 0; j < typeFieldWidth; ++j) {
|
||||
@ -337,7 +336,7 @@ class XRef {
|
||||
for (j = 0; j < generationFieldWidth; ++j) {
|
||||
generation = (generation << 8) | stream.getByte();
|
||||
}
|
||||
var entry = {};
|
||||
const entry = {};
|
||||
entry.offset = offset;
|
||||
entry.gen = generation;
|
||||
switch (type) {
|
||||
@ -366,15 +365,15 @@ class XRef {
|
||||
indexObjects() {
|
||||
// Simple scan through the PDF content to find objects,
|
||||
// trailers and XRef streams.
|
||||
var TAB = 0x9,
|
||||
const TAB = 0x9,
|
||||
LF = 0xa,
|
||||
CR = 0xd,
|
||||
SPACE = 0x20;
|
||||
var PERCENT = 0x25,
|
||||
const PERCENT = 0x25,
|
||||
LT = 0x3c;
|
||||
|
||||
function readToken(data, offset) {
|
||||
var token = "",
|
||||
let token = "",
|
||||
ch = data[offset];
|
||||
while (ch !== LF && ch !== CR && ch !== LT) {
|
||||
if (++offset >= data.length) {
|
||||
@ -386,12 +385,12 @@ class XRef {
|
||||
return token;
|
||||
}
|
||||
function skipUntil(data, offset, what) {
|
||||
var length = what.length,
|
||||
const length = what.length,
|
||||
dataLength = data.length;
|
||||
var skipped = 0;
|
||||
let skipped = 0;
|
||||
// finding byte sequence
|
||||
while (offset < dataLength) {
|
||||
var i = 0;
|
||||
let i = 0;
|
||||
while (i < length && data[offset + i] === what[i]) {
|
||||
++i;
|
||||
}
|
||||
@ -403,30 +402,30 @@ class XRef {
|
||||
}
|
||||
return skipped;
|
||||
}
|
||||
var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
|
||||
const objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
|
||||
const endobjRegExp = /\bendobj[\b\s]$/;
|
||||
const nestedObjRegExp = /\s+(\d+\s+\d+\s+obj[\b\s<])$/;
|
||||
const CHECK_CONTENT_LENGTH = 25;
|
||||
|
||||
var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
|
||||
const trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
|
||||
// prettier-ignore
|
||||
var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
|
||||
const startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
|
||||
101, 102]);
|
||||
const objBytes = new Uint8Array([111, 98, 106]);
|
||||
var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
|
||||
const xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
|
||||
|
||||
// Clear out any existing entries, since they may be bogus.
|
||||
this.entries.length = 0;
|
||||
|
||||
var stream = this.stream;
|
||||
const stream = this.stream;
|
||||
stream.pos = 0;
|
||||
var buffer = stream.getBytes();
|
||||
var position = stream.start,
|
||||
const buffer = stream.getBytes(),
|
||||
length = buffer.length;
|
||||
var trailers = [],
|
||||
let position = stream.start;
|
||||
const trailers = [],
|
||||
xrefStms = [];
|
||||
while (position < length) {
|
||||
var ch = buffer[position];
|
||||
let ch = buffer[position];
|
||||
if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
|
||||
++position;
|
||||
continue;
|
||||
@ -442,8 +441,8 @@ class XRef {
|
||||
} while (ch !== LF && ch !== CR);
|
||||
continue;
|
||||
}
|
||||
var token = readToken(buffer, position);
|
||||
var m;
|
||||
const token = readToken(buffer, position);
|
||||
let m;
|
||||
if (
|
||||
token.startsWith("xref") &&
|
||||
(token.length === 4 || /\s/.test(token[4]))
|
||||
@ -497,7 +496,7 @@ class XRef {
|
||||
|
||||
// checking XRef stream suspect
|
||||
// (it shall have '/XRef' and next char is not a letter)
|
||||
var xrefTagOffset = skipUntil(content, 0, xrefBytes);
|
||||
const xrefTagOffset = skipUntil(content, 0, xrefBytes);
|
||||
if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
|
||||
xrefStms.push(position - stream.start);
|
||||
this.xrefstms[position - stream.start] = 1; // Avoid recursion
|
||||
@ -529,7 +528,7 @@ class XRef {
|
||||
allowStreams: true,
|
||||
recoveryMode: true,
|
||||
});
|
||||
var obj = parser.getObj();
|
||||
const obj = parser.getObj();
|
||||
if (!isCmd(obj, "trailer")) {
|
||||
continue;
|
||||
}
|
||||
@ -572,7 +571,7 @@ class XRef {
|
||||
}
|
||||
|
||||
readXRef(recoveryMode = false) {
|
||||
var stream = this.stream;
|
||||
const stream = this.stream;
|
||||
// Keep track of already parsed XRef tables, to prevent an infinite loop
|
||||
// when parsing corrupt PDF files where e.g. the /Prev entries create a
|
||||
// circular dependency between tables (fixes bug1393476.pdf).
|
||||
@ -580,7 +579,7 @@ class XRef {
|
||||
|
||||
try {
|
||||
while (this.startXRefQueue.length) {
|
||||
var startXRef = this.startXRefQueue[0];
|
||||
const startXRef = this.startXRefQueue[0];
|
||||
|
||||
if (startXRefParsedCache.has(startXRef)) {
|
||||
warn("readXRef - skipping XRef table since it was already parsed.");
|
||||
@ -596,8 +595,8 @@ class XRef {
|
||||
xref: this,
|
||||
allowStreams: true,
|
||||
});
|
||||
var obj = parser.getObj();
|
||||
var dict;
|
||||
let obj = parser.getObj();
|
||||
let dict;
|
||||
|
||||
// Get dictionary
|
||||
if (isCmd(obj, "xref")) {
|
||||
@ -610,7 +609,7 @@ class XRef {
|
||||
// Recursively get other XRefs 'XRefStm', if any
|
||||
obj = dict.get("XRefStm");
|
||||
if (Number.isInteger(obj)) {
|
||||
var pos = obj;
|
||||
const pos = obj;
|
||||
// ignore previously loaded xref streams
|
||||
// (possible infinite recursion)
|
||||
if (!(pos in this.xrefstms)) {
|
||||
@ -666,7 +665,7 @@ class XRef {
|
||||
}
|
||||
|
||||
getEntry(i) {
|
||||
var xrefEntry = this.entries[i];
|
||||
const xrefEntry = this.entries[i];
|
||||
if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
|
||||
return xrefEntry;
|
||||
}
|
||||
@ -720,12 +719,12 @@ class XRef {
|
||||
}
|
||||
|
||||
fetchUncompressed(ref, xrefEntry, suppressEncryption = false) {
|
||||
var gen = ref.gen;
|
||||
var num = ref.num;
|
||||
const gen = ref.gen;
|
||||
let num = ref.num;
|
||||
if (xrefEntry.gen !== gen) {
|
||||
throw new XRefEntryException(`Inconsistent generation in XRef: ${ref}`);
|
||||
}
|
||||
var stream = this.stream.makeSubStream(
|
||||
const stream = this.stream.makeSubStream(
|
||||
xrefEntry.offset + this.stream.start
|
||||
);
|
||||
const parser = new Parser({
|
||||
@ -733,9 +732,9 @@ class XRef {
|
||||
xref: this,
|
||||
allowStreams: true,
|
||||
});
|
||||
var obj1 = parser.getObj();
|
||||
var obj2 = parser.getObj();
|
||||
var obj3 = parser.getObj();
|
||||
const obj1 = parser.getObj();
|
||||
const obj2 = parser.getObj();
|
||||
const obj3 = parser.getObj();
|
||||
|
||||
if (obj1 !== num || obj2 !== gen || !(obj3 instanceof Cmd)) {
|
||||
throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user