Guard against adding a structure element to more than one parent.

This commit is contained in:
Ben Schmidt 2020-11-04 01:40:31 +11:00 committed by Luiz Américo
parent 2ed3782473
commit 4c4a49ebff
2 changed files with 10 additions and 1 deletions

View File

@ -10,7 +10,6 @@ class PDFStructureElement {
this.document = document;
this._ended = false;
this._flushed = false;
this.dictionary = document.ref({
// Type: "StructElem",
S: type
@ -92,6 +91,10 @@ class PDFStructureElement {
}
setParent(parentRef) {
if (this.dictionary.data.P) {
throw new Error(`Structure element added to more than one parent`);
}
this.dictionary.data.P = parentRef;
if (this._ended) {

View File

@ -426,6 +426,12 @@ EMC
struct.add(document.struct('Bar'));
}).toThrow();
struct = document.struct('Foo');
let parent = document.struct('Bar').add(struct);
expect(() => {
parent.add(struct);
}).toThrow();
expect(() => {
document.struct('Foo', [1]);
}).toThrow();