Add console/require to codeRunner

This commit is contained in:
Anthony Laibe 2018-08-28 12:16:36 +01:00
parent 307b7dc8e7
commit 6a2b91d99b
3 changed files with 7 additions and 8 deletions

View File

@ -2,7 +2,6 @@ const RunCode = require('./runCode.js');
const EmbarkJS = require('embarkjs');
const IpfsApi = require('ipfs-api');
const Web3 = require('web3');
const namehash = require('eth-ens-namehash');
class CodeRunner {
constructor(options) {
@ -29,16 +28,17 @@ class CodeRunner {
self.events.request("runcode:eval", command.code);
}
});
} else {
}
if (!this.ipc.connected) {
this.runCode.registerVar('IpfsApi', IpfsApi);
this.runCode.registerVar('Web3', Web3);
this.runCode.registerVar('namehash', namehash);
this.runCode.registerVar('EmbarkJS', EmbarkJS);
this.events.on('code-generator-ready', () => {
this.events.request('code-generator:embarkjs:initialization-code', (code) => {
this.runCode.doEval(code);
});
})
});
}
this.events.on("runcode:register", (varName, code) => {

View File

@ -2,7 +2,7 @@ const vm = require('vm');
class RunCode {
constructor() {
this.context = Object.assign({}, global.this);
this.context = Object.assign({}, {require, console, ...global.this});
}
doEval(code) {
@ -19,8 +19,6 @@ class RunCode {
// /*global web3*/
if (varName === 'web3') {
global.web3 = code;
} else if (varName === 'namehash') {
global.namehash = code;
}
this.context[varName] = code;
}

View File

@ -1,4 +1,5 @@
/*global web3, namehash*/
/*global web3*/
const namehash = require('eth-ens-namehash');
function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, secureSend, callback) {
const subnode = namehash.hash(subdomain);