make linter happy

pull/7/head
Iuri Matias 6 years ago
parent 3ea9af71e7
commit 06071125b3
  1. 87
      remix-debug/rdb.js
  2. 2
      remix-debug/src/cmdline/contextManager.js
  3. 111
      remix-debug/src/cmdline/index.js
  4. 4
      remix-debug/src/debugger/debugger.js
  5. 2
      remix-debug/src/debugger/solidityLocals.js
  6. 5
      remix-debug/src/debugger/solidityState.js
  7. 20
      remix-debug/src/debugger/stepManager.js

@ -1,13 +1,13 @@
var CmdLine = require('./src/cmdline/index.js')
var compilation = require('./compilation.json')
// var compilation = require('./compilation.json')
var solc = require('solc')
var fs = require('fs')
var filename = 'test/sol/simple_storage.sol'
var short_filename = "simple_storage.sol"
var shortFilename = 'simple_storage.sol'
var input_json = {
var inputJson = {
language: 'Solidity',
sources: {
},
@ -25,85 +25,84 @@ var input_json = {
}
}
input_json.sources[short_filename] = {content: fs.readFileSync(filename).toString()}
inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}
console.dir(input_json)
console.dir(inputJson)
console.log("compiling...")
console.log('compiling...')
let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(input_json)))
let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
console.dir(Object.keys(compilationData))
var compilation = {}
compilation.data = compilationData
compilation.source = { sources: input_json.sources }
compilation.source = { sources: inputJson.sources }
console.dir(compilation)
console.dir(compilation.data.errors)
var cmd_line = new CmdLine()
cmd_line.connect("http", "http://localhost:8545")
cmd_line.loadCompilationResult(compilation)
cmd_line.initDebugger()
var deployContract = function (cb) {
let _web3 = cmd_line.debugger.debugger.web3
let blockNumber = null
let txNumber = null
let tx = null
let code = compilation.data.contracts[short_filename].SimpleStorage.evm.bytecode.object
console.dir("deploying...")
console.dir(code)
_web3.eth.sendTransaction({data: "0x" + code, from: _web3.eth.accounts[0], gas: 800000}, cb)
}
let _web3 = cmd_line.debugger.debugger.web3
var tx = "0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa"
var cmdLine = new CmdLine()
cmdLine.connect('http', 'http://localhost:8545')
cmdLine.loadCompilationResult(compilation)
cmdLine.initDebugger()
// var deployContract = function (cb) {
// let _web3 = cmdLine.debugger.debugger.web3
//
// let blockNumber = null
// let txNumber = null
// let tx = null
//
// let code = compilation.data.contracts[shortFilename].SimpleStorage.evm.bytecode.object
// console.dir('deploying...')
// console.dir(code)
// _web3.eth.sendTransaction({data: '0x' + code, from: _web3.eth.accounts[0], gas: 800000}, cb)
// }
// let _web3 = cmdLine.debugger.debugger.web3
var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
// deployContract((err, tx) => {
cmd_line.startDebug(tx, short_filename)
cmdLine.startDebug(tx, shortFilename)
cmd_line.events.on("source", () => {
cmd_line.getSource().forEach(console.dir)
cmdLine.events.on('source', () => {
cmdLine.getSource().forEach(console.dir)
})
// })
//})
// })
const repl = require('repl')
const r = repl.start({
repl.start({
prompt: '> ',
eval: (cmd, context, filename, cb) => {
let command = cmd.trim()
if (command === 'next' || command === 'n') {
cmd_line.stepOverForward(true)
cmdLine.stepOverForward(true)
}
if (command === 'previous' || command === 'p' || command === 'prev') {
cmd_line.stepOverBack(true)
cmdLine.stepOverBack(true)
}
if (command === 'step' || command === 's') {
cmd_line.stepIntoForward(true)
cmdLine.stepIntoForward(true)
}
if (command === 'stepback' || command === 'sb') {
cmd_line.stepIntoBack(true)
cmdLine.stepIntoBack(true)
}
if (command === 'exit' || command === 'quit') {
process.exit(0)
}
if (command === 'var local' || command === 'v l' || command === 'vl') {
cmd_line.displayLocals()
cmdLine.displayLocals()
}
if (command === 'var global' || command === 'v g' || command === 'vg') {
cmd_line.displayGlobals()
cmdLine.displayGlobals()
}
if (command.split(' ')[0] === 'jump') {
let stepIndex = parseInt(command.split(' ')[1], 10)
cmd_line.jumpTo(stepIndex)
cmdLine.jumpTo(stepIndex)
}
cb(null, '');
cb(null, '')
}
});
module.exports = cmd_line
})
module.exports = cmdLine

@ -48,7 +48,7 @@ class ContextManager {
self.web3 = (!webDebugNode ? obj : webDebugNode)
}
self.event.trigger('providerChanged', [type, self.web3])
if (cb) return cb();
if (cb) return cb()
})
self.event.trigger('providerChanged', [type, self.web3])
}

@ -12,7 +12,7 @@ class CmdLine {
}
connect (providerType, url) {
if (providerType !== 'http') throw new Error("unsupported provider type")
if (providerType !== 'http') throw new Error('unsupported provider type')
this.web3 = new Web3(new Web3.providers.HttpProvider(url))
}
@ -47,167 +47,166 @@ class CmdLine {
this.contextManager.switchProvider('debugger_web3', cb)
}
getSource() {
getSource () {
const self = this
let lineColumnPos = this.lineColumnPos
if (!lineColumnPos || !lineColumnPos.start) return [];
if (!lineColumnPos || !lineColumnPos.start) return []
let content = self.compilation.lastCompilationResult.source.sources[this.filename].content.split("\n")
let content = self.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')
let source = []
let line
line = content[lineColumnPos.start.line - 2]
if ( line !== undefined) {
source.push(" " + (lineColumnPos.start.line - 1) + ": " + line)
if (line !== undefined) {
source.push(' ' + (lineColumnPos.start.line - 1) + ': ' + line)
}
line = content[lineColumnPos.start.line - 1]
if ( line !== undefined) {
source.push(" " + lineColumnPos.start.line + ": " + line)
if (line !== undefined) {
source.push(' ' + lineColumnPos.start.line + ': ' + line)
}
let currentLineNumber = lineColumnPos.start.line
let currentLine = content[currentLineNumber]
source.push("=> " + (currentLineNumber + 1) + ": " + currentLine)
source.push('=> ' + (currentLineNumber + 1) + ': ' + currentLine)
let startLine = lineColumnPos.start.line
for (var i=1; i < 4; i++) {
for (var i = 1; i < 4; i++) {
let line = content[startLine + i]
source.push(" " + (startLine + i + 1) + ": " + line)
source.push(' ' + (startLine + i + 1) + ': ' + line)
}
return source
}
getCurrentLine() {
getCurrentLine () {
let lineColumnPos = this.lineColumnPos
if (!lineColumnPos) return ""
if (!lineColumnPos) return ''
let currentLineNumber = lineColumnPos.start.line
let content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split("\n")
let content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')
return content[currentLineNumber]
}
startDebug(txNumber, filename, cb) {
startDebug (txNumber, filename, cb) {
const self = this
this.filename = filename
this.txHash = txNumber
this.debugger.debug(null, txNumber, null, () => {
self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) {
self.lineColumnPos = lineColumnPos
self.rawLocation = rawLocation
self.events.emit("source", [lineColumnPos, rawLocation])
});
self.events.emit('source', [lineColumnPos, rawLocation])
})
self.debugger.vmDebuggerLogic.event.register('solidityState', (data) => {
self.solidityState = data
self.events.emit("globals", data)
});
self.events.emit('globals', data)
})
// TODO: this doesnt work too well, it should request the data instead...
self.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => {
if (JSON.stringify(data) === '{}') return
self.solidityLocals = data
self.events.emit("locals", data)
});
self.events.emit('locals', data)
})
if (cb) {
// TODO: this should be an onReady event
setTimeout(cb, 1000);
setTimeout(cb, 1000)
}
})
}
getVars() {
getVars () {
return {
locals: this.solidityLocals,
contract: this.solidityState
}
}
triggerSourceUpdate() {
this.events.emit("source", [this.lineColumnPos, this.rawLocation])
triggerSourceUpdate () {
this.events.emit('source', [this.lineColumnPos, this.rawLocation])
}
stepJumpNextBreakpoint() {
this.debugger.step_manager.jumpNextBreakpoint()
stepJumpNextBreakpoint () {
this.debugger.step_manager.jumpNextBreakpoint()
}
stepJumpPreviousBreakpoint() {
this.debugger.step_manager.jumpPreviousBreakpoint()
stepJumpPreviousBreakpoint () {
this.debugger.step_manager.jumpPreviousBreakpoint()
}
stepOverForward(solidityMode) {
this.debugger.step_manager.stepOverForward(solidityMode)
stepOverForward (solidityMode) {
this.debugger.step_manager.stepOverForward(solidityMode)
}
stepOverBack(solidityMode) {
this.debugger.step_manager.stepOverBack(solidityMode)
stepOverBack (solidityMode) {
this.debugger.step_manager.stepOverBack(solidityMode)
}
stepIntoForward(solidityMode) {
this.debugger.step_manager.stepIntoForward(solidityMode)
stepIntoForward (solidityMode) {
this.debugger.step_manager.stepIntoForward(solidityMode)
}
stepIntoBack(solidityMode) {
this.debugger.step_manager.stepIntoBack(solidityMode)
stepIntoBack (solidityMode) {
this.debugger.step_manager.stepIntoBack(solidityMode)
}
jumpTo(step) {
jumpTo (step) {
this.debugger.step_manager.jumpTo(step)
}
getTraceLength() {
if (!this.debugger.step_manager) return 0;
getTraceLength () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.traceLength
}
getCodeFirstStep() {
if (!this.debugger.step_manager) return 0;
getCodeFirstStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.calculateFirstStep()
}
getCodeTraceLength() {
if (!this.debugger.step_manager) return 0;
getCodeTraceLength () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.calculateCodeLength()
}
nextStep() {
if (!this.debugger.step_manager) return 0;
nextStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.nextStep()
}
previousStep() {
if (!this.debugger.step_manager) return 0;
previousStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.previousStep()
}
currentStep() {
if (!this.debugger.step_manager) return 0;
currentStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.currentStepIndex
}
canGoNext() {
canGoNext () {
return this.currentStep() < this.getCodeTraceLength()
}
canGoPrevious() {
canGoPrevious () {
return this.currentStep() > this.getCodeFirstStep()
}
unload() {
unload () {
return this.debugger.unload()
}
displayLocals () {
console.dir("= displayLocals")
console.dir('= displayLocals')
console.dir(this.solidityLocals)
}
displayGlobals () {
console.dir("= displayGlobals")
console.dir('= displayGlobals')
console.dir(this.solidityState)
}
}

@ -112,11 +112,11 @@ Debugger.prototype.debugTx = function (tx, loadingCb) {
})
this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree)
this.vmDebuggerLogic.start()
this.vmDebuggerLogic.start()
this.step_manager.event.register('stepChanged', this, function (stepIndex) {
if (!stepIndex) {
return self.event.trigger("endDebug")
return self.event.trigger('endDebug')
}
self.debugger.codeManager.resolveStep(stepIndex, tx)

@ -40,7 +40,7 @@ class DebuggerSolidityLocals {
self.stepManager.currentStepIndex,
(error, result) => {
if (error) {
return error;
return error
}
var stack = result[0].value
var memory = result[1].value

@ -39,11 +39,10 @@ class DebuggerSolidityState {
// necessary due to some states that can crash the debugger
try {
self.decode(index)
} catch(err) {
console.dir("====> error")
} catch (err) {
console.dir('====> error')
console.dir(err)
}
}, 500)
}

@ -158,17 +158,17 @@ class DebuggerStepManager {
this.debugger.breakpointManager.jumpPreviousBreakpoint(this.currentStepIndex, true)
}
calculateFirstStep() {
calculateFirstStep () {
let step = this.resolveToReducedTrace(0, 1)
return this.resolveToReducedTrace(step, 1)
}
calculateCodeStepList() {
calculateCodeStepList () {
let step = 0
let steps = []
while (step < this.traceLength) {
let _step = this.resolveToReducedTrace(step, 1)
if (!_step) break;
if (!_step) break
steps.push(_step)
step += 1
}
@ -176,17 +176,17 @@ class DebuggerStepManager {
return steps
}
calculateCodeLength() {
let steps = this.calculateCodeStepList().reverse()
return this.calculateCodeStepList().reverse()[1] || this.traceLength;
calculateCodeLength () {
this.calculateCodeStepList().reverse()
return this.calculateCodeStepList().reverse()[1] || this.traceLength
}
nextStep() {
return this.resolveToReducedTrace(this.currentStepIndex, 1);
nextStep () {
return this.resolveToReducedTrace(this.currentStepIndex, 1)
}
previousStep() {
return this.resolveToReducedTrace(this.currentStepIndex, -1);
previousStep () {
return this.resolveToReducedTrace(this.currentStepIndex, -1)
}
resolveToReducedTrace (value, incr) {

Loading…
Cancel
Save