Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 11 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 29 additions & 26 deletions src/core/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,46 @@ const nonSerializable = function nonSerializableClosure() {
};

class Dict {
__nonSerializable__ = nonSerializable; // Disable cloning of the Dict.

#map = new Map();

objId = null;

suppressEncryption = false;

xref;

constructor(xref = null) {
// Map should only be used internally, use functions below to access.
this._map = new Map();
this.xref = xref;
this.objId = null;
this.suppressEncryption = false;
this.__nonSerializable__ = nonSerializable; // Disable cloning of the Dict.
}

assignXref(newXref) {
this.xref = newXref;
}

get size() {
return this._map.size;
return this.#map.size;
}

#getValue(isAsync, key1, key2, key3) {
let value = this._map.get(key1);
let value = this.#map.get(key1);
if (value === undefined && key2 !== undefined) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
key2.length < key1.length
) {
unreachable("Dict.#getValue: Expected keys to be ordered by length.");
}
value = this._map.get(key2);
value = this.#map.get(key2);
if (value === undefined && key3 !== undefined) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
key3.length < key2.length
) {
unreachable("Dict.#getValue: Expected keys to be ordered by length.");
}
value = this._map.get(key3);
value = this.#map.get(key3);
}
}
if (value instanceof Ref && this.xref) {
Expand Down Expand Up @@ -139,20 +144,20 @@ class Dict {

// No dereferencing.
getRaw(key) {
return this._map.get(key);
return this.#map.get(key);
}

getKeys() {
return this._map.keys();
return this.#map.keys();
}

// No dereferencing.
getRawValues() {
return this._map.values();
return this.#map.values();
}

getRawEntries() {
return this._map.entries();
return this.#map.entries();
}

set(key, value) {
Expand All @@ -163,7 +168,7 @@ class Dict {
unreachable('Dict.set: The "value" cannot be undefined.');
}
}
this._map.set(key, value);
this.#map.set(key, value);
}

setIfNotExists(key, value) {
Expand Down Expand Up @@ -205,11 +210,11 @@ class Dict {
}

has(key) {
return this._map.has(key);
return this.#map.has(key);
}

*[Symbol.iterator]() {
for (const [key, value] of this._map) {
for (const [key, value] of this.#map) {
yield [
key,
value instanceof Ref && this.xref
Expand All @@ -236,7 +241,7 @@ class Dict {
if (!(dict instanceof Dict)) {
continue;
}
for (const [key, value] of dict._map) {
for (const [key, value] of dict.getRawEntries()) {
let property = properties.get(key);
if (property === undefined) {
property = [];
Expand All @@ -252,20 +257,18 @@ class Dict {
}
for (const [name, values] of properties) {
if (values.length === 1 || !(values[0] instanceof Dict)) {
mergedDict._map.set(name, values[0]);
mergedDict.set(name, values[0]);
continue;
}
const subDict = new Dict(xref);

for (const dict of values) {
for (const [key, value] of dict._map) {
if (!subDict._map.has(key)) {
subDict._map.set(key, value);
}
for (const [key, value] of dict.getRawEntries()) {
subDict.setIfNotExists(key, value);
}
}
if (subDict.size > 0) {
mergedDict._map.set(name, subDict);
mergedDict.set(name, subDict);
}
}
properties.clear();
Expand All @@ -275,14 +278,14 @@ class Dict {

clone() {
const dict = new Dict(this.xref);
for (const [key, rawVal] of this.getRawEntries()) {
dict.set(key, rawVal);
for (const [key, value] of this.#map) {
dict.set(key, value);
}
return dict;
}

delete(key) {
this._map.delete(key);
this.#map.delete(key);
}
}

Expand Down
Loading
Loading