1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

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 prefs = Object.create(null);
let prefs = null;
if (isDict(obj)) {
for (const key in ViewerPreferencesValidators) {
@ -583,6 +583,9 @@ class Catalog {
}
if (prefValue !== undefined) {
if (!prefs) {
prefs = Object.create(null);
}
prefs[key] = prefValue;
} else {
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
* the viewer preferences.
* the viewer preferences, or `null` when no viewer preferences are present
* in the PDF file.
*/
getViewerPreferences() {
return this._transport.getViewerPreferences();

View file

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