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: Use an arrow function and Object.defineProperty Created April 30, 2015, 5:05 a.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 }
Wladimir Palant 2015/04/30 08:30:24 enumerable: true please, otherwise debugging will
Felix Dahlke 2015/04/30 13:17:38 Done.
69 }); 72 });
70 } 73 }
71 74
72 function load() 75 function load()
73 { 76 {
74 _fileSystem.read(path, function(result) 77 _fileSystem.read(path, function(result)
75 { 78 {
76 // prefs.json is expected to be missing, ignore errors reading file 79 // prefs.json is expected to be missing, ignore errors reading file
77 if (!result.error) 80 if (!result.error)
78 { 81 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 let index = listeners.indexOf(listener); 127 let index = listeners.indexOf(listener);
125 if (index >= 0) 128 if (index >= 0)
126 listeners.splice(index, 1); 129 listeners.splice(index, 1);
127 }, 130 },
128 }; 131 };
129 132
130 for (let key in defaults) 133 for (let key in defaults)
131 defineProperty(key); 134 defineProperty(key);
132 135
133 load(); 136 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