mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[api-minor] Fix the return value of PDFDocumentProxy.getViewerPreferences
when no viewer preferences are present (PR 10738 follow-up)
This patch fixes yet another instalment in the never-ending series of "what the *bleep* was I thinking", by changing the `PDFDocumentProxy.getViewerPreferences` method to return `null` by default. Not only is this method now consistent with many other API methods, for the data not present case, but it also avoids having to e.g. loop through an object to check if it's actually empty (note the old unit-test).
This commit is contained in:
parent
50bc4a18e8
commit
746eaf3154
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue