Commit 68b4b822 authored by Iuri Matias's avatar Iuri Matias Committed by aniket-engg

refactor getReturnValue value

parent 13fe9cb6
...@@ -145,13 +145,14 @@ class VmDebuggerLogic { ...@@ -145,13 +145,14 @@ class VmDebuggerLogic {
this.event.trigger('traceRemainingGasUpdate', [error]) this.event.trigger('traceRemainingGasUpdate', [error])
} }
this._traceManager.getReturnValue(index, (error, returnValue) => { try {
if (error) { const returnValue = this._traceManager.getReturnValue(index)
this.event.trigger('traceReturnValueUpdate', [[error]]) if (this.stepManager.currentStepIndex === index) {
} else if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceReturnValueUpdate', [[returnValue]]) this.event.trigger('traceReturnValueUpdate', [[returnValue]])
} }
}) } catch (error) {
this.event.trigger('traceReturnValueUpdate', [[error]])
}
}) })
} }
......
...@@ -79,16 +79,11 @@ CodeManager.prototype.getCode = function (address, cb) { ...@@ -79,16 +79,11 @@ CodeManager.prototype.getCode = function (address, cb) {
CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast) { CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast) {
try { try {
const address = this.traceManager.getCurrentCalledAddressAt(stepIndex) const address = this.traceManager.getCurrentCalledAddressAt(stepIndex)
this.traceManager.getCurrentPC(stepIndex, (error, pc) => { const pc = this.traceManager.getCurrentPC(stepIndex)
if (error) {
console.log(error)
return { error: 'Cannot retrieve current PC for ' + stepIndex }
}
return this.getFunctionFromPC(address, pc, sourceMap, ast) return this.getFunctionFromPC(address, pc, sourceMap, ast)
})
} catch (error) { } catch (error) {
console.log(error) console.log(error)
return { error: 'Cannot retrieve current address for ' + stepIndex } return { error: 'Cannot retrieve current address or PC for ' + stepIndex }
} }
} }
...@@ -100,14 +95,14 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast) ...@@ -100,14 +95,14 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast)
* @param {Function} callback - instruction index * @param {Function} callback - instruction index
*/ */
CodeManager.prototype.getInstructionIndex = function (address, step, callback) { CodeManager.prototype.getInstructionIndex = function (address, step, callback) {
this.traceManager.getCurrentPC(step, (error, pc) => { try {
if (error) { const pc = this.traceManager.getCurrentPC(step)
const itemIndex = this.codeResolver.getInstructionIndex(address, pc)
callback(null, itemIndex)
} catch (error) {
console.log(error) console.log(error)
return callback('Cannot retrieve current PC for ' + step, null) return callback('Cannot retrieve current PC for ' + step, null)
} }
const itemIndex = this.codeResolver.getInstructionIndex(address, pc)
callback(null, itemIndex)
})
} }
/** /**
......
...@@ -179,26 +179,25 @@ TraceManager.prototype.getMemoryAt = function (stepIndex) { ...@@ -179,26 +179,25 @@ TraceManager.prototype.getMemoryAt = function (stepIndex) {
return this.trace[lastChanges].memory return this.trace[lastChanges].memory
} }
TraceManager.prototype.getCurrentPC = function (stepIndex, callback) { TraceManager.prototype.getCurrentPC = function (stepIndex) {
try { try {
this.checkRequestedStep(stepIndex) this.checkRequestedStep(stepIndex)
} catch (check) { } catch (check) {
return callback(check, null) throw new Error(check)
} }
callback(null, this.trace[stepIndex].pc) return this.trace[stepIndex].pc
} }
TraceManager.prototype.getReturnValue = function (stepIndex, callback) { TraceManager.prototype.getReturnValue = function (stepIndex) {
try { try {
this.checkRequestedStep(stepIndex) this.checkRequestedStep(stepIndex)
} catch (check) { } catch (check) {
return callback(check, null) throw new Error(check)
} }
if (!this.traceCache.returnValues[stepIndex]) { if (!this.traceCache.returnValues[stepIndex]) {
callback('current step is not a return step') throw new Error('current step is not a return step')
} else {
callback(null, this.traceCache.returnValues[stepIndex])
} }
return this.traceCache.returnValues[stepIndex]
} }
TraceManager.prototype.getCurrentStep = function (stepIndex, callback) { TraceManager.prototype.getCurrentStep = function (stepIndex, callback) {
......
...@@ -198,16 +198,15 @@ tape('TraceManager', function (t) { ...@@ -198,16 +198,15 @@ tape('TraceManager', function (t) {
}) })
t.test('TraceManager.getCurrentPC', function (st) { t.test('TraceManager.getCurrentPC', function (st) {
traceManager.getCurrentPC(13, function (error, result) { try {
const result = traceManager.getCurrentPC(13)
console.log(result) console.log(result)
if (error) {
st.fail(error)
} else {
st.ok(result === '65') st.ok(result === '65')
st.end() st.end()
} catch (error) {
st.fail(error)
} }
}) })
})
t.test('TraceManager.getCurrentStep', function (st) { t.test('TraceManager.getCurrentStep', function (st) {
traceManager.getCurrentStep(66, function (error, result) { traceManager.getCurrentStep(66, function (error, result) {
...@@ -283,13 +282,12 @@ tape('TraceManager', function (t) { ...@@ -283,13 +282,12 @@ tape('TraceManager', function (t) {
}) })
t.test('TraceManager.getReturnValue', function (st) { t.test('TraceManager.getReturnValue', function (st) {
traceManager.getReturnValue(108, function (error, result) { try {
if (error) { const result = traceManager.getReturnValue(108)
st.fail(error)
} else {
st.ok(result[0] === '0x60606040526008565b0000000000000000000000000000000000000000000000') st.ok(result[0] === '0x60606040526008565b0000000000000000000000000000000000000000000000')
st.end() st.end()
} catch (error) {
st.fail(error)
} }
}) })
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment