mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #16779 from Snuffleupagus/deprecate-getJavaScript
[api-minor] Deprecate the `PDFDocumentProxy.getJavaScript` method
This commit is contained in:
commit
e6728f94f4
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.#cacheSimpleMethod("GetDocJSActions");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue