mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 00:28:06 +02:00
[api-minor] Deprecate the PDFDocumentProxy.getJavaScript
method
This method is very old, however with the exception of the auto-print hack (when scripting is disabled) in the viewer it's never actually been used. Most likely the idea with `PDFDocumentProxy.getJavaScript` was that it'd be useful if scripting support was added, however it turned out that it was a bit too simplistic and instead a number of new methods were added for the scripting use-cases.
This commit is contained in:
parent
5b8f680480
commit
64e8557fb5
5 changed files with 42 additions and 58 deletions
|
@ -987,7 +987,10 @@ class Catalog {
|
|||
return;
|
||||
}
|
||||
js = stringToPDFString(js).replaceAll("\x00", "");
|
||||
(javaScript ||= new Map()).set(name, js);
|
||||
// Skip empty entries, similar to the `_collectJS` function.
|
||||
if (js) {
|
||||
(javaScript ||= new Map()).set(name, js);
|
||||
}
|
||||
}
|
||||
|
||||
if (obj instanceof Dict && obj.has("JavaScript")) {
|
||||
|
@ -1005,15 +1008,6 @@ class Catalog {
|
|||
return javaScript;
|
||||
}
|
||||
|
||||
get javaScript() {
|
||||
const javaScript = this._collectJavaScript();
|
||||
return shadow(
|
||||
this,
|
||||
"javaScript",
|
||||
javaScript ? [...javaScript.values()] : null
|
||||
);
|
||||
}
|
||||
|
||||
get jsActions() {
|
||||
const javaScript = this._collectJavaScript();
|
||||
let actions = collectActions(
|
||||
|
@ -1023,9 +1017,8 @@ class Catalog {
|
|||
);
|
||||
|
||||
if (javaScript) {
|
||||
if (!actions) {
|
||||
actions = Object.create(null);
|
||||
}
|
||||
actions ||= Object.create(null);
|
||||
|
||||
for (const [key, val] of javaScript) {
|
||||
if (key in actions) {
|
||||
actions[key].push(val);
|
||||
|
|
|
@ -463,10 +463,6 @@ class WorkerMessageHandler {
|
|||
return pdfManager.ensureCatalog("attachments");
|
||||
});
|
||||
|
||||
handler.on("GetJavaScript", function (data) {
|
||||
return pdfManager.ensureCatalog("javaScript");
|
||||
});
|
||||
|
||||
handler.on("GetDocJSActions", function (data) {
|
||||
return pdfManager.ensureCatalog("jsActions");
|
||||
});
|
||||
|
|
|
@ -760,6 +760,26 @@ class PDFDocumentProxy {
|
|||
this._pdfInfo = pdfInfo;
|
||||
this._transport = transport;
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
Object.defineProperty(this, "getJavaScript", {
|
||||
value: () => {
|
||||
deprecated(
|
||||
"`PDFDocumentProxy.getJavaScript`, " +
|
||||
"please use `PDFDocumentProxy.getJSActions` instead."
|
||||
);
|
||||
return this.getJSActions().then(js => {
|
||||
if (!js) {
|
||||
return js;
|
||||
}
|
||||
const jsArr = [];
|
||||
for (const name in js) {
|
||||
jsArr.push(...js[name]);
|
||||
}
|
||||
return jsArr;
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
// For testing purposes.
|
||||
Object.defineProperty(this, "getXFADatasets", {
|
||||
|
@ -917,19 +937,10 @@ class PDFDocumentProxy {
|
|||
return this._transport.getAttachments();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<Array<string> | null>} A promise that is resolved with
|
||||
* an {Array} of all the JavaScript strings in the name tree, or `null`
|
||||
* if no JavaScript exists.
|
||||
*/
|
||||
getJavaScript() {
|
||||
return this._transport.getJavaScript();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<Object | null>} A promise that is resolved with
|
||||
* an {Object} with the JavaScript actions:
|
||||
* - from the name tree (like getJavaScript);
|
||||
* - from the name tree.
|
||||
* - from A or AA entries in the catalog dictionary.
|
||||
* , or `null` if no JavaScript exists.
|
||||
*/
|
||||
|
@ -3016,10 +3027,6 @@ class WorkerTransport {
|
|||
return this.messageHandler.sendWithPromise("GetAttachments", null);
|
||||
}
|
||||
|
||||
getJavaScript() {
|
||||
return this.messageHandler.sendWithPromise("GetJavaScript", null);
|
||||
}
|
||||
|
||||
getDocJSActions() {
|
||||
return this.messageHandler.sendWithPromise("GetDocJSActions", null);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue