Merge pull request #12375 from Snuffleupagus/emptyDict-set
Ensure that the empty dictionary won't be accidentally modified, and slightly improve the "SaveDocument" handler in `src/core/worker.js`
This commit is contained in:
commit
374aad77c4
@ -171,7 +171,14 @@ var Dict = (function DictClosure() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Dict.empty = new Dict(null);
|
Dict.empty = (function () {
|
||||||
|
const emptyDict = new Dict(null);
|
||||||
|
|
||||||
|
emptyDict.set = (key, value) => {
|
||||||
|
unreachable("Should not call `set` on the empty dictionary.");
|
||||||
|
};
|
||||||
|
return emptyDict;
|
||||||
|
})();
|
||||||
|
|
||||||
Dict.merge = function ({ xref, dictArray, mergeSubDicts = false }) {
|
Dict.merge = function ({ xref, dictArray, mergeSubDicts = false }) {
|
||||||
const mergedDict = new Dict(xref);
|
const mergedDict = new Dict(xref);
|
||||||
|
@ -32,7 +32,7 @@ import {
|
|||||||
VerbosityLevel,
|
VerbosityLevel,
|
||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import { clearPrimitiveCaches, Dict, isDict, Ref } from "./primitives.js";
|
import { clearPrimitiveCaches, Dict, Ref } from "./primitives.js";
|
||||||
import { LocalPdfManager, NetworkPdfManager } from "./pdf_manager.js";
|
import { LocalPdfManager, NetworkPdfManager } from "./pdf_manager.js";
|
||||||
import { incrementalUpdate } from "./writer.js";
|
import { incrementalUpdate } from "./writer.js";
|
||||||
import { isNodeJS } from "../shared/is_node.js";
|
import { isNodeJS } from "../shared/is_node.js";
|
||||||
@ -548,8 +548,7 @@ class WorkerMessageHandler {
|
|||||||
return stream.bytes;
|
return stream.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
acroForm = isDict(acroForm) ? acroForm : Dict.empty;
|
const xfa = (acroForm instanceof Dict && acroForm.get("XFA")) || [];
|
||||||
const xfa = acroForm.get("XFA") || [];
|
|
||||||
let xfaDatasets = null;
|
let xfaDatasets = null;
|
||||||
if (Array.isArray(xfa)) {
|
if (Array.isArray(xfa)) {
|
||||||
for (let i = 0, ii = xfa.length; i < ii; i += 2) {
|
for (let i = 0, ii = xfa.length; i < ii; i += 2) {
|
||||||
@ -568,7 +567,7 @@ class WorkerMessageHandler {
|
|||||||
// Get string info from Info in order to compute fileId
|
// Get string info from Info in order to compute fileId
|
||||||
const _info = Object.create(null);
|
const _info = Object.create(null);
|
||||||
const xrefInfo = xref.trailer.get("Info") || null;
|
const xrefInfo = xref.trailer.get("Info") || null;
|
||||||
if (xrefInfo) {
|
if (xrefInfo instanceof Dict) {
|
||||||
xrefInfo.forEach((key, value) => {
|
xrefInfo.forEach((key, value) => {
|
||||||
if (isString(key) && isString(value)) {
|
if (isString(key) && isString(value)) {
|
||||||
_info[key] = stringToPDFString(value);
|
_info[key] = stringToPDFString(value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user