Move destroying of the scripting-instance from PDFViewerApplication.close
and into its own helper method
Since the `close` method has become quite large, this small re-factoring shouldn't hurt (and may also be useful with future changes to the `_initializeJavaScript` method).
This commit is contained in:
parent
8d72981c18
commit
6c807f3f86
38
web/app.js
38
web/app.js
@ -776,6 +776,26 @@ const PDFViewerApplication = {
|
|||||||
this._idleCallbacks.clear();
|
this._idleCallbacks.clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
async _destroyScriptingInstance() {
|
||||||
|
if (!this._scriptingInstance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { scripting, events } = this._scriptingInstance;
|
||||||
|
try {
|
||||||
|
await scripting.destroySandbox();
|
||||||
|
} catch (ex) {}
|
||||||
|
|
||||||
|
for (const [name, listener] of events) {
|
||||||
|
window.removeEventListener(name, listener);
|
||||||
|
}
|
||||||
|
events.clear();
|
||||||
|
|
||||||
|
this._scriptingInstance = null;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes opened PDF document.
|
* Closes opened PDF document.
|
||||||
* @returns {Promise} - Returns the promise, which is resolved when all
|
* @returns {Promise} - Returns the promise, which is resolved when all
|
||||||
@ -788,8 +808,9 @@ const PDFViewerApplication = {
|
|||||||
if (!this.pdfLoadingTask) {
|
if (!this.pdfLoadingTask) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
const promise = this.pdfLoadingTask.destroy();
|
promises.push(this.pdfLoadingTask.destroy());
|
||||||
this.pdfLoadingTask = null;
|
this.pdfLoadingTask = null;
|
||||||
|
|
||||||
if (this.pdfDocument) {
|
if (this.pdfDocument) {
|
||||||
@ -814,18 +835,7 @@ const PDFViewerApplication = {
|
|||||||
this._saveInProgress = false;
|
this._saveInProgress = false;
|
||||||
|
|
||||||
this._cancelIdleCallbacks();
|
this._cancelIdleCallbacks();
|
||||||
|
promises.push(this._destroyScriptingInstance());
|
||||||
if (this._scriptingInstance) {
|
|
||||||
const { scripting, events } = this._scriptingInstance;
|
|
||||||
try {
|
|
||||||
scripting.destroySandbox();
|
|
||||||
} catch (ex) {}
|
|
||||||
|
|
||||||
for (const [name, listener] of events) {
|
|
||||||
window.removeEventListener(name, listener);
|
|
||||||
}
|
|
||||||
this._scriptingInstance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pdfSidebar.reset();
|
this.pdfSidebar.reset();
|
||||||
this.pdfOutlineViewer.reset();
|
this.pdfOutlineViewer.reset();
|
||||||
@ -844,7 +854,7 @@ const PDFViewerApplication = {
|
|||||||
if (typeof PDFBug !== "undefined") {
|
if (typeof PDFBug !== "undefined") {
|
||||||
PDFBug.cleanup();
|
PDFBug.cleanup();
|
||||||
}
|
}
|
||||||
return promise;
|
return Promise.all(promises);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user