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;
@ -127,35 +132,25 @@ SettingsLock.prototype = {
: store.mozGetAll(info.name);
getReq.onsuccess = function(event) {
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
"Record count: " + event.target.result.length);
if (event.target.result.length == 0) {
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,15 +325,14 @@ 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!");
}
break;
default:
default:
if (DEBUG) debug("Wrong message: " + aMessage.name);
}
},

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

@ -308,7 +308,7 @@ var steps = [
is(req2.result["screen.brightness"], 0.7, "same Value");
}
req2.onerror = onFailure;
var lock2 = mozSettings.createLock();
req5 = lock2.get("screen.brightness");
req5.onsuccess = function () {
@ -465,7 +465,7 @@ var steps = [
}.bind({testObj: testObj, request: req5});
req5.onerror = onFailure;
}
var lock5 = mozSettings.createLock();
req6 = lock5.clear();
req6.onsuccess = function () {
@ -495,14 +495,14 @@ var steps = [
function () {
ok(true, "Test locking result");
var lock = mozSettings.createLock();
req = lock.get("wifi.enabled");
req.onsuccess = function() {
check(req.result, wifiEnabled);
ok(true, "Test2 locking result done");
}
req.onerror = onFailure;
req2 = lock.clear();
req2.onsuccess = function () {
ok(true, "Deleted the database");
@ -515,7 +515,7 @@ var steps = [
next();
}
req3.onerror = onFailure;
},
function () {
ok(true, "Get all settings");
@ -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();