Merge pull request #9034 from Snuffleupagus/javascript-null
[api-major] Change `getJavaScript` to return `null`, rather than an empty Array, when no JavaScript exists
This commit is contained in:
commit
17cc94db4e
@ -371,7 +371,7 @@ var Catalog = (function CatalogClosure() {
|
|||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
var obj = this.catDict.get('Names');
|
var obj = this.catDict.get('Names');
|
||||||
|
|
||||||
var javaScript = [];
|
let javaScript = null;
|
||||||
function appendIfJavaScriptDict(jsDict) {
|
function appendIfJavaScriptDict(jsDict) {
|
||||||
var type = jsDict.get('S');
|
var type = jsDict.get('S');
|
||||||
if (!isName(type, 'JavaScript')) {
|
if (!isName(type, 'JavaScript')) {
|
||||||
@ -383,6 +383,9 @@ var Catalog = (function CatalogClosure() {
|
|||||||
} else if (!isString(js)) {
|
} else if (!isString(js)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!javaScript) {
|
||||||
|
javaScript = [];
|
||||||
|
}
|
||||||
javaScript.push(stringToPDFString(js));
|
javaScript.push(stringToPDFString(js));
|
||||||
}
|
}
|
||||||
if (obj && obj.has('JavaScript')) {
|
if (obj && obj.has('JavaScript')) {
|
||||||
@ -407,6 +410,9 @@ var Catalog = (function CatalogClosure() {
|
|||||||
// but is supported by many PDF readers/writers (including Adobe's).
|
// but is supported by many PDF readers/writers (including Adobe's).
|
||||||
var action = openactionDict.get('N');
|
var action = openactionDict.get('N');
|
||||||
if (isName(action, 'Print')) {
|
if (isName(action, 'Print')) {
|
||||||
|
if (!javaScript) {
|
||||||
|
javaScript = [];
|
||||||
|
}
|
||||||
javaScript.push('print({});');
|
javaScript.push('print({});');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -574,10 +574,10 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
return this.transport.getAttachments();
|
return this.transport.getAttachments();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @return {Promise} A promise that is resolved with an array of all the
|
* @return {Promise} A promise that is resolved with an {Array} of all the
|
||||||
* JavaScript strings in the name tree.
|
* JavaScript strings in the name tree, or `null` if no JavaScript exists.
|
||||||
*/
|
*/
|
||||||
getJavaScript: function PDFDocumentProxy_getJavaScript() {
|
getJavaScript() {
|
||||||
return this.transport.getJavaScript();
|
return this.transport.getJavaScript();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -683,7 +683,7 @@ describe('api', function() {
|
|||||||
it('gets javascript', function(done) {
|
it('gets javascript', function(done) {
|
||||||
var promise = doc.getJavaScript();
|
var promise = doc.getJavaScript();
|
||||||
promise.then(function (data) {
|
promise.then(function (data) {
|
||||||
expect(data).toEqual([]);
|
expect(data).toEqual(null);
|
||||||
done();
|
done();
|
||||||
}).catch(function (reason) {
|
}).catch(function (reason) {
|
||||||
done.fail(reason);
|
done.fail(reason);
|
||||||
|
@ -1035,10 +1035,12 @@ let PDFViewerApplication = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pdfDocument.getJavaScript().then((javaScript) => {
|
pdfDocument.getJavaScript().then((javaScript) => {
|
||||||
if (javaScript.length) {
|
if (!javaScript) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.warn('Warning: JavaScript is not supported');
|
console.warn('Warning: JavaScript is not supported');
|
||||||
this.fallback(UNSUPPORTED_FEATURES.javaScript);
|
this.fallback(UNSUPPORTED_FEATURES.javaScript);
|
||||||
}
|
|
||||||
// Hack to support auto printing.
|
// Hack to support auto printing.
|
||||||
let regex = /\bprint\s*\(/;
|
let regex = /\bprint\s*\(/;
|
||||||
for (let i = 0, ii = javaScript.length; i < ii; i++) {
|
for (let i = 0, ii = javaScript.length; i < ii; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user