mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Change the signature of the Parser
constructor to take a parameter object
A lot of the `new Parser()` call-sites look quite unwieldy/ugly as-is, with a bunch of somewhat randomly ordered arguments, which we can avoid by changing the constructor to accept an object instead. As an added bonus, this provides better documentation without having to add inline argument comments in the code.
This commit is contained in:
parent
1c9a69db82
commit
f710eb56e4
5 changed files with 53 additions and 21 deletions
|
@ -2960,7 +2960,10 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||
this.opMap = getOPMap();
|
||||
// TODO(mduan): pass array of knownCommands rather than this.opMap
|
||||
// dictionary
|
||||
this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
|
||||
this.parser = new Parser({
|
||||
lexer: new Lexer(stream, this.opMap),
|
||||
xref,
|
||||
});
|
||||
this.stateManager = stateManager;
|
||||
this.nonProcessedArgs = [];
|
||||
this._numInvalidPathOPS = 0;
|
||||
|
|
|
@ -1477,8 +1477,12 @@ var XRef = (function XRefClosure() {
|
|||
let trailerDict;
|
||||
for (i = 0, ii = trailers.length; i < ii; ++i) {
|
||||
stream.pos = trailers[i];
|
||||
var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
|
||||
/* xref = */ this, /* recoveryMode = */ true);
|
||||
const parser = new Parser({
|
||||
lexer: new Lexer(stream),
|
||||
xref: this,
|
||||
allowStreams: true,
|
||||
recoveryMode: true,
|
||||
});
|
||||
var obj = parser.getObj();
|
||||
if (!isCmd(obj, 'trailer')) {
|
||||
continue;
|
||||
|
@ -1536,7 +1540,11 @@ var XRef = (function XRefClosure() {
|
|||
|
||||
stream.pos = startXRef + stream.start;
|
||||
|
||||
var parser = new Parser(new Lexer(stream), true, this);
|
||||
const parser = new Parser({
|
||||
lexer: new Lexer(stream),
|
||||
xref: this,
|
||||
allowStreams: true,
|
||||
});
|
||||
var obj = parser.getObj();
|
||||
var dict;
|
||||
|
||||
|
@ -1662,7 +1670,11 @@ var XRef = (function XRefClosure() {
|
|||
}
|
||||
var stream = this.stream.makeSubStream(xrefEntry.offset +
|
||||
this.stream.start);
|
||||
var parser = new Parser(new Lexer(stream), true, this);
|
||||
const parser = new Parser({
|
||||
lexer: new Lexer(stream),
|
||||
xref: this,
|
||||
allowStreams: true,
|
||||
});
|
||||
var obj1 = parser.getObj();
|
||||
var obj2 = parser.getObj();
|
||||
var obj3 = parser.getObj();
|
||||
|
@ -1709,8 +1721,11 @@ var XRef = (function XRefClosure() {
|
|||
throw new FormatError(
|
||||
'invalid first and n parameters for ObjStm stream');
|
||||
}
|
||||
var parser = new Parser(new Lexer(stream), false, this);
|
||||
parser.allowStreams = true;
|
||||
const parser = new Parser({
|
||||
lexer: new Lexer(stream),
|
||||
xref: this,
|
||||
allowStreams: true,
|
||||
});
|
||||
var i, entries = [], num, nums = [];
|
||||
// read the object numbers to populate cache
|
||||
for (i = 0; i < n; ++i) {
|
||||
|
|
|
@ -51,10 +51,10 @@ function computeAdler32(bytes) {
|
|||
}
|
||||
|
||||
class Parser {
|
||||
constructor(lexer, allowStreams, xref, recoveryMode = false) {
|
||||
constructor({ lexer, xref, allowStreams = false, recoveryMode = false, }) {
|
||||
this.lexer = lexer;
|
||||
this.allowStreams = allowStreams;
|
||||
this.xref = xref;
|
||||
this.allowStreams = allowStreams;
|
||||
this.recoveryMode = recoveryMode;
|
||||
|
||||
this.imageCache = Object.create(null);
|
||||
|
@ -748,7 +748,7 @@ function toHexDigit(ch) {
|
|||
}
|
||||
|
||||
class Lexer {
|
||||
constructor(stream, knownCommands) {
|
||||
constructor(stream, knownCommands = null) {
|
||||
this.stream = stream;
|
||||
this.nextChar();
|
||||
|
||||
|
@ -1202,7 +1202,10 @@ class Linearization {
|
|||
throw new Error('Hint array in the linearization dictionary is invalid.');
|
||||
}
|
||||
|
||||
const parser = new Parser(new Lexer(stream), false, null);
|
||||
const parser = new Parser({
|
||||
lexer: new Lexer(stream),
|
||||
xref: null,
|
||||
});
|
||||
const obj1 = parser.getObj();
|
||||
const obj2 = parser.getObj();
|
||||
const obj3 = parser.getObj();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue