1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

[api-major] Change getJavaScript to return null, rather than an empty Array, when no JavaScript exists

Other API methods already return `null`, rather than empty Arrays/Objects, hence it makes sense to change `getJavaScript` to be consistent.
This commit is contained in:
Jonas Jenwald 2017-10-15 22:13:58 +02:00
parent 4fdb0f57d7
commit 1cd1582cb9
4 changed files with 16 additions and 8 deletions

View file

@ -371,7 +371,7 @@ var Catalog = (function CatalogClosure() {
var xref = this.xref;
var obj = this.catDict.get('Names');
var javaScript = [];
let javaScript = null;
function appendIfJavaScriptDict(jsDict) {
var type = jsDict.get('S');
if (!isName(type, 'JavaScript')) {
@ -383,6 +383,9 @@ var Catalog = (function CatalogClosure() {
} else if (!isString(js)) {
return;
}
if (!javaScript) {
javaScript = [];
}
javaScript.push(stringToPDFString(js));
}
if (obj && obj.has('JavaScript')) {
@ -407,6 +410,9 @@ var Catalog = (function CatalogClosure() {
// but is supported by many PDF readers/writers (including Adobe's).
var action = openactionDict.get('N');
if (isName(action, 'Print')) {
if (!javaScript) {
javaScript = [];
}
javaScript.push('print({});');
}
} else {

View file

@ -574,10 +574,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
return this.transport.getAttachments();
},
/**
* @return {Promise} A promise that is resolved with an array of all the
* JavaScript strings in the name tree.
* @return {Promise} A promise that is resolved with an {Array} of all the
* JavaScript strings in the name tree, or `null` if no JavaScript exists.
*/
getJavaScript: function PDFDocumentProxy_getJavaScript() {
getJavaScript() {
return this.transport.getJavaScript();
},
/**