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

Unified Diff: lib/prefs.js

Issue 5485735259930624: Issue 2066 - Get rid of non-standard __defineGetter__, __defineSetter__, and __lookupGetter__ (Closed)
Patch Set: Created March 1, 2015, 1:14 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/utils.js » ('j') | qunit/common.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/prefs.js
===================================================================
--- a/lib/prefs.js
+++ b/lib/prefs.js
@@ -45,44 +45,47 @@
function defineProperty(key)
{
let value = null;
- Prefs.__defineGetter__(key, function()
- {
- if (value === null)
+ Object.defineProperty(Prefs, key, {
+ get: function()
{
- if (key in ext.storage)
+ if (value === null)
{
- try
+ if (key in ext.storage)
{
- value = JSON.parse(ext.storage[key]);
+ try
+ {
+ value = JSON.parse(ext.storage[key]);
+ }
+ catch(e)
+ {
+ Cu.reportError(e);
+ }
}
- catch(e)
- {
- Cu.reportError(e);
- }
+
+ if (value === null)
+ value = JSON.parse(JSON.stringify(defaults[key]));
}
+ return value;
+ },
+ set: function(newValue)
+ {
+ if (typeof newValue != typeof defaults[key])
+ throw new Error("Attempt to change preference type");
- if (value === null)
- value = JSON.parse(JSON.stringify(defaults[key]));
- }
- return value;
- });
- Prefs.__defineSetter__(key, function(newValue)
- {
- if (typeof newValue != typeof defaults[key])
- throw new Error("Attempt to change preference type");
+ let stringified = JSON.stringify(newValue);
+ if (stringified != JSON.stringify(defaults[key]))
+ ext.storage[key] = stringified;
+ else
+ delete ext.storage[key];
- let stringified = JSON.stringify(newValue);
- if (stringified != JSON.stringify(defaults[key]))
- ext.storage[key] = stringified;
- else
- delete ext.storage[key];
+ value = newValue;
- value = newValue;
+ for (let listener of listeners)
+ listener(key);
- for (let listener of listeners)
- listener(key);
-
- return value;
+ return value;
+ },
+ enumerable: true
});
}
« no previous file with comments | « no previous file | lib/utils.js » ('j') | qunit/common.js » ('J')

Powered by Google App Engine
This is Rietveld