Use JSON.parse instead of deprecated goog.json.parse.

Thanks to [] shared libraries at Google now produce valid JSON which allows using JSON.parse. It is safer and faster than goog.json.parse which uses eval by default.

NOTE: All shared libraries producing JSON at Google were changed to produce valid JSON. However, if your code uses a custom way of producing JSON (not using the shared libraries) or if your code parses JSON generated a long time ago and stored, this CL might break you so please review with care.

Design doc: []

Tested:
    TAP --sample for global presubmit queue
    []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166454709
This commit is contained in:
jakubvrana 2017-08-25 02:35:09 -07:00 committed by Ben McIlwain
parent 103b3d7608
commit 4a81236652
5 changed files with 5 additions and 5 deletions

View file

@ -123,7 +123,7 @@ registry.registrar.BrainFrame.prototype.onMessage_ = function(e) {
throw new Error(
'Message origin is "' + msg.origin + '" but wanted: ' + this.origin_);
}
var data = goog.json.parse(msg.data);
var data = /** @type {!Object} */ (JSON.parse(msg.data));
switch (goog.object.get(data, 'type')) {
case registry.registrar.BrainFrame.MessageType.TOKEN_RESPONSE:
goog.global.braintree.setup(goog.object.get(data, 'token'), 'dropin', {

View file

@ -165,7 +165,7 @@ registry.registrar.ContactSettings.prototype.sendDelete = function() {
throw new Error('Email to delete does not match model.');
}
var modelCopy = /** @type {!Object}
*/ (goog.json.parse(goog.json.serialize(this.model)));
*/ (JSON.parse(goog.json.serialize(this.model)));
goog.array.removeAt(modelCopy.contacts, ndxToDel);
this.resource.update(modelCopy, goog.bind(this.handleDeleteResponse, this));
};

View file

@ -285,7 +285,7 @@ registry.registrar.Payment.prototype.onMessage_ = function(e) {
}
var data;
try {
data = goog.json.parse(msg.data);
data = /** @type {!Object} */ (JSON.parse(msg.data));
} catch (ex) {
// TODO(b/26876003): Figure out why it's possible that the Braintree iframe
// is able to propagate messages up to our level.

View file

@ -119,7 +119,7 @@ registry.ResourceComponent.prototype.handleFetchItem = function(id, rsp) {
/** @override */
registry.ResourceComponent.prototype.sendUpdate = function() {
var modelCopy = /** @type {!Object}
*/ (goog.json.parse(goog.json.serialize(this.model)));
*/ (JSON.parse(goog.json.serialize(this.model)));
this.prepareUpdate(modelCopy);
if (this.id) {
this.resource.update(modelCopy, goog.bind(this.handleUpdateResponse, this));

View file

@ -131,7 +131,7 @@ registry.testing.assertReqMockRsp =
// XXX: XHR header checking should probably be added. Was inconsistent
// between admin and registrar consoles.
registry.testing.assertObjectEqualsPretty(
expectReqJson, goog.json.parse(xhr.getLastContent()));
expectReqJson, JSON.parse(xhr.getLastContent()));
xhr.simulateResponse(200, goog.json.serialize(mockRspJson));
};