mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Remove the isEOF
helper function and slightly re-factor EOF
Given how trivial the `isEOF` function is, we can simply inline the check at the various call-sites and remove the function (which ought to be ever so slightly more efficient as well). Furthermore, this patch also changes the `EOF` primitive itself to a `Symbol` instead of an Object since that has the nice benefit of making it unclonable (thus preventing *accidentally* trying to send `EOF` from the worker-thread).
This commit is contained in:
parent
0b95d698d8
commit
766299016f
4 changed files with 16 additions and 35 deletions
|
@ -28,7 +28,6 @@ import {
|
|||
EOF,
|
||||
isCmd,
|
||||
isDict,
|
||||
isEOF,
|
||||
isName,
|
||||
Name,
|
||||
Ref,
|
||||
|
@ -124,10 +123,10 @@ class Parser {
|
|||
return this.makeInlineImage(cipherTransform);
|
||||
case "[": // array
|
||||
const array = [];
|
||||
while (!isCmd(this.buf1, "]") && !isEOF(this.buf1)) {
|
||||
while (!isCmd(this.buf1, "]") && this.buf1 !== EOF) {
|
||||
array.push(this.getObj(cipherTransform));
|
||||
}
|
||||
if (isEOF(this.buf1)) {
|
||||
if (this.buf1 === EOF) {
|
||||
if (this.recoveryMode) {
|
||||
return array;
|
||||
}
|
||||
|
@ -137,7 +136,7 @@ class Parser {
|
|||
return array;
|
||||
case "<<": // dictionary or stream
|
||||
const dict = new Dict(this.xref);
|
||||
while (!isCmd(this.buf1, ">>") && !isEOF(this.buf1)) {
|
||||
while (!isCmd(this.buf1, ">>") && this.buf1 !== EOF) {
|
||||
if (!isName(this.buf1)) {
|
||||
info("Malformed dictionary: key must be a name object");
|
||||
this.shift();
|
||||
|
@ -146,12 +145,12 @@ class Parser {
|
|||
|
||||
const key = this.buf1.name;
|
||||
this.shift();
|
||||
if (isEOF(this.buf1)) {
|
||||
if (this.buf1 === EOF) {
|
||||
break;
|
||||
}
|
||||
dict.set(key, this.getObj(cipherTransform));
|
||||
}
|
||||
if (isEOF(this.buf1)) {
|
||||
if (this.buf1 === EOF) {
|
||||
if (this.recoveryMode) {
|
||||
return dict;
|
||||
}
|
||||
|
@ -498,13 +497,13 @@ class Parser {
|
|||
// Parse dictionary.
|
||||
const dict = new Dict(this.xref);
|
||||
let dictLength;
|
||||
while (!isCmd(this.buf1, "ID") && !isEOF(this.buf1)) {
|
||||
while (!isCmd(this.buf1, "ID") && this.buf1 !== EOF) {
|
||||
if (!isName(this.buf1)) {
|
||||
throw new FormatError("Dictionary key must be a name object");
|
||||
}
|
||||
const key = this.buf1.name;
|
||||
this.shift();
|
||||
if (isEOF(this.buf1)) {
|
||||
if (this.buf1 === EOF) {
|
||||
break;
|
||||
}
|
||||
dict.set(key, this.getObj(cipherTransform));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue