summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/api.js34
1 files changed, 14 insertions, 20 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 3209cc31..9fed99a1 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -25,42 +25,36 @@ async function apiOptionsSet(changedOptions, optionsContext, source) {
const options = await apiOptionsGet(optionsContext);
function getValuePaths(obj) {
- let valuePaths = [];
- let nodes = [{
- obj,
- path: []
- }];
+ const valuePaths = [];
+ const nodes = [{obj, path: []}];
while (nodes.length > 0) {
- let node = nodes.pop();
- Object.keys(node.obj).forEach((key) => {
- let path = node.path.concat(key);
- let value = node.obj[key];
- if (typeof value === 'object') {
- nodes.unshift({
- obj: value,
- path: path
- });
+ const node = nodes.pop();
+ for (const key of Object.keys(node.obj)) {
+ const path = node.path.concat(key);
+ const obj = node.obj[key];
+ if (obj !== null && typeof obj === 'object') {
+ nodes.unshift({obj, path});
} else {
- valuePaths.push([value, path]);
+ valuePaths.push([obj, path]);
}
- });
+ }
}
return valuePaths;
}
function modifyOption(path, value, options) {
let pivot = options;
- for (let pathKey of path.slice(0, -1)) {
- if (!(pathKey in pivot)) {
+ for (const key of path.slice(0, -1)) {
+ if (!pivot.hasOwnProperty(key)) {
return false;
}
- pivot = pivot[pathKey];
+ pivot = pivot[key];
}
pivot[path[path.length - 1]] = value;
return true;
}
- for (let [value, path] of getValuePaths(changedOptions)) {
+ for (const [value, path] of getValuePaths(changedOptions)) {
modifyOption(path, value, options);
}