Replace instanceof Array with Array.isArray because of reasons. (#995)

This commit is contained in:
Allen McCabe 2017-09-15 04:08:01 -07:00 committed by Fabian Vogelsteller
parent 530c4a3b1d
commit f74d60c171
5 changed files with 99 additions and 99 deletions

82
dist/web3-light.js vendored
View File

@ -1192,7 +1192,7 @@ module.exports = SolidityTypeInt;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file param.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -1211,7 +1211,7 @@ var SolidityParam = function (value, offset) {
/**
* This method should be used to get length of params's dynamic part
*
*
* @method dynamicPartLength
* @returns {Number} length of dynamic part (in bytes)
*/
@ -1239,7 +1239,7 @@ SolidityParam.prototype.withOffset = function (offset) {
* @param {SolidityParam} result of combination
*/
SolidityParam.prototype.combine = function (param) {
return new SolidityParam(this.value + param.value);
return new SolidityParam(this.value + param.value);
};
/**
@ -1271,8 +1271,8 @@ SolidityParam.prototype.offsetAsBytes = function () {
*/
SolidityParam.prototype.staticPart = function () {
if (!this.isDynamic()) {
return this.value;
}
return this.value;
}
return this.offsetAsBytes();
};
@ -1304,7 +1304,7 @@ SolidityParam.prototype.encode = function () {
* @returns {String}
*/
SolidityParam.encodeList = function (params) {
// updating offsets
var totalOffset = params.length * 32;
var offsetParams = params.map(function (param) {
@ -1746,13 +1746,13 @@ if (typeof XMLHttpRequest === 'undefined') {
/**
* Utils
*
*
* @module utils
*/
/**
* Utility functions
*
*
* @class [utils] config
* @constructor
*/
@ -1819,7 +1819,7 @@ module.exports = {
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file sha3.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -2368,7 +2368,7 @@ var isFunction = function (object) {
* @return {Boolean}
*/
var isObject = function (object) {
return object !== null && !(object instanceof Array) && typeof object === 'object';
return object !== null && !(Array.isArray(object)) && typeof object === 'object';
};
/**
@ -2390,7 +2390,7 @@ var isBoolean = function (object) {
* @return {Boolean}
*/
var isArray = function (object) {
return object instanceof Array;
return Array.isArray(object);
};
/**
@ -2739,7 +2739,7 @@ module.exports = AllSolidityEvents;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file batch.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -2784,7 +2784,7 @@ Batch.prototype.execute = function () {
requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
}
});
});
});
};
module.exports = Batch;
@ -2971,7 +2971,7 @@ var ContractFactory = function (eth, abi) {
*/
this.new = function () {
/*jshint maxcomplexity: 7 */
var contract = new Contract(this.eth, this.abi);
// parse arguments
@ -3119,7 +3119,7 @@ module.exports = ContractFactory;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file errors.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -3394,7 +3394,7 @@ var extend = function (web3) {
}
};
ex.formatters = formatters;
ex.formatters = formatters;
ex.utils = utils;
ex.Method = Method;
ex.Property = Property;
@ -4425,7 +4425,7 @@ module.exports = HttpProvider;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file iban.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -4625,7 +4625,7 @@ Iban.prototype.address = function () {
var base36 = this._iban.substr(4);
var asBn = new BigNumber(base36, 36);
return padLeft(asBn.toString(16), 20);
}
}
return '';
};
@ -4670,7 +4670,7 @@ var IpcProvider = function (path, net) {
var _this = this;
this.responseCallbacks = {};
this.path = path;
this.connection = net.connect({path: this.path});
this.connection.on('error', function(e){
@ -4680,7 +4680,7 @@ var IpcProvider = function (path, net) {
this.connection.on('end', function(){
_this._timeout();
});
});
// LISTEN FOR CONNECTION RESPONSES
@ -4719,7 +4719,7 @@ Will parse the response and make an array out of it.
IpcProvider.prototype._parseResponse = function(data) {
var _this = this,
returnValues = [];
// DE-CHUNKER
var dechunkedData = data
.replace(/\}[\n\r]?\{/g,'}|--|{') // }{
@ -4823,7 +4823,7 @@ IpcProvider.prototype.send = function (payload) {
try {
result = JSON.parse(data);
} catch(e) {
throw errors.InvalidResponse(data);
throw errors.InvalidResponse(data);
}
return result;
@ -4998,7 +4998,7 @@ Method.prototype.extractCallback = function (args) {
/**
* Should be called to check if the number of arguments is correct
*
*
* @method validateArgs
* @param {Array} arguments
* @throws {Error} if it is not
@ -5011,7 +5011,7 @@ Method.prototype.validateArgs = function (args) {
/**
* Should be called to format input args of method
*
*
* @method formatInput
* @param {Array}
* @return {Array}
@ -5065,7 +5065,7 @@ Method.prototype.attachToObject = function (obj) {
obj[name[0]] = obj[name[0]] || {};
obj[name[0]][name[1]] = func;
} else {
obj[name[0]] = func;
obj[name[0]] = func;
}
};
@ -5128,8 +5128,8 @@ var DB = function (web3) {
this._requestManager = web3._requestManager;
var self = this;
methods().forEach(function(method) {
methods().forEach(function(method) {
method.attachToObject(self);
method.setRequestManager(web3._requestManager);
});
@ -5554,7 +5554,7 @@ var Net = function (web3) {
var self = this;
properties().forEach(function(p) {
properties().forEach(function(p) {
p.attachToObject(self);
p.setRequestManager(web3._requestManager);
});
@ -6113,7 +6113,7 @@ module.exports = {
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file namereg.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -6300,7 +6300,7 @@ module.exports = Property;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file requestmanager.js
* @author Jeffrey Wilcke <jeff@ethdev.com>
* @author Marek Kotewicz <marek@ethdev.com>
@ -6367,7 +6367,7 @@ RequestManager.prototype.sendAsync = function (data, callback) {
if (err) {
return callback(err);
}
if (!Jsonrpc.isValidResponse(result)) {
return callback(errors.InvalidResponse(result));
}
@ -6400,7 +6400,7 @@ RequestManager.prototype.sendBatch = function (data, callback) {
}
callback(err, results);
});
});
};
/**
@ -6504,7 +6504,7 @@ RequestManager.prototype.poll = function () {
}
var payload = Jsonrpc.toBatchPayload(pollsData);
// map the request id to they poll id
var pollsIdMap = {};
payload.forEach(function(load, index){
@ -6534,7 +6534,7 @@ RequestManager.prototype.poll = function () {
} else
return false;
}).filter(function (result) {
return !!result;
return !!result;
}).filter(function (result) {
var valid = Jsonrpc.isValidResponse(result);
if (!valid) {
@ -6609,16 +6609,16 @@ var pollSyncing = function(self) {
self.callbacks.forEach(function (callback) {
if (self.lastSyncState !== sync) {
// call the callback with true first so the app can stop anything, before receiving the sync data
if(!self.lastSyncState && utils.isObject(sync))
callback(null, true);
// call on the next CPU cycle, so the actions of the sync stop can be processes first
setTimeout(function() {
callback(null, sync);
}, 0);
self.lastSyncState = sync;
}
});
@ -6673,7 +6673,7 @@ module.exports = IsSyncing;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file transfer.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -6692,7 +6692,7 @@ var exchangeAbi = require('../contracts/SmartExchange.json');
* @param {Function} callback, callback
*/
var transfer = function (eth, from, to, value, callback) {
var iban = new Iban(to);
var iban = new Iban(to);
if (!iban.isValid()) {
throw new Error('invalid iban address');
}
@ -6700,7 +6700,7 @@ var transfer = function (eth, from, to, value, callback) {
if (iban.isDirect()) {
return transferToAddress(eth, from, iban.address(), value, callback);
}
if (!callback) {
var address = eth.icapNamereg().addr(iban.institution());
return deposit(eth, from, address, value, iban.client());
@ -6709,7 +6709,7 @@ var transfer = function (eth, from, to, value, callback) {
eth.icapNamereg().addr(iban.institution(), function (err, address) {
return deposit(eth, from, address, value, iban.client(), callback);
});
};
/**

82
dist/web3.js vendored
View File

@ -1192,7 +1192,7 @@ module.exports = SolidityTypeInt;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file param.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -1211,7 +1211,7 @@ var SolidityParam = function (value, offset) {
/**
* This method should be used to get length of params's dynamic part
*
*
* @method dynamicPartLength
* @returns {Number} length of dynamic part (in bytes)
*/
@ -1239,7 +1239,7 @@ SolidityParam.prototype.withOffset = function (offset) {
* @param {SolidityParam} result of combination
*/
SolidityParam.prototype.combine = function (param) {
return new SolidityParam(this.value + param.value);
return new SolidityParam(this.value + param.value);
};
/**
@ -1271,8 +1271,8 @@ SolidityParam.prototype.offsetAsBytes = function () {
*/
SolidityParam.prototype.staticPart = function () {
if (!this.isDynamic()) {
return this.value;
}
return this.value;
}
return this.offsetAsBytes();
};
@ -1304,7 +1304,7 @@ SolidityParam.prototype.encode = function () {
* @returns {String}
*/
SolidityParam.encodeList = function (params) {
// updating offsets
var totalOffset = params.length * 32;
var offsetParams = params.map(function (param) {
@ -1746,13 +1746,13 @@ if (typeof XMLHttpRequest === 'undefined') {
/**
* Utils
*
*
* @module utils
*/
/**
* Utility functions
*
*
* @class [utils] config
* @constructor
*/
@ -1819,7 +1819,7 @@ module.exports = {
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file sha3.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -2368,7 +2368,7 @@ var isFunction = function (object) {
* @return {Boolean}
*/
var isObject = function (object) {
return object !== null && !(object instanceof Array) && typeof object === 'object';
return object !== null && !(Array.isArray(object)) && typeof object === 'object';
};
/**
@ -2390,7 +2390,7 @@ var isBoolean = function (object) {
* @return {Boolean}
*/
var isArray = function (object) {
return object instanceof Array;
return Array.isArray(object);
};
/**
@ -2739,7 +2739,7 @@ module.exports = AllSolidityEvents;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file batch.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -2784,7 +2784,7 @@ Batch.prototype.execute = function () {
requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
}
});
});
});
};
module.exports = Batch;
@ -2971,7 +2971,7 @@ var ContractFactory = function (eth, abi) {
*/
this.new = function () {
/*jshint maxcomplexity: 7 */
var contract = new Contract(this.eth, this.abi);
// parse arguments
@ -3119,7 +3119,7 @@ module.exports = ContractFactory;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file errors.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -3394,7 +3394,7 @@ var extend = function (web3) {
}
};
ex.formatters = formatters;
ex.formatters = formatters;
ex.utils = utils;
ex.Method = Method;
ex.Property = Property;
@ -4425,7 +4425,7 @@ module.exports = HttpProvider;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file iban.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -4625,7 +4625,7 @@ Iban.prototype.address = function () {
var base36 = this._iban.substr(4);
var asBn = new BigNumber(base36, 36);
return padLeft(asBn.toString(16), 20);
}
}
return '';
};
@ -4670,7 +4670,7 @@ var IpcProvider = function (path, net) {
var _this = this;
this.responseCallbacks = {};
this.path = path;
this.connection = net.connect({path: this.path});
this.connection.on('error', function(e){
@ -4680,7 +4680,7 @@ var IpcProvider = function (path, net) {
this.connection.on('end', function(){
_this._timeout();
});
});
// LISTEN FOR CONNECTION RESPONSES
@ -4719,7 +4719,7 @@ Will parse the response and make an array out of it.
IpcProvider.prototype._parseResponse = function(data) {
var _this = this,
returnValues = [];
// DE-CHUNKER
var dechunkedData = data
.replace(/\}[\n\r]?\{/g,'}|--|{') // }{
@ -4823,7 +4823,7 @@ IpcProvider.prototype.send = function (payload) {
try {
result = JSON.parse(data);
} catch(e) {
throw errors.InvalidResponse(data);
throw errors.InvalidResponse(data);
}
return result;
@ -4998,7 +4998,7 @@ Method.prototype.extractCallback = function (args) {
/**
* Should be called to check if the number of arguments is correct
*
*
* @method validateArgs
* @param {Array} arguments
* @throws {Error} if it is not
@ -5011,7 +5011,7 @@ Method.prototype.validateArgs = function (args) {
/**
* Should be called to format input args of method
*
*
* @method formatInput
* @param {Array}
* @return {Array}
@ -5065,7 +5065,7 @@ Method.prototype.attachToObject = function (obj) {
obj[name[0]] = obj[name[0]] || {};
obj[name[0]][name[1]] = func;
} else {
obj[name[0]] = func;
obj[name[0]] = func;
}
};
@ -5128,8 +5128,8 @@ var DB = function (web3) {
this._requestManager = web3._requestManager;
var self = this;
methods().forEach(function(method) {
methods().forEach(function(method) {
method.attachToObject(self);
method.setRequestManager(web3._requestManager);
});
@ -5554,7 +5554,7 @@ var Net = function (web3) {
var self = this;
properties().forEach(function(p) {
properties().forEach(function(p) {
p.attachToObject(self);
p.setRequestManager(web3._requestManager);
});
@ -6113,7 +6113,7 @@ module.exports = {
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file namereg.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -6300,7 +6300,7 @@ module.exports = Property;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file requestmanager.js
* @author Jeffrey Wilcke <jeff@ethdev.com>
* @author Marek Kotewicz <marek@ethdev.com>
@ -6367,7 +6367,7 @@ RequestManager.prototype.sendAsync = function (data, callback) {
if (err) {
return callback(err);
}
if (!Jsonrpc.isValidResponse(result)) {
return callback(errors.InvalidResponse(result));
}
@ -6400,7 +6400,7 @@ RequestManager.prototype.sendBatch = function (data, callback) {
}
callback(err, results);
});
});
};
/**
@ -6504,7 +6504,7 @@ RequestManager.prototype.poll = function () {
}
var payload = Jsonrpc.toBatchPayload(pollsData);
// map the request id to they poll id
var pollsIdMap = {};
payload.forEach(function(load, index){
@ -6534,7 +6534,7 @@ RequestManager.prototype.poll = function () {
} else
return false;
}).filter(function (result) {
return !!result;
return !!result;
}).filter(function (result) {
var valid = Jsonrpc.isValidResponse(result);
if (!valid) {
@ -6609,16 +6609,16 @@ var pollSyncing = function(self) {
self.callbacks.forEach(function (callback) {
if (self.lastSyncState !== sync) {
// call the callback with true first so the app can stop anything, before receiving the sync data
if(!self.lastSyncState && utils.isObject(sync))
callback(null, true);
// call on the next CPU cycle, so the actions of the sync stop can be processes first
setTimeout(function() {
callback(null, sync);
}, 0);
self.lastSyncState = sync;
}
});
@ -6673,7 +6673,7 @@ module.exports = IsSyncing;
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
/**
* @file transfer.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
@ -6692,7 +6692,7 @@ var exchangeAbi = require('../contracts/SmartExchange.json');
* @param {Function} callback, callback
*/
var transfer = function (eth, from, to, value, callback) {
var iban = new Iban(to);
var iban = new Iban(to);
if (!iban.isValid()) {
throw new Error('invalid iban address');
}
@ -6700,7 +6700,7 @@ var transfer = function (eth, from, to, value, callback) {
if (iban.isDirect()) {
return transferToAddress(eth, from, iban.address(), value, callback);
}
if (!callback) {
var address = eth.icapNamereg().addr(iban.institution());
return deposit(eth, from, address, value, iban.client());
@ -6709,7 +6709,7 @@ var transfer = function (eth, from, to, value, callback) {
eth.icapNamereg().addr(iban.institution(), function (err, address) {
return deposit(eth, from, address, value, iban.client(), callback);
});
};
/**

View File

@ -523,7 +523,7 @@ var isFunction = function (object) {
* @return {Boolean}
*/
var isObject = function (object) {
return object !== null && !(object instanceof Array) && typeof object === 'object';
return object !== null && !(Array.isArray(object)) && typeof object === 'object';
};
/**
@ -545,7 +545,7 @@ var isBoolean = function (object) {
* @return {Boolean}
*/
var isArray = function (object) {
return object instanceof Array;
return Array.isArray(object);
};
/**

View File

@ -4,8 +4,8 @@ var Jsonrpc = require('../lib/web3/jsonrpc');
describe('jsonrpc', function () {
describe('toBatchPayload', function () {
it('should create basic batch payload', function () {
// given
// given
var messages = [{
method: 'helloworld'
}, {
@ -17,30 +17,30 @@ describe('jsonrpc', function () {
var payload = Jsonrpc.toBatchPayload(messages);
// then
assert.equal(payload instanceof Array, true);
assert.equal(Array.isArray(payload), true);
assert.equal(payload.length, 2);
assert.equal(payload[0].jsonrpc, '2.0');
assert.equal(payload[1].jsonrpc, '2.0');
assert.equal(payload[0].method, 'helloworld');
assert.equal(payload[1].method, 'test2');
assert.equal(payload[0].params instanceof Array, true);
assert.equal(Array.isArray(payload[0].params), true);
assert.equal(payload[1].params.length, 1);
assert.equal(payload[1].params[0], 1);
assert.equal(typeof payload[0].id, 'number');
assert.equal(typeof payload[1].id, 'number');
assert.equal(payload[0].id + 1, payload[1].id);
});
it('should create batch payload for empty input array', function () {
// given
// given
var messages = [];
// when
var payload = Jsonrpc.toBatchPayload(messages);
// then
assert.equal(payload instanceof Array, true);
assert.equal(Array.isArray(payload), true);
assert.equal(payload.length, 0);
});
});

View File

@ -1,12 +1,12 @@
var chai = require('chai');
var assert = chai.assert;
var assert = chai.assert;
var Jsonrpc = require('../lib/web3/jsonrpc');
describe('jsonrpc', function () {
describe('toPayload', function () {
it('should create basic payload', function () {
// given
// given
var method = 'helloworld';
// when
@ -15,14 +15,14 @@ describe('jsonrpc', function () {
// then
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, method);
assert.equal(payload.params instanceof Array, true);
assert.equal(Array.isArray(payload.params), true);
assert.equal(payload.params.length, 0);
assert.equal(typeof payload.id, 'number');
});
it('should create payload with params', function () {
// given
// given
var method = 'helloworld1';
var params = [123, 'test'];