Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-minor] Fix the return value of PDFDocumentProxy.getViewerPreferences when no viewer preferences are present (PR 10738 follow-up) #11806

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}".`);
Expand Down
3 changes: 2 additions & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
createPromiseCapability,
FontType,
InvalidPDFException,
isEmptyObj,
MissingPDFException,
OPS,
PasswordException,
Expand Down Expand Up @@ -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);
})
Expand Down