1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #12758 from Snuffleupagus/AnnotationStorage-rm-event

Run `AnnotationStorage.resetModified` when destroying the `PDFDocumentLoadingTask`/`PDFDocumentProxy`
This commit is contained in:
Tim van der Meij 2020-12-19 21:13:28 +01:00 committed by GitHub
commit 1c8ead133a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 20 deletions

View file

@ -2127,6 +2127,10 @@ class WorkerTransport {
this.setupMessageHandler();
}
get loadingTaskSettled() {
return this.loadingTask._capability.settled;
}
destroy() {
if (this.destroyCapability) {
return this.destroyCapability.promise;
@ -2154,6 +2158,18 @@ class WorkerTransport {
// We also need to wait for the worker to finish its long running tasks.
const terminated = this.messageHandler.sendWithPromise("Terminate", null);
waitOn.push(terminated);
// Allow `AnnotationStorage`-related clean-up when destroying the document.
if (this.loadingTaskSettled) {
const annotationStorageResetModified = this.loadingTask.promise
.then(pdfDocument => {
// Avoid initializing the `annotationStorage` if it doesn't exist.
if (pdfDocument.hasOwnProperty("annotationStorage")) {
pdfDocument.annotationStorage.resetModified();
}
})
.catch(() => {});
waitOn.push(annotationStorageResetModified);
}
Promise.all(waitOn).then(() => {
this.commonObjs.clear();
this.fontLoader.clear();