зеркало из https://github.com/mozilla/gecko-dev.git
Bug 760448 - Send result to CommonUtils.jsonSave's callback; r=rnewman
This commit is contained in:
Родитель
bd7fee43f0
Коммит
3dcc94ff11
|
@ -11,7 +11,9 @@ function run_test() {
|
|||
|
||||
add_test(function test_roundtrip() {
|
||||
_("Do a simple write of an array to json and read");
|
||||
CommonUtils.jsonSave("foo", {}, ["v1", "v2"], ensureThrows(function() {
|
||||
CommonUtils.jsonSave("foo", {}, ["v1", "v2"], ensureThrows(function(error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
CommonUtils.jsonLoad("foo", {}, ensureThrows(function(val) {
|
||||
let foo = val;
|
||||
do_check_eq(typeof foo, "object");
|
||||
|
@ -25,7 +27,9 @@ add_test(function test_roundtrip() {
|
|||
|
||||
add_test(function test_string() {
|
||||
_("Try saving simple strings");
|
||||
CommonUtils.jsonSave("str", {}, "hi", ensureThrows(function() {
|
||||
CommonUtils.jsonSave("str", {}, "hi", ensureThrows(function(error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
CommonUtils.jsonLoad("str", {}, ensureThrows(function(val) {
|
||||
let str = val;
|
||||
do_check_eq(typeof str, "string");
|
||||
|
@ -39,7 +43,9 @@ add_test(function test_string() {
|
|||
|
||||
add_test(function test_number() {
|
||||
_("Try saving a number");
|
||||
CommonUtils.jsonSave("num", {}, 42, ensureThrows(function() {
|
||||
CommonUtils.jsonSave("num", {}, 42, ensureThrows(function(error) {
|
||||
do_check_eq(error, null);
|
||||
|
||||
CommonUtils.jsonLoad("num", {}, ensureThrows(function(val) {
|
||||
let num = val;
|
||||
do_check_eq(typeof num, "number");
|
||||
|
|
|
@ -390,6 +390,9 @@ let CommonUtils = {
|
|||
* function, it'll be used as the object to make a json string.
|
||||
* @param callback
|
||||
* Function called when the write has been performed. Optional.
|
||||
* The first argument will be a Components.results error
|
||||
* constant on error or null if no error was encountered (and
|
||||
* the file saved successfully).
|
||||
*/
|
||||
jsonSave: function jsonSave(filePath, that, obj, callback) {
|
||||
let path = filePath + ".json";
|
||||
|
@ -405,7 +408,8 @@ let CommonUtils = {
|
|||
let is = this._utf8Converter.convertToInputStream(out);
|
||||
NetUtil.asyncCopy(is, fos, function (result) {
|
||||
if (typeof callback == "function") {
|
||||
callback.call(that);
|
||||
let error = (result == Cr.NS_OK) ? null : result;
|
||||
callback.call(that, error);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче