mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Merge pull request #18450 from Snuffleupagus/AppOptions-set-validation
Add more validation when setting `AppOptions` (PR 18413 follow-up)
This commit is contained in:
commit
e92a6a14ff
1 changed files with 11 additions and 10 deletions
|
@ -511,6 +511,11 @@ class AppOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
static set(name, value) {
|
static set(name, value) {
|
||||||
|
const defaultOption = defaultOptions[name];
|
||||||
|
|
||||||
|
if (!defaultOption || typeof value !== typeof defaultOption.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
userOptions[name] = value;
|
userOptions[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,22 +523,18 @@ class AppOptions {
|
||||||
let events;
|
let events;
|
||||||
|
|
||||||
for (const name in options) {
|
for (const name in options) {
|
||||||
const userOption = options[name];
|
const defaultOption = defaultOptions[name],
|
||||||
|
userOption = options[name];
|
||||||
|
|
||||||
if (prefs) {
|
if (!defaultOption || typeof userOption !== typeof defaultOption.value) {
|
||||||
const defaultOption = defaultOptions[name];
|
|
||||||
|
|
||||||
if (!defaultOption) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const { kind, value } = defaultOption;
|
if (prefs) {
|
||||||
|
const { kind } = defaultOption;
|
||||||
|
|
||||||
if (!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
|
if (!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (typeof userOption !== typeof value) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
|
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) {
|
||||||
(events ||= new Map()).set(name, userOption);
|
(events ||= new Map()).set(name, userOption);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue