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

Some hasJSActions, and general annotation-code, related cleanup in the viewer and API

- Add support for logical assignment operators, i.e. `&&=`, `||=`, and `??=`, with a Babel-plugin. Given that these required incrementing the ECMAScript version in the ESLint and Acorn configurations, and that platform/browser support is still fairly limited, always transpiling them seems appropriate for now.

 - Cache the `hasJSActions` promise in the API, similar to the existing `getAnnotations` caching. With this implemented, the lookup should now be cheap enough that it can be called unconditionally in the viewer.

 - Slightly improve cleanup of resources when destroying the `WorkerTransport`.

 - Remove the `annotationStorage`-property from the `PDFPageView` constructor, since it's not necessary and also brings it more inline with the `BaseViewer`.

 - Update the `BaseViewer.createAnnotationLayerBuilder` method to actaually agree with the `IPDFAnnotationLayerFactory` interface.[1]

 - Slightly tweak a couple of JSDoc comments.

---
[1] We probably ought to re-factor both the `IPDFTextLayerFactory` and `IPDFAnnotationLayerFactory` interfaces to take parameter objects instead, since especially the `IPDFAnnotationLayerFactory` one is becoming quite unwieldy. Given that that would likely be a breaking change for any custom viewer-components implementation, this probably requires careful deprecation.
This commit is contained in:
Jonas Jenwald 2020-11-14 13:38:36 +01:00
parent 59b35600be
commit de628cec59
8 changed files with 30 additions and 19 deletions

View file

@ -905,7 +905,7 @@ class PDFDocumentProxy {
/**
* @returns {Promise<boolean>} A promise that is resolved with `true`
* if some /AcroForm fields have JavaScript actions.
* if some /AcroForm fields have JavaScript actions.
*/
hasJSActions() {
return this._transport.hasJSActions();
@ -2128,7 +2128,10 @@ class WorkerTransport {
const terminated = this.messageHandler.sendWithPromise("Terminate", null);
waitOn.push(terminated);
Promise.all(waitOn).then(() => {
this.commonObjs.clear();
this.fontLoader.clear();
this._hasJSActionsPromise = null;
if (this._networkStream) {
this._networkStream.cancelAllRequests(
new AbortException("Worker was terminated.")
@ -2577,7 +2580,10 @@ class WorkerTransport {
}
hasJSActions() {
return this.messageHandler.sendWithPromise("HasJSActions", null);
return (this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise(
"HasJSActions",
null
));
}
getCalculationOrderIds() {
@ -2679,6 +2685,7 @@ class WorkerTransport {
}
this.commonObjs.clear();
this.fontLoader.clear();
this._hasJSActionsPromise = null;
});
}