mirror of https://github.com/embarklabs/embark.git
isolate eval in a module
This commit is contained in:
parent
a83cc6a44a
commit
3f3a129276
|
@ -1,5 +1,5 @@
|
||||||
var Web3 = require('web3');
|
|
||||||
var utils = require('./utils.js');
|
var utils = require('./utils.js');
|
||||||
|
var RunCode = require('./runCode.js');
|
||||||
|
|
||||||
var Console = function(options) {
|
var Console = function(options) {
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
|
@ -7,7 +7,7 @@ var Console = function(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Console.prototype.runCode = function(code) {
|
Console.prototype.runCode = function(code) {
|
||||||
eval(code); // jshint ignore:line
|
RunCode.doEval(code); // jshint ignore:line
|
||||||
};
|
};
|
||||||
|
|
||||||
Console.prototype.executeCmd = function(cmd, callback) {
|
Console.prototype.executeCmd = function(cmd, callback) {
|
||||||
|
@ -37,7 +37,7 @@ Console.prototype.executeCmd = function(cmd, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var result = eval(cmd); // jshint ignore:line
|
var result = RunCode.doEval(cmd);
|
||||||
return callback(result);
|
return callback(result);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var DeployTracker = require('./deploy_tracker.js');
|
var DeployTracker = require('./deploy_tracker.js');
|
||||||
var ABIGenerator = require('./abi.js');
|
var ABIGenerator = require('./abi.js');
|
||||||
var web3;
|
var RunCode = require('./runCode.js');
|
||||||
|
|
||||||
var Deploy = function(options) {
|
var Deploy = function(options) {
|
||||||
this.web3 = options.web3;
|
this.web3 = options.web3;
|
||||||
|
@ -76,17 +76,13 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
|
||||||
self.deployTracker.save();
|
self.deployTracker.save();
|
||||||
self.logger.contractsState(self.contractsManager.contractsState());
|
self.logger.contractsState(self.contractsManager.contractsState());
|
||||||
|
|
||||||
// TODO: replace evals with separate process so it's isolated and with
|
|
||||||
// a callback
|
|
||||||
if (contract.onDeploy !== undefined) {
|
if (contract.onDeploy !== undefined) {
|
||||||
self.logger.info('executing onDeploy commands');
|
self.logger.info('executing onDeploy commands');
|
||||||
var abiGenerator = new ABIGenerator({contractsManager: self.contractsManager});
|
var abiGenerator = new ABIGenerator({contractsManager: self.contractsManager});
|
||||||
web3 = self.web3;
|
|
||||||
var abi = abiGenerator.generateContracts(false);
|
var abi = abiGenerator.generateContracts(false);
|
||||||
eval(abi); // jshint ignore:line
|
|
||||||
|
|
||||||
var cmds = contract.onDeploy.join(';\n');
|
var cmds = contract.onDeploy.join(';\n');
|
||||||
eval(cmds); // jshint ignore:line
|
|
||||||
|
RunCode.doEval(abi + "\n" + cmds, self.web3);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
var Web3 = require('web3');
|
||||||
|
var web3;
|
||||||
|
|
||||||
|
// ======================
|
||||||
|
// the eval is used for evaluating some of the contact calls for different purposes
|
||||||
|
// this should be at least moved to a different process and scope
|
||||||
|
// for now it is defined here
|
||||||
|
// ======================
|
||||||
|
function doEval(code, _web3) {
|
||||||
|
if (_web3) {
|
||||||
|
web3 = _web3;
|
||||||
|
}
|
||||||
|
return eval(code); // jshint ignore:line
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
doEval: doEval
|
||||||
|
};
|
|
@ -6,6 +6,7 @@ var Deploy = require('./deploy.js');
|
||||||
var TestLogger = require('./test_logger.js');
|
var TestLogger = require('./test_logger.js');
|
||||||
var Config = require('./config.js');
|
var Config = require('./config.js');
|
||||||
var ABIGenerator = require('./abi.js');
|
var ABIGenerator = require('./abi.js');
|
||||||
|
var RunCode = require('./runCode.js');
|
||||||
|
|
||||||
var Test = function(_options) {
|
var Test = function(_options) {
|
||||||
var options = _options || {};
|
var options = _options || {};
|
||||||
|
@ -80,11 +81,8 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
var web3 = self.web3;
|
self.web3.eth.defaultAccount = accounts[0];
|
||||||
web3.eth.defaultAccount = accounts[0];
|
RunCode.doEval(result, self.web3); // jshint ignore:line
|
||||||
// TODO: replace evals with separate process so it's isolated and with
|
|
||||||
// a callback
|
|
||||||
eval(result); // jshint ignore:line
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue