Skip to content

Commit f419699

Browse files
committed
Use a RefSet, rather than a plain Object, for tracking already processed nodes in PartialEvaluator.hasBlendModes
1 parent f20aeb9 commit f419699

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/core/evaluator.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
isStream,
4545
Name,
4646
Ref,
47+
RefSet,
4748
} from "./primitives.js";
4849
import {
4950
ErrorFont,
@@ -237,9 +238,9 @@ class PartialEvaluator {
237238
return false;
238239
}
239240

240-
var processed = Object.create(null);
241+
const processed = new RefSet();
241242
if (resources.objId) {
242-
processed[resources.objId] = true;
243+
processed.put(resources.objId);
243244
}
244245

245246
var nodes = [resources],
@@ -252,7 +253,7 @@ class PartialEvaluator {
252253
for (const key of graphicStates.getKeys()) {
253254
let graphicState = graphicStates.getRaw(key);
254255
if (graphicState instanceof Ref) {
255-
if (processed[graphicState.toString()]) {
256+
if (processed.has(graphicState)) {
256257
continue; // The ExtGState has already been processed.
257258
}
258259
try {
@@ -262,7 +263,7 @@ class PartialEvaluator {
262263
throw ex;
263264
}
264265
// Avoid parsing a corrupt ExtGState more than once.
265-
processed[graphicState.toString()] = true;
266+
processed.put(graphicState);
266267

267268
info(`hasBlendModes - ignoring ExtGState: "${ex}".`);
268269
continue;
@@ -272,7 +273,7 @@ class PartialEvaluator {
272273
continue;
273274
}
274275
if (graphicState.objId) {
275-
processed[graphicState.objId] = true;
276+
processed.put(graphicState.objId);
276277
}
277278

278279
const bm = graphicState.get("BM");
@@ -299,7 +300,7 @@ class PartialEvaluator {
299300
for (const key of xObjects.getKeys()) {
300301
var xObject = xObjects.getRaw(key);
301302
if (xObject instanceof Ref) {
302-
if (processed[xObject.toString()]) {
303+
if (processed.has(xObject)) {
303304
// The XObject has already been processed, and by avoiding a
304305
// redundant `xref.fetch` we can *significantly* reduce the load
305306
// time for badly generated PDF files (fixes issue6961.pdf).
@@ -312,7 +313,7 @@ class PartialEvaluator {
312313
throw ex;
313314
}
314315
// Avoid parsing a corrupt XObject more than once.
315-
processed[xObject.toString()] = true;
316+
processed.put(xObject);
316317

317318
info(`hasBlendModes - ignoring XObject: "${ex}".`);
318319
continue;
@@ -322,20 +323,20 @@ class PartialEvaluator {
322323
continue;
323324
}
324325
if (xObject.dict.objId) {
325-
processed[xObject.dict.objId] = true;
326+
processed.put(xObject.dict.objId);
326327
}
327328
var xResources = xObject.dict.get("Resources");
328329
if (!(xResources instanceof Dict)) {
329330
continue;
330331
}
331332
// Checking objId to detect an infinite loop.
332-
if (xResources.objId && processed[xResources.objId]) {
333+
if (xResources.objId && processed.has(xResources)) {
333334
continue;
334335
}
335336

336337
nodes.push(xResources);
337338
if (xResources.objId) {
338-
processed[xResources.objId] = true;
339+
processed.put(xResources.objId);
339340
}
340341
}
341342
}

0 commit comments

Comments
 (0)