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 {
this.event.trigger('traceRemainingGasUpdate', [error])
}
this._traceManager.getReturnValue(index, (error, returnValue) => {
if (error) {
this.event.trigger('traceReturnValueUpdate', [[error]])
} else if (this.stepManager.currentStepIndex === index) {
try {
const returnValue = this._traceManager.getReturnValue(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceReturnValueUpdate', [[returnValue]])
}
})
} catch (error) {
this.event.trigger('traceReturnValueUpdate', [[error]])
}
})
}
......
......@@ -79,16 +79,11 @@ CodeManager.prototype.getCode = function (address, cb) {
CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast) {
try {
const address = this.traceManager.getCurrentCalledAddressAt(stepIndex)
this.traceManager.getCurrentPC(stepIndex, (error, pc) => {
if (error) {
console.log(error)
return { error: 'Cannot retrieve current PC for ' + stepIndex }
}
const pc = this.traceManager.getCurrentPC(stepIndex)
return this.getFunctionFromPC(address, pc, sourceMap, ast)
})
} catch (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)
* @param {Function} callback - instruction index
*/
CodeManager.prototype.getInstructionIndex = function (address, step, callback) {
this.traceManager.getCurrentPC(step, (error, pc) => {
if (error) {
try {
const pc = this.traceManager.getCurrentPC(step)
const itemIndex = this.codeResolver.getInstructionIndex(address, pc)
callback(null, itemIndex)
} catch (error) {
console.log(error)
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) {
return this.trace[lastChanges].memory
}
TraceManager.prototype.getCurrentPC = function (stepIndex, callback) {
TraceManager.prototype.getCurrentPC = function (stepIndex) {
try {
this.checkRequestedStep(stepIndex)
} 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 {
this.checkRequestedStep(stepIndex)
} catch (check) {
return callback(check, null)
throw new Error(check)
}
if (!this.traceCache.returnValues[stepIndex]) {
callback('current step is not a return step')
} else {
callback(null, this.traceCache.returnValues[stepIndex])
throw new Error('current step is not a return step')
}
return this.traceCache.returnValues[stepIndex]
}
TraceManager.prototype.getCurrentStep = function (stepIndex, callback) {
......
......@@ -198,16 +198,15 @@ tape('TraceManager', function (t) {
})
t.test('TraceManager.getCurrentPC', function (st) {
traceManager.getCurrentPC(13, function (error, result) {
try {
const result = traceManager.getCurrentPC(13)
console.log(result)
if (error) {
st.fail(error)
} else {
st.ok(result === '65')
st.end()
} catch (error) {
st.fail(error)
}
})
})
t.test('TraceManager.getCurrentStep', function (st) {
traceManager.getCurrentStep(66, function (error, result) {
......@@ -283,13 +282,12 @@ tape('TraceManager', function (t) {
})
t.test('TraceManager.getReturnValue', function (st) {
traceManager.getReturnValue(108, function (error, result) {
if (error) {
st.fail(error)
} else {
try {
const result = traceManager.getReturnValue(108)
st.ok(result[0] === '0x60606040526008565b0000000000000000000000000000000000000000000000')
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