mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Add more validation when setting AppOptions
(PR 18413 follow-up)
After the changes in PR 18413 we're now relying even more on `AppOptions` and it thus seems like a good idea to ensure that no invalid values can be added. Hence the `AppOptions.{set, setAll}` methods will now *unconditionally* validate that the type of the values agree with the default-options.
This commit is contained in:
parent
ed83d7c5e1
commit
216d3a9faf
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 (!defaultOption || typeof userOption !== typeof defaultOption.value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (prefs) {
|
if (prefs) {
|
||||||
const defaultOption = defaultOptions[name];
|
const { kind } = defaultOption;
|
||||||
|
|
||||||
if (!defaultOption) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const { kind, value } = 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