зеркало из https://github.com/mozilla/pjs.git
Bug 481741 - Switch to JSON from nsIJSON
This commit is contained in:
Родитель
e22f52680d
Коммит
3cead7f04b
|
@ -156,7 +156,7 @@ CollectionIterator.prototype = {
|
|||
return;
|
||||
let item = this._coll.data[this._idx++];
|
||||
let record = new this._coll._recordObj();
|
||||
record.deserialize(Svc.Json.encode(item)); // FIXME: inefficient
|
||||
record.deserialize(JSON.stringify(item)); // FIXME: inefficient
|
||||
record.baseUri = this._coll.uri;
|
||||
|
||||
self.done(record);
|
||||
|
@ -167,4 +167,4 @@ CollectionIterator.prototype = {
|
|||
reset: function CollIter_reset() {
|
||||
this._idx = 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -96,7 +96,7 @@ CryptoWrapper.prototype = {
|
|||
let meta = yield CryptoMetas.get(self.cb, this.encryption);
|
||||
let symkey = yield meta.getKey(self.cb, privkey, passphrase);
|
||||
|
||||
this.ciphertext = Svc.Crypto.encrypt(Svc.Json.encode([this.cleartext]),
|
||||
this.ciphertext = Svc.Crypto.encrypt(JSON.stringify([this.cleartext]),
|
||||
symkey, meta.bulkIV);
|
||||
this.cleartext = null;
|
||||
|
||||
|
@ -122,7 +122,7 @@ CryptoWrapper.prototype = {
|
|||
let symkey = yield meta.getKey(self.cb, privkey, passphrase);
|
||||
|
||||
// note: payload is wrapped in an array, see _encrypt
|
||||
this.cleartext = Svc.Json.decode(Svc.Crypto.decrypt(this.ciphertext,
|
||||
this.cleartext = JSON.parse(Svc.Crypto.decrypt(this.ciphertext,
|
||||
symkey, meta.bulkIV))[0];
|
||||
this.ciphertext = null;
|
||||
|
||||
|
@ -137,7 +137,7 @@ CryptoWrapper.prototype = {
|
|||
" parent: " + this.parentid + "\n" +
|
||||
" depth: " + this.depth + ", index: " + this.sortindex + "\n" +
|
||||
" modified: " + this.modified + "\n" +
|
||||
" payload: " + Svc.Json.encode(this.cleartext) + " }";
|
||||
" payload: " + JSON.stringify(this.cleartext) + " }";
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -230,4 +230,4 @@ function CryptoRecordManager() { this._init(); }
|
|||
CryptoRecordManager.prototype = {
|
||||
__proto__: RecordManager.prototype,
|
||||
_recordType: CryptoMeta
|
||||
};
|
||||
};
|
||||
|
|
|
@ -118,15 +118,15 @@ WBORecord.prototype = {
|
|||
// payload is encoded twice in serialized form, because the
|
||||
// server expects a string
|
||||
serialize: function WBORec_serialize() {
|
||||
this.payload = Svc.Json.encode([this.payload]);
|
||||
let ret = Svc.Json.encode(this.data);
|
||||
this.payload = Svc.Json.decode(this.payload)[0];
|
||||
this.payload = JSON.stringify([this.payload]);
|
||||
let ret = JSON.stringify(this.data);
|
||||
this.payload = JSON.parse(this.payload)[0];
|
||||
return ret;
|
||||
},
|
||||
|
||||
deserialize: function WBORec_deserialize(json) {
|
||||
this.data = Svc.Json.decode(json);
|
||||
this.payload = Svc.Json.decode(this.payload)[0];
|
||||
this.data = JSON.parse(json);
|
||||
this.payload = JSON.parse(this.payload)[0];
|
||||
},
|
||||
|
||||
toString: function WBORec_toString() {
|
||||
|
@ -134,7 +134,7 @@ WBORecord.prototype = {
|
|||
" parent: " + this.parentid + "\n" +
|
||||
" depth: " + this.depth + ", index: " + this.sortindex + "\n" +
|
||||
" modified: " + this.modified + "\n" +
|
||||
" payload: " + Svc.Json.encode(this.payload) + " }";
|
||||
" payload: " + JSON.stringify(this.payload) + " }";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -454,7 +454,7 @@ SyncEngine.prototype = {
|
|||
if (out.payload) // skip deleted records
|
||||
this._store.createMetaRecords(out.id, meta);
|
||||
yield out.encrypt(self.cb, ID.get('WeaveCryptoID').password);
|
||||
up.pushData(Svc.Json.decode(out.serialize())); // FIXME: inefficient
|
||||
up.pushData(JSON.parse(out.serialize())); // FIXME: inefficient
|
||||
}
|
||||
|
||||
this._store.cache.enabled = true;
|
||||
|
|
|
@ -178,7 +178,7 @@ ClientStore.prototype = {
|
|||
this._log.debug("Saving client list to disk");
|
||||
let file = Utils.getProfileFile(
|
||||
{path: "weave/meta/clients.json", autoCreate: true});
|
||||
let out = Svc.Json.encode(this._clients);
|
||||
let out = JSON.stringify(this._clients);
|
||||
let [fos] = Utils.open(file, ">");
|
||||
fos.writeString(out);
|
||||
fos.close();
|
||||
|
@ -193,7 +193,7 @@ ClientStore.prototype = {
|
|||
let [is] = Utils.open(file, "<");
|
||||
let json = Utils.readStream(is);
|
||||
is.close();
|
||||
this._clients = Svc.Json.decode(json);
|
||||
this._clients = JSON.parse(json);
|
||||
} catch (e) {
|
||||
this._log.debug("Failed to load saved client list" + e);
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ TabEngine.prototype = {
|
|||
* _addFennecTabsToRecord. Unify? */
|
||||
if (Cc["@mozilla.org/browser/sessionstore;1"]) {
|
||||
let state = this._store._sessionStore.getBrowserState();
|
||||
let session = this._store._json.decode(state);
|
||||
let session = JSON.parse(state);
|
||||
for (let i = 0; i < session.windows.length; i++) {
|
||||
let window = session.windows[i];
|
||||
for (let j = 0; j < window.tabs.length; j++) {
|
||||
|
@ -158,7 +158,7 @@ TabStore.prototype = {
|
|||
jsonObj[id] = this._remoteClients[id].toJson();
|
||||
}
|
||||
let [fos] = Utils.open(file, ">");
|
||||
fos.writeString(this._json.encode(jsonObj));
|
||||
fos.writeString(JSON.stringify(jsonObj));
|
||||
fos.close();
|
||||
},
|
||||
|
||||
|
@ -174,7 +174,7 @@ TabStore.prototype = {
|
|||
let [is] = Utils.open(file, "<");
|
||||
let json = Utils.readStream(is);
|
||||
is.close();
|
||||
let jsonObj = this._json.decode(json);
|
||||
let jsonObj = JSON.parse(json);
|
||||
for (let id in jsonObj) {
|
||||
this._remoteClients[id] = new TabSetRecord();
|
||||
this._remoteClients[id].fromJson(jsonObj[id]);
|
||||
|
@ -199,12 +199,6 @@ TabStore.prototype = {
|
|||
return this._windowMediator;
|
||||
},
|
||||
|
||||
get _json() {
|
||||
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
||||
this.__defineGetter__("_json", function() {return json;});
|
||||
return this._json;
|
||||
},
|
||||
|
||||
_createLocalClientTabSetRecord: function TabStore__createLocalTabSet() {
|
||||
// Test for existence of sessionStore. If it doesn't exist, then
|
||||
// use get _fennecTabs instead.
|
||||
|
@ -235,7 +229,7 @@ TabStore.prototype = {
|
|||
let tab = tabChild.QueryInterface(Ci.nsIDOMNode);
|
||||
if (!tab)
|
||||
continue;
|
||||
let tabState = this._json.decode(this._sessionStore.getTabState(tab));
|
||||
let tabState = JSON.parse(this._sessionStore.getTabState(tab));
|
||||
// Skip empty (i.e. just-opened, no history yet) tabs:
|
||||
if (tabState.entries.length == 0)
|
||||
continue;
|
||||
|
|
|
@ -346,22 +346,16 @@ function JsonFilter() {
|
|||
this._log.level = Log4Moz.Level[level];
|
||||
}
|
||||
JsonFilter.prototype = {
|
||||
get _json() {
|
||||
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
||||
this.__defineGetter__("_json", function() json);
|
||||
return this._json;
|
||||
},
|
||||
|
||||
beforePUT: function JsonFilter_beforePUT(data) {
|
||||
let self = yield;
|
||||
this._log.trace("Encoding data as JSON");
|
||||
self.done(this._json.encode(data));
|
||||
self.done(JSON.stringify(data));
|
||||
},
|
||||
|
||||
afterGET: function JsonFilter_afterGET(data) {
|
||||
let self = yield;
|
||||
this._log.trace("Decoding JSON data");
|
||||
self.done(this._json.decode(data));
|
||||
self.done(JSON.parse(data));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -478,7 +478,7 @@ WeaveSvc.prototype = {
|
|||
};
|
||||
yield res.get(self.cb);
|
||||
|
||||
//Svc.Json.decode(res.data); // throws if not json
|
||||
//JSON.parse(res.data); // throws if not json
|
||||
self.done(true);
|
||||
};
|
||||
this._catchAll(this._notify("verify-login", "", fn)).async(this, onComplete);
|
||||
|
@ -961,7 +961,7 @@ WeaveSvc.prototype = {
|
|||
yield res.get(self.cb);
|
||||
|
||||
// Get the array of collections and delete each one
|
||||
let allCollections = Svc.Json.decode(res.data);
|
||||
let allCollections = JSON.parse(res.data);
|
||||
for each (let name in allCollections) {
|
||||
try {
|
||||
// If we have a list of engines, make sure it's one we want
|
||||
|
@ -1198,9 +1198,9 @@ WeaveSvc.prototype = {
|
|||
let actionStr = command + "(" + args + ")";
|
||||
|
||||
// Convert args into a string to simplify array comparisons
|
||||
let jsonArgs = Svc.Json.encode(args);
|
||||
let jsonArgs = JSON.stringify(args);
|
||||
let notDupe = function(action) action.command != command ||
|
||||
Svc.Json.encode(action.args) != jsonArgs;
|
||||
JSON.stringify(action.args) != jsonArgs;
|
||||
|
||||
this._log.info("Sending clients: " + actionStr + "; " + commandData.desc);
|
||||
|
||||
|
|
|
@ -64,14 +64,6 @@ Store.prototype = {
|
|||
// set this property in child object's wrap()!
|
||||
_lookup: null,
|
||||
|
||||
__json: null,
|
||||
get _json() {
|
||||
if (!this.__json)
|
||||
this.__json = Cc["@mozilla.org/dom/json;1"].
|
||||
createInstance(Ci.nsIJSON);
|
||||
return this.__json;
|
||||
},
|
||||
|
||||
get cache() {
|
||||
let cache = new Cache();
|
||||
this.__defineGetter__("cache", function() cache);
|
||||
|
@ -284,7 +276,7 @@ SnapshotStore.prototype = {
|
|||
let out = {version: this.version,
|
||||
GUID: this.GUID,
|
||||
snapshot: this.data};
|
||||
out = this._json.encode(out);
|
||||
out = JSON.stringify(out);
|
||||
|
||||
let [fos] = Utils.open(file, ">");
|
||||
fos.writeString(out);
|
||||
|
@ -300,7 +292,7 @@ SnapshotStore.prototype = {
|
|||
let [is] = Utils.open(file, "<");
|
||||
let json = Utils.readStream(is);
|
||||
is.close();
|
||||
json = this._json.decode(json);
|
||||
json = JSON.parse(json);
|
||||
|
||||
if (json && 'snapshot' in json && 'version' in json && 'GUID' in json) {
|
||||
this._log.debug("Read saved snapshot from disk");
|
||||
|
@ -315,7 +307,7 @@ SnapshotStore.prototype = {
|
|||
},
|
||||
|
||||
serialize: function SStore_serialize() {
|
||||
let json = this._json.encode(this.data);
|
||||
let json = JSON.stringify(this.data);
|
||||
json = json.replace(/:{type/g, ":\n\t{type");
|
||||
json = json.replace(/}, /g, "},\n ");
|
||||
json = json.replace(/, parentid/g, ",\n\t parentid");
|
||||
|
|
|
@ -67,12 +67,6 @@ Tracker.prototype = {
|
|||
_logName: "Tracker",
|
||||
file: "none",
|
||||
|
||||
get _json() {
|
||||
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
||||
this.__defineGetter__("_json", function() json);
|
||||
return json;
|
||||
},
|
||||
|
||||
_init: function T__init() {
|
||||
this._log = Log4Moz.repository.getLogger(this._logName);
|
||||
this._score = 0;
|
||||
|
@ -124,7 +118,7 @@ Tracker.prototype = {
|
|||
let file = Utils.getProfileFile(
|
||||
{path: "weave/changes/" + this.file + ".json",
|
||||
autoCreate: true});
|
||||
let out = this._json.encode(this.changedIDs);
|
||||
let out = JSON.stringify(this.changedIDs);
|
||||
let [fos] = Utils.open(file, ">");
|
||||
fos.writeString(out);
|
||||
fos.close();
|
||||
|
@ -142,7 +136,7 @@ Tracker.prototype = {
|
|||
let json = Utils.readStream(is);
|
||||
is.close();
|
||||
|
||||
let ids = this._json.decode(json);
|
||||
let ids = JSON.parse(json);
|
||||
for (let id in ids) {
|
||||
this.changedIDs[id] = 1;
|
||||
}
|
||||
|
|
|
@ -566,7 +566,6 @@ Utils.EventListener.prototype = {
|
|||
|
||||
let Svc = {};
|
||||
Svc.Prefs = new Preferences(PREFS_BRANCH);
|
||||
Utils.lazyInstance(Svc, 'Json', "@mozilla.org/dom/json;1", Ci.nsIJSON);
|
||||
[["Crypto", "@labs.mozilla.com/Weave/Crypto;1", "IWeaveCrypto"],
|
||||
["Directory", "@mozilla.org/file/directory_service;1", "nsIProperties"],
|
||||
["IO", "@mozilla.org/network/io-service;1", "nsIIOService"],
|
||||
|
|
|
@ -11,35 +11,34 @@ try {
|
|||
}
|
||||
Function.prototype.async = Async.sugar;
|
||||
|
||||
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
||||
let keys, cryptoMeta, cryptoWrap;
|
||||
|
||||
function pubkey_handler(metadata, response) {
|
||||
let obj = {id: "ignore-me",
|
||||
modified: keys.pubkey.modified,
|
||||
payload: json.encode(keys.pubkey.payload)};
|
||||
return httpd_basic_auth_handler(json.encode(obj), metadata, response);
|
||||
payload: JSON.stringify(keys.pubkey.payload)};
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function privkey_handler(metadata, response) {
|
||||
let obj = {id: "ignore-me-2",
|
||||
modified: keys.privkey.modified,
|
||||
payload: json.encode(keys.privkey.payload)};
|
||||
return httpd_basic_auth_handler(json.encode(obj), metadata, response);
|
||||
payload: JSON.stringify(keys.privkey.payload)};
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function crypted_resource_handler(metadata, response) {
|
||||
let obj = {id: "ignore-me-3",
|
||||
modified: cryptoWrap.modified,
|
||||
payload: json.encode(cryptoWrap.payload)};
|
||||
return httpd_basic_auth_handler(json.encode(obj), metadata, response);
|
||||
payload: JSON.stringify(cryptoWrap.payload)};
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function crypto_meta_handler(metadata, response) {
|
||||
let obj = {id: "ignore-me-4",
|
||||
modified: cryptoMeta.modified,
|
||||
payload: json.encode(cryptoMeta.payload)};
|
||||
return httpd_basic_auth_handler(json.encode(obj), metadata, response);
|
||||
payload: JSON.stringify(cryptoMeta.payload)};
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function async_test() {
|
||||
|
|
|
@ -9,24 +9,22 @@ try {
|
|||
|
||||
Function.prototype.async = Async.sugar;
|
||||
|
||||
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
||||
|
||||
function pubkey_handler(metadata, response) {
|
||||
let obj = {id: "asdf-1234-asdf-1234",
|
||||
modified: "2454725.98283",
|
||||
payload: json.encode({type: "pubkey",
|
||||
payload: JSON.stringify({type: "pubkey",
|
||||
private_key: "http://localhost:8080/privkey",
|
||||
key_data: "asdfasdfasf..."})};
|
||||
return httpd_basic_auth_handler(json.encode(obj), metadata, response);
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function privkey_handler(metadata, response) {
|
||||
let obj = {id: "asdf-1234-asdf-1234-2",
|
||||
modified: "2454725.98283",
|
||||
payload: json.encode({type: "privkey",
|
||||
payload: JSON.stringify({type: "privkey",
|
||||
public_key: "http://localhost:8080/pubkey",
|
||||
key_data: "asdfasdfasf..."})};
|
||||
return httpd_basic_auth_handler(json.encode(obj), metadata, response);
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function async_test() {
|
||||
|
|
|
@ -9,13 +9,11 @@ try {
|
|||
|
||||
Function.prototype.async = Async.sugar;
|
||||
|
||||
let json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
|
||||
|
||||
function record_handler(metadata, response) {
|
||||
let obj = {id: "asdf-1234-asdf-1234",
|
||||
modified: "2454725.98283",
|
||||
payload: json.encode({cheese: "roquefort"})};
|
||||
return httpd_basic_auth_handler(json.encode(obj), metadata, response);
|
||||
payload: JSON.stringify({cheese: "roquefort"})};
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function async_test() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче