Merge pull request #11806 from Snuffleupagus/pr-10738-followup

[api-minor] Fix the return value of `PDFDocumentProxy.getViewerPreferences` when no viewer preferences are present (PR 10738 follow-up)
This commit is contained in:
Tim van der Meij 2020-04-15 23:32:08 +02:00 committed by GitHub
commit b9cce0e0c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View File

@ -479,7 +479,7 @@ class Catalog {
}; };
const obj = this.catDict.get("ViewerPreferences"); const obj = this.catDict.get("ViewerPreferences");
const prefs = Object.create(null); let prefs = null;
if (isDict(obj)) { if (isDict(obj)) {
for (const key in ViewerPreferencesValidators) { for (const key in ViewerPreferencesValidators) {
@ -583,6 +583,9 @@ class Catalog {
} }
if (prefValue !== undefined) { if (prefValue !== undefined) {
if (!prefs) {
prefs = Object.create(null);
}
prefs[key] = prefValue; prefs[key] = prefValue;
} else { } else {
info(`Bad value in ViewerPreferences for "${key}".`); info(`Bad value in ViewerPreferences for "${key}".`);

View File

@ -663,7 +663,8 @@ class PDFDocumentProxy {
/** /**
* @returns {Promise} A promise that is resolved with an {Object} containing * @returns {Promise} A promise that is resolved with an {Object} containing
* the viewer preferences. * the viewer preferences, or `null` when no viewer preferences are present
* in the PDF file.
*/ */
getViewerPreferences() { getViewerPreferences() {
return this._transport.getViewerPreferences(); return this._transport.getViewerPreferences();

View File

@ -24,7 +24,6 @@ import {
createPromiseCapability, createPromiseCapability,
FontType, FontType,
InvalidPDFException, InvalidPDFException,
isEmptyObj,
MissingPDFException, MissingPDFException,
OPS, OPS,
PasswordException, PasswordException,
@ -846,9 +845,7 @@ describe("api", function () {
return pdfDoc.getViewerPreferences(); return pdfDoc.getViewerPreferences();
}) })
.then(function (prefs) { .then(function (prefs) {
expect( expect(prefs).toEqual(null);
typeof prefs === "object" && prefs !== null && isEmptyObj(prefs)
).toEqual(true);
loadingTask.destroy().then(done); loadingTask.destroy().then(done);
}) })