Bug 849616 - Use ObjectWrapper.jsm instead of __exposedProps__ in Settings API. r=gwagner

--HG--
extra : rebase_source : b6f492515c0735e8d16fb3f9e903389b09ae3943
This commit is contained in:
Reuben Morais 2013-03-11 22:31:19 -07:00
Родитель 356c0e84be
Коммит e4e518e0f3
2 изменённых файлов: 47 добавлений и 23 удалений

Просмотреть файл

@ -17,6 +17,7 @@ Cu.import("resource://gre/modules/SettingsQueue.jsm");
Cu.import("resource://gre/modules/SettingsDB.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/ObjectWrapper.jsm")
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
@ -42,6 +43,10 @@ SettingsLock.prototype = {
return !this._open;
},
_wrap: function _wrap(obj) {
return ObjectWrapper.wrap(obj, this._settingsManager._window);
},
process: function process() {
let lock = this;
lock._open = false;
@ -134,28 +139,18 @@ SettingsLock.prototype = {
if (DEBUG) debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database.\n");
}
let results = {
__exposedProps__: {
}
};
let results = {};
for (var i in event.target.result) {
let result = event.target.result[i];
var name = result.settingName;
if (DEBUG) debug("VAL: " + result.userValue +", " + result.defaultValue + "\n");
var value = result.userValue !== undefined ? result.userValue : result.defaultValue;
results[name] = value;
results.__exposedProps__[name] = "r";
// If the value itself is an object, expose the properties.
if (typeof value == "object" && value != null) {
var exposed = {};
Object.keys(value).forEach(function(key) { exposed[key] = 'r'; });
results[name].__exposedProps__ = exposed;
}
results[name] = this._wrap(value);
}
this._open = true;
Services.DOMRequest.fireSuccess(request, results);
Services.DOMRequest.fireSuccess(request, this._wrap(results));
this._open = false;
}.bind(lock);
@ -272,6 +267,10 @@ SettingsManager.prototype = {
_onsettingchange: null,
_callbacks: null,
_wrap: function _wrap(obj) {
return ObjectWrapper.wrap(obj, this._window);
},
nextTick: function nextTick(aCallback, thisObj) {
if (thisObj)
aCallback = aCallback.bind(thisObj);
@ -326,9 +325,8 @@ SettingsManager.prototype = {
if (this._callbacks && this._callbacks[msg.key]) {
if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
this._callbacks[msg.key].forEach(function(cb) {
cb({settingName: msg.key, settingValue: msg.value,
__exposedProps__: {settingName: 'r', settingValue: 'r'}});
});
cb(this._wrap({settingName: msg.key, settingValue: msg.value}));
}.bind(this));
}
} else {
if (DEBUG) debug("no observers stored!");

Просмотреть файл

@ -734,6 +734,32 @@ var steps = [
};
req.onerror = onFailure;
},
function() {
ok(true, "Set object value");
var lock = mozSettings.createLock();
req = lock.set({"setting-obj": {foo: {bar: 23}}});
req.onsuccess = function() {
req2 = lock.get("setting-obj");
req2.onsuccess = function(event) {
var result = event.target.result["setting-obj"];
ok(result, "Got valid result");
ok(typeof result == "object", "Result is object");
ok("foo" in result && "bar" in result.foo, "Result has properties");
ok(result.foo.bar == 23, "Result properties are set");
next();
};
};
},
function() {
ok(true, "Clear DB");
var lock = mozSettings.createLock();
req = lock.clear();
req.onsuccess = function () {
ok(true, "Deleted the database");
next();
};
req.onerror = onFailure;
},
function () {
ok(true, "all done!\n");
SimpleTest.finish();