Skip to content

Commit 2aefc40

Browse files
Merge pull request #12622 from Snuffleupagus/hasJSActions-cleanup
Some `hasJSActions`, and general annotation-code, related cleanup in the viewer and API
2 parents bfc5d0d + de628ce commit 2aefc40

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"parserOptions": {
3-
"ecmaVersion": 2020,
3+
"ecmaVersion": 2021,
44
"sourceType": "module",
55
},
66

external/builder/preprocessor2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var path = require("path");
88

99
var PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
1010
var ROOT_PREFIX = "$ROOT/";
11-
const ACORN_ECMA_VERSION = 2020;
11+
const ACORN_ECMA_VERSION = 2021;
1212

1313
function isLiteral(obj, value) {
1414
return obj.type === "Literal" && obj.value === value;

gulpfile.js

+3
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ function createWebpackConfig(defines, output) {
226226
options: {
227227
presets: skipBabel ? undefined : ["@babel/preset-env"],
228228
plugins: [
229+
"@babel/plugin-proposal-logical-assignment-operators",
229230
"@babel/plugin-transform-modules-commonjs",
230231
[
231232
"@babel/plugin-transform-runtime",
@@ -570,6 +571,7 @@ gulp.task("default_preferences-pre", function () {
570571
sourceType: "module",
571572
presets: undefined, // SKIP_BABEL
572573
plugins: [
574+
"@babel/plugin-proposal-logical-assignment-operators",
573575
"@babel/plugin-transform-modules-commonjs",
574576
babelPluginReplaceNonWebPackRequire,
575577
],
@@ -1234,6 +1236,7 @@ function buildLib(defines, dir) {
12341236
sourceType: "module",
12351237
presets: skipBabel ? undefined : ["@babel/preset-env"],
12361238
plugins: [
1239+
"@babel/plugin-proposal-logical-assignment-operators",
12371240
"@babel/plugin-transform-modules-commonjs",
12381241
[
12391242
"@babel/plugin-transform-runtime",

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "2.0.0",
44
"devDependencies": {
55
"@babel/core": "^7.12.3",
6+
"@babel/plugin-proposal-logical-assignment-operators": "^7.12.1",
67
"@babel/plugin-transform-modules-commonjs": "^7.12.1",
78
"@babel/plugin-transform-runtime": "^7.12.1",
89
"@babel/preset-env": "^7.12.1",

src/display/api.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ class PDFDocumentProxy {
905905

906906
/**
907907
* @returns {Promise<boolean>} A promise that is resolved with `true`
908-
* if some /AcroForm fields have JavaScript actions.
908+
* if some /AcroForm fields have JavaScript actions.
909909
*/
910910
hasJSActions() {
911911
return this._transport.hasJSActions();
@@ -2128,7 +2128,10 @@ class WorkerTransport {
21282128
const terminated = this.messageHandler.sendWithPromise("Terminate", null);
21292129
waitOn.push(terminated);
21302130
Promise.all(waitOn).then(() => {
2131+
this.commonObjs.clear();
21312132
this.fontLoader.clear();
2133+
this._hasJSActionsPromise = null;
2134+
21322135
if (this._networkStream) {
21332136
this._networkStream.cancelAllRequests(
21342137
new AbortException("Worker was terminated.")
@@ -2577,7 +2580,10 @@ class WorkerTransport {
25772580
}
25782581

25792582
hasJSActions() {
2580-
return this.messageHandler.sendWithPromise("HasJSActions", null);
2583+
return (this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise(
2584+
"HasJSActions",
2585+
null
2586+
));
25812587
}
25822588

25832589
getCalculationOrderIds() {
@@ -2679,6 +2685,7 @@ class WorkerTransport {
26792685
}
26802686
this.commonObjs.clear();
26812687
this.fontLoader.clear();
2688+
this._hasJSActionsPromise = null;
26822689
});
26832690
}
26842691

web/annotation_layer_builder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ class DefaultAnnotationLayerFactory {
137137
* for annotation icons. Include trailing slash.
138138
* @param {boolean} renderInteractiveForms
139139
* @param {IL10n} l10n
140-
* @param {boolean} enableScripting
141-
* @param {Promise<boolean>} hasJSActionsPromise
140+
* @param {boolean} [enableScripting]
141+
* @param {Promise<boolean>} [hasJSActionsPromise]
142142
* @returns {AnnotationLayerBuilder}
143143
*/
144144
createAnnotationLayerBuilder(

web/base_viewer.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ class BaseViewer {
469469
}
470470
const pagesCount = pdfDocument.numPages;
471471
const firstPagePromise = pdfDocument.getPage(1);
472-
473-
const annotationStorage = pdfDocument.annotationStorage;
472+
// Rendering (potentially) depends on this, hence fetching it immediately.
474473
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
475474

476475
this._pagesCapability.promise.then(() => {
@@ -521,7 +520,6 @@ class BaseViewer {
521520
id: pageNum,
522521
scale,
523522
defaultViewport: viewport.clone(),
524-
annotationStorage,
525523
optionalContentConfigPromise,
526524
renderingQueue: this.renderingQueue,
527525
textLayerFactory,
@@ -1244,11 +1242,14 @@ class BaseViewer {
12441242
/**
12451243
* @param {HTMLDivElement} pageDiv
12461244
* @param {PDFPage} pdfPage
1245+
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
1246+
* data in forms.
12471247
* @param {string} [imageResourcesPath] - Path for image resources, mainly
12481248
* for annotation icons. Include trailing slash.
12491249
* @param {boolean} renderInteractiveForms
12501250
* @param {IL10n} l10n
12511251
* @param {boolean} [enableScripting]
1252+
* @param {Promise<boolean>} [hasJSActionsPromise]
12521253
* @returns {AnnotationLayerBuilder}
12531254
*/
12541255
createAnnotationLayerBuilder(
@@ -1258,21 +1259,22 @@ class BaseViewer {
12581259
imageResourcesPath = "",
12591260
renderInteractiveForms = false,
12601261
l10n = NullL10n,
1261-
enableScripting = false
1262+
enableScripting = false,
1263+
hasJSActionsPromise = null
12621264
) {
12631265
return new AnnotationLayerBuilder({
12641266
pageDiv,
12651267
pdfPage,
1266-
annotationStorage,
1268+
annotationStorage:
1269+
annotationStorage || this.pdfDocument?.annotationStorage,
12671270
imageResourcesPath,
12681271
renderInteractiveForms,
12691272
linkService: this.linkService,
12701273
downloadManager: this.downloadManager,
12711274
l10n,
12721275
enableScripting,
1273-
hasJSActionsPromise: enableScripting
1274-
? this.pdfDocument.hasJSActions()
1275-
: Promise.resolve(false),
1276+
hasJSActionsPromise:
1277+
hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
12761278
});
12771279
}
12781280

web/pdf_page_view.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import { viewerCompatibilityParams } from "./viewer_compatibility.js";
3838
* @property {number} id - The page unique ID (normally its number).
3939
* @property {number} scale - The page scale display.
4040
* @property {PageViewport} defaultViewport - The page viewport.
41-
* @property {AnnotationStorage} [annotationStorage] - Storage for annotation
42-
* data in forms. The default value is `null`.
4341
* @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
4442
* A promise that is resolved with an {@link OptionalContentConfig} instance.
4543
* The default value is `null`.
@@ -89,7 +87,6 @@ class PDFPageView {
8987
this.scale = options.scale || DEFAULT_SCALE;
9088
this.viewport = defaultViewport;
9189
this.pdfPageRotate = defaultViewport.rotation;
92-
this._annotationStorage = options.annotationStorage || null;
9390
this._optionalContentConfigPromise =
9491
options.optionalContentConfigPromise || null;
9592
this.hasRestrictedScaling = false;
@@ -549,11 +546,12 @@ class PDFPageView {
549546
this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(
550547
div,
551548
pdfPage,
552-
this._annotationStorage,
549+
/* annotationStorage = */ null,
553550
this.imageResourcesPath,
554551
this.renderInteractiveForms,
555552
this.l10n,
556-
this.enableScripting
553+
this.enableScripting,
554+
/* hasJSActionsPromise = */ null
557555
);
558556
}
559557
this._renderAnnotationLayer();

0 commit comments

Comments
 (0)