Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/prefs.js

Issue 5519479341580288: Issue 2437 - Update adblockplus dependency to revision 752ffe2eeaf1 (Closed)
Patch Set: Make the properties enumerable Created April 30, 2015, 1:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ensure_dependencies.py ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 }; 45 };
46 46
47 let values = Object.create(defaults); 47 let values = Object.create(defaults);
48 let path = _fileSystem.resolve("prefs.json"); 48 let path = _fileSystem.resolve("prefs.json");
49 let listeners = []; 49 let listeners = [];
50 let isDirty = false; 50 let isDirty = false;
51 let isSaving = false; 51 let isSaving = false;
52 52
53 function defineProperty(key) 53 function defineProperty(key)
54 { 54 {
55 Prefs.__defineGetter__(key, function() values[key]); 55 Object.defineProperty(Prefs, key,
56 Prefs.__defineSetter__(key, function(value)
57 { 56 {
58 if (typeof value != typeof defaults[key]) 57 get: () => values[key],
59 throw new Error("Attempt to change preference type"); 58 set: function(value)
59 {
60 if (typeof value != typeof defaults[key])
61 throw new Error("Attempt to change preference type");
60 62
61 if (value == defaults[key]) 63 if (value == defaults[key])
62 delete values[key]; 64 delete values[key];
63 else 65 else
64 values[key] = value; 66 values[key] = value;
65 save(); 67 save();
66 68
67 for (let listener of listeners) 69 for (let listener of listeners)
68 listener(key); 70 listener(key);
71 },
72 enumerable: true
69 }); 73 });
70 } 74 }
71 75
72 function load() 76 function load()
73 { 77 {
74 _fileSystem.read(path, function(result) 78 _fileSystem.read(path, function(result)
75 { 79 {
76 // prefs.json is expected to be missing, ignore errors reading file 80 // prefs.json is expected to be missing, ignore errors reading file
77 if (!result.error) 81 if (!result.error)
78 { 82 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 let index = listeners.indexOf(listener); 128 let index = listeners.indexOf(listener);
125 if (index >= 0) 129 if (index >= 0)
126 listeners.splice(index, 1); 130 listeners.splice(index, 1);
127 }, 131 },
128 }; 132 };
129 133
130 for (let key in defaults) 134 for (let key in defaults)
131 defineProperty(key); 135 defineProperty(key);
132 136
133 load(); 137 load();
OLDNEW
« no previous file with comments | « ensure_dependencies.py ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld