refactor getReturnValue value

pull/5370/head
Iuri Matias 4 years ago committed by aniket-engg
parent 0b301c4a3f
commit 12bf5ce4fb
  1. 11
      libs/remix-debug/src/debugger/VmDebugger.js
  2. 23
      libs/remix-lib/src/code/codeManager.js
  3. 15
      libs/remix-lib/src/trace/traceManager.js
  4. 30
      libs/remix-lib/test/traceManager.js

@ -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 }
}
return this.getFunctionFromPC(address, pc, sourceMap, ast)
})
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) {
console.log(error)
return callback('Cannot retrieve current PC for ' + step, null)
}
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)
}
}
/**

@ -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,15 +198,14 @@ 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()
}
})
st.ok(result === '65')
st.end()
} catch (error) {
st.fail(error)
}
})
t.test('TraceManager.getCurrentStep', function (st) {
@ -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 {
st.ok(result[0] === '0x60606040526008565b0000000000000000000000000000000000000000000000')
st.end()
}
})
try {
const result = traceManager.getReturnValue(108)
st.ok(result[0] === '0x60606040526008565b0000000000000000000000000000000000000000000000')
st.end()
} catch (error) {
st.fail(error)
}
})
})

Loading…
Cancel
Save