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

Side by Side Diff: lib/prefs.js

Issue 5462707926990848: Issue 1434 - Removed remaining non-standard JavaScript code from buildtools (Closed)
Patch Set: Created April 1, 2015, 11:32 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 | « lib/keySelector.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 Cu.import("resource://gre/modules/Services.jsm"); 5 Cu.import("resource://gre/modules/Services.jsm");
6 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 6 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
7 7
8 let {addonRoot, addonName} = require("info"); 8 let {addonRoot, addonName} = require("info");
9 let branchName = "extensions." + addonName + "."; 9 let branchName = "extensions." + addonName + ".";
10 let branch = Services.prefs.getBranch(branchName); 10 let branch = Services.prefs.getBranch(branchName);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 try 55 try
56 { 56 {
57 value = readFunc(branch, name); 57 value = readFunc(branch, name);
58 triggerListeners(name); 58 triggerListeners(name);
59 } 59 }
60 catch(e) 60 catch(e)
61 { 61 {
62 Cu.reportError(e); 62 Cu.reportError(e);
63 } 63 }
64 }; 64 };
65 Prefs.__defineGetter__(name, function() value); 65 Object.defineProperty(Prefs, name, {
66 Prefs.__defineSetter__(name, function(newValue) 66 get: () => value,
67 { 67 set: function(newValue)
68 if (value == newValue) 68 {
69 if (value == newValue)
70 return value;
71
72 try
73 {
74 ignorePrefChanges = true;
75 writeFunc(branch, name, newValue);
76 value = newValue;
77 Services.prefs.savePrefFile(null);
78 triggerListeners(name);
79 }
80 catch(e)
81 {
82 Cu.reportError(e);
83 }
84 finally
85 {
86 ignorePrefChanges = false;
87 }
69 return value; 88 return value;
70
71 try
72 {
73 ignorePrefChanges = true;
74 writeFunc(branch, name, newValue);
75 value = newValue;
76 Services.prefs.savePrefFile(null);
77 triggerListeners(name);
78 } 89 }
79 catch(e)
80 {
81 Cu.reportError(e);
82 }
83 finally
84 {
85 ignorePrefChanges = false;
86 }
87 return value;
88 }); 90 });
89 Prefs["_update_" + name](); 91 Prefs["_update_" + name]();
90 } 92 }
91 93
92 let listeners = []; 94 let listeners = [];
93 function triggerListeners(/**String*/ name) 95 function triggerListeners(/**String*/ name)
94 { 96 {
95 for (let i = 0; i < listeners.length; i++) 97 for (let i = 0; i < listeners.length; i++)
96 { 98 {
97 try 99 try
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 { 183 {
182 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt ring); 184 let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsSt ring);
183 str.data = newValue; 185 str.data = newValue;
184 branch.setComplexValue(pref, Ci.nsISupportsString, str); 186 branch.setComplexValue(pref, Ci.nsISupportsString, str);
185 } 187 }
186 188
187 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref)) 189 function getJSONPref(branch, pref) JSON.parse(getCharPref(branch, pref))
188 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri ngify(newValue)) 190 function setJSONPref(branch, pref, newValue) setCharPref(branch, pref, JSON.stri ngify(newValue))
189 191
190 init(); 192 init();
OLDNEW
« no previous file with comments | « lib/keySelector.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld