From 6a2b91d99ba5416ac59466bda2b8b0a9f4b303d2 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 28 Aug 2018 12:16:36 +0100 Subject: [PATCH] Add console/require to codeRunner --- lib/core/modules/coderunner/codeRunner.js | 8 ++++---- lib/core/modules/coderunner/runCode.js | 4 +--- lib/modules/ens/register.js | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/core/modules/coderunner/codeRunner.js b/lib/core/modules/coderunner/codeRunner.js index 951e6c54..be1bb964 100644 --- a/lib/core/modules/coderunner/codeRunner.js +++ b/lib/core/modules/coderunner/codeRunner.js @@ -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) => { diff --git a/lib/core/modules/coderunner/runCode.js b/lib/core/modules/coderunner/runCode.js index d3c422a2..1e080a52 100644 --- a/lib/core/modules/coderunner/runCode.js +++ b/lib/core/modules/coderunner/runCode.js @@ -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; } diff --git a/lib/modules/ens/register.js b/lib/modules/ens/register.js index 5a34e71e..1ebf3478 100644 --- a/lib/modules/ens/register.js +++ b/lib/modules/ens/register.js @@ -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);