Merge pull request #13577 from Snuffleupagus/rm-PDFScriptingManager._pageEventsReady

Remove the internal `PDFScriptingManager._pageEventsReady` boolean (PR 13074 follow-up)
This commit is contained in:
Tim van der Meij 2021-06-18 21:06:00 +02:00 committed by GitHub
commit 248efb16a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,7 +46,6 @@ class PDFScriptingManager {
this._scripting = null; this._scripting = null;
this._mouseState = Object.create(null); this._mouseState = Object.create(null);
this._pageEventsReady = false;
this._ready = false; this._ready = false;
this._eventBus = eventBus; this._eventBus = eventBus;
@ -97,7 +96,14 @@ class PDFScriptingManager {
if (pdfDocument !== this._pdfDocument) { if (pdfDocument !== this._pdfDocument) {
return; // The document was closed while the data resolved. return; // The document was closed while the data resolved.
} }
this._scripting = this._createScripting(); try {
this._scripting = this._createScripting();
} catch (error) {
console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
await this._destroyScripting();
return;
}
this._internalEvents.set("updatefromsandbox", event => { this._internalEvents.set("updatefromsandbox", event => {
if (event?.source !== window) { if (event?.source !== window) {
@ -308,7 +314,6 @@ class PDFScriptingManager {
return; return;
} }
} }
delete detail.id; delete detail.id;
delete detail.siblings; delete detail.siblings;
@ -333,10 +338,8 @@ class PDFScriptingManager {
if (initialize) { if (initialize) {
this._closeCapability = createPromiseCapability(); this._closeCapability = createPromiseCapability();
this._pageEventsReady = true;
} }
if (!this._pageEventsReady) { if (!this._closeCapability) {
return; // Scripting isn't fully initialized yet. return; // Scripting isn't fully initialized yet.
} }
const pageView = this._pdfViewer.getPageView(/* index = */ pageNumber - 1); const pageView = this._pdfViewer.getPageView(/* index = */ pageNumber - 1);
@ -373,7 +376,7 @@ class PDFScriptingManager {
const pdfDocument = this._pdfDocument, const pdfDocument = this._pdfDocument,
visitedPages = this._visitedPages; visitedPages = this._visitedPages;
if (!this._pageEventsReady) { if (!this._closeCapability) {
return; // Scripting isn't fully initialized yet. return; // Scripting isn't fully initialized yet.
} }
if (this._pageOpenPending.has(pageNumber)) { if (this._pageOpenPending.has(pageNumber)) {
@ -481,7 +484,6 @@ class PDFScriptingManager {
this._scripting = null; this._scripting = null;
delete this._mouseState.isDown; delete this._mouseState.isDown;
this._pageEventsReady = false;
this._ready = false; this._ready = false;
this._destroyCapability?.resolve(); this._destroyCapability?.resolve();