Revert "Wrap JSON.parse in try/catch"

This reverts commit 6704120105.
This commit is contained in:
wltsmrz
2013-06-26 03:41:46 +09:00
parent daaac98bef
commit 13b7c9bfbb

View File

@@ -45,8 +45,8 @@ var Request = function (remote, command) {
this.remote = remote;
this.requested = false;
this.message = {
'command': command,
'id': void(0)
'command' : command,
'id' : void(0),
};
};
@@ -108,7 +108,7 @@ Request.prototype.ledger_select = function (ledger_spec) {
if (String(ledger_spec).length > 12) {
this.message.ledger_hash = ledger_spec;
} else {
this.message.ledger_index = ledger_spec;
this.message.ledger_index = ledger_spec;
}
}
@@ -132,8 +132,8 @@ Request.prototype.index = function (hash) {
// --> seq : sequence number of transaction creating offer (integer)
Request.prototype.offer_id = function (account, seq) {
this.message.offer = {
'account': UInt160.json_rewrite(account),
'seq': seq
'account' : UInt160.json_rewrite(account),
'seq' : seq
};
return this;
@@ -185,19 +185,20 @@ Request.prototype.ripple_state = function (account, issuer, currency) {
};
Request.prototype.accounts = function (accounts, realtime) {
if (!Array.isArray(accounts)) {
accounts = [ accounts ];
if (typeof accounts !== 'object') {
accounts = [accounts];
}
// Process accounts parameters
var procAccounts = accounts.map(function(account) {
return UInt160.json_rewrite(account);
});
var procAccounts = [];
for (var i = 0, l = accounts.length; i < l; i++) {
procAccounts.push(UInt160.json_rewrite(accounts[i]));
}
if (realtime) {
this.message.rt_accounts = procAccounts;
} else {
this.message.accounts = procAccounts;
this.message.accounts = procAccounts;
}
return this;
@@ -313,7 +314,7 @@ var Remote = function (opts, trace) {
// Local signing implies local fees and sequences
if (this.local_signing) {
this.local_sequence = true;
this.local_fee = true;
this.local_fee = true;
}
this._servers = [];
@@ -326,6 +327,7 @@ var Remote = function (opts, trace) {
// Otherwise, clear it to have it automatically refreshed from the network.
// account : { seq : __ }
};
// Hash map of Account objects by AccountId.
@@ -349,31 +351,33 @@ var Remote = function (opts, trace) {
}
};
// Support old API
if (!('servers' in opts)) {
opts.servers = [ {
host: opts.websocket_ip,
port: opts.websocket_port,
secure: opts.websocket_ssl,
trusted: opts.trusted
} ]
opts.servers = [
{
host: opts.websocket_ip,
port: opts.websocket_port,
secure: opts.websocket_ssl,
trusted: opts.trusted
}
]
}
// Initialize servers
opts.servers.forEach(function(server) {
self.add_server(server);
});
for (var i=0; i<opts.servers.length; i++) {
this.add_server(opts.servers[i]);
}
// This is used to remove EventEmitter warnings
if ('maxListeners' in opts) {
this._servers.concat(this).forEach(function(i) {
i.setMaxListeners(opts.maxListeners);
});
// This is used to remove Emitter warnings
this.setMaxListeners(opts.maxListeners)
for (var i=0; i<this._servers.length; i++) {
this._servers[i].setMaxListeners(opts.maxListeners);
}
}
// XXX Add support for multiple servers
this.on('newListener', function (type, listener) {
if ('transaction_all' === type) {
if (!self._transaction_subs && self._online_state === 'open') {
if (!self._transaction_subs && 'open' === self._online_state) {
self.request_subscribe('transactions').request();
}
self._transaction_subs += 1;
@@ -383,7 +387,7 @@ var Remote = function (opts, trace) {
this.on('removeListener', function (type, listener) {
if ('transaction_all' === type) {
self._transaction_subs -= 1;
if (!self._transaction_subs && self._online_state === 'open') {
if (!self._transaction_subs && 'open' === self._online_state) {
self.request_unsubscribe('transactions').request();
}
}
@@ -403,13 +407,13 @@ Remote.flags = {
};
Remote.from_config = function (obj, trace) {
var serverConfig = typeof obj === 'string' ? config.servers[obj] : obj;
var serverConfig = 'string' === typeof obj ? config.servers[obj] : obj;
var remote = new Remote(serverConfig, trace);
for (var account in config.accounts) {
var accountInfo = config.accounts[account];
if (typeof accountInfo === 'object') {
if ('object' === typeof accountInfo) {
if (accountInfo.secret) {
// Index by nickname ...
remote.set_secret(account, accountInfo.secret);
@@ -508,7 +512,7 @@ Remote.prototype.set_trace = function (trace) {
*/
Remote.prototype.connect = function (online) {
// Downwards compatibility
if (typeof online !== 'undefined' && !online) {
if ('undefined' !== typeof online && !online) {
return this.disconnect();
}
@@ -543,18 +547,14 @@ Remote.prototype.ledger_hash = function () {
// It is possible for messages to be dispatched after the connection is closed.
Remote.prototype._handle_message = function (json) {
var self = this;
var message = JSON.parse(json);
var unexpected = false;
var request, message;
var request;
try {
message = JSON.parse(json);
} catch(exception) {
unexpected = true;
}
if (typeof message !== 'object') {
if ('object' !== typeof message) {
unexpected = true;
} else {
}
else {
switch (message.type) {
case 'response':
// Handled by the server that sent the request
@@ -837,6 +837,7 @@ Remote.prototype.request_subscribe = function (streams) {
return request;
};
// .accounts(accounts, realtime)
Remote.prototype.request_unsubscribe = function (streams) {
var request = new Request(this, 'unsubscribe');
@@ -1066,7 +1067,7 @@ Remote.prototype._server_prepare_subscribe = function () {
Remote.prototype.ledger_accept = function () {
if (this._stand_alone || undefined === this._stand_alone) {
var request = new Request(this, 'ledger_accept');
request.request();
request .request();
} else {
this.emit('error', {
'error' : 'notStandAlone'