1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15: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:
Jonas Jenwald 2019-06-23 16:01:45 +02:00
parent 1c9a69db82
commit f710eb56e4
5 changed files with 53 additions and 21 deletions

View file

@ -409,8 +409,10 @@ describe('annotation', function() {
'/URI (http://www.example.com/\\303\\274\\303\\266\\303\\244)\n' +
'>>\n'
);
const lexer = new Lexer(actionStream);
const parser = new Parser(lexer);
const parser = new Parser({
lexer: new Lexer(actionStream),
xref: null,
});
const actionDict = parser.getObj();
const annotationDict = new Dict();
@ -1412,8 +1414,11 @@ describe('annotation', function() {
'Test attachment' +
'endstream\n'
);
const lexer = new Lexer(fileStream);
const parser = new Parser(lexer, /* allowStreams = */ true);
const parser = new Parser({
lexer: new Lexer(fileStream),
xref: null,
allowStreams: true,
});
const fileStreamRef = Ref.get(18, 0);
const fileStreamDict = parser.getObj();

View file

@ -26,9 +26,12 @@ describe('parser', function() {
const string = 'q 1 0 0 1 0 0 cm BI /W 10 /H 10 /BPC 1 ' +
'/F /A85 ID abc123~> EI Q';
const input = new StringStream(string);
const lexer = new Lexer(input);
const parser = new Parser(lexer, /* allowStreams = */ true,
/* xref = */ null);
const parser = new Parser({
lexer: new Lexer(input),
xref: null,
allowStreams: true,
});
parser.inlineStreamSkipEI(input);
expect(input.pos).toEqual(string.indexOf('Q'));
expect(input.peekByte()).toEqual(0x51); // 'Q'
@ -39,9 +42,12 @@ describe('parser', function() {
const string = 'q 1 0 0 1 0 0 cm BI /W 10 /H 10 /BPC 1 ' +
'/F /A85 ID abc123~> Q';
const input = new StringStream(string);
const lexer = new Lexer(input);
const parser = new Parser(lexer, /* allowStreams = */ true,
/* xref = */ null);
const parser = new Parser({
lexer: new Lexer(input),
xref: null,
allowStreams: true,
});
parser.inlineStreamSkipEI(input);
expect(input.pos).toEqual(string.length);
expect(input.peekByte()).toEqual(-1);