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:
commit
b9cce0e0c1
3 changed files with 7 additions and 6 deletions
|
@ -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}".`);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue