Add console/require to codeRunner
This commit is contained in:
parent
307b7dc8e7
commit
6a2b91d99b
|
@ -2,7 +2,6 @@ const RunCode = require('./runCode.js');
|
||||||
const EmbarkJS = require('embarkjs');
|
const EmbarkJS = require('embarkjs');
|
||||||
const IpfsApi = require('ipfs-api');
|
const IpfsApi = require('ipfs-api');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const namehash = require('eth-ens-namehash');
|
|
||||||
|
|
||||||
class CodeRunner {
|
class CodeRunner {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -29,16 +28,17 @@ class CodeRunner {
|
||||||
self.events.request("runcode:eval", command.code);
|
self.events.request("runcode:eval", command.code);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (!this.ipc.connected) {
|
||||||
this.runCode.registerVar('IpfsApi', IpfsApi);
|
this.runCode.registerVar('IpfsApi', IpfsApi);
|
||||||
this.runCode.registerVar('Web3', Web3);
|
this.runCode.registerVar('Web3', Web3);
|
||||||
this.runCode.registerVar('namehash', namehash);
|
|
||||||
this.runCode.registerVar('EmbarkJS', EmbarkJS);
|
this.runCode.registerVar('EmbarkJS', EmbarkJS);
|
||||||
this.events.on('code-generator-ready', () => {
|
this.events.on('code-generator-ready', () => {
|
||||||
this.events.request('code-generator:embarkjs:initialization-code', (code) => {
|
this.events.request('code-generator:embarkjs:initialization-code', (code) => {
|
||||||
this.runCode.doEval(code);
|
this.runCode.doEval(code);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.events.on("runcode:register", (varName, code) => {
|
this.events.on("runcode:register", (varName, code) => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ const vm = require('vm');
|
||||||
|
|
||||||
class RunCode {
|
class RunCode {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.context = Object.assign({}, global.this);
|
this.context = Object.assign({}, {require, console, ...global.this});
|
||||||
}
|
}
|
||||||
|
|
||||||
doEval(code) {
|
doEval(code) {
|
||||||
|
@ -19,8 +19,6 @@ class RunCode {
|
||||||
// /*global web3*/
|
// /*global web3*/
|
||||||
if (varName === 'web3') {
|
if (varName === 'web3') {
|
||||||
global.web3 = code;
|
global.web3 = code;
|
||||||
} else if (varName === 'namehash') {
|
|
||||||
global.namehash = code;
|
|
||||||
}
|
}
|
||||||
this.context[varName] = code;
|
this.context[varName] = code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, secureSend, callback) {
|
||||||
const subnode = namehash.hash(subdomain);
|
const subnode = namehash.hash(subdomain);
|
||||||
|
|
Loading…
Reference in New Issue