diff --git a/libs/remix-debug/src/debugger/VmDebugger.js b/libs/remix-debug/src/debugger/VmDebugger.js index ba8c15824e..e3d24e04a5 100644 --- a/libs/remix-debug/src/debugger/VmDebugger.js +++ b/libs/remix-debug/src/debugger/VmDebugger.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]]) + } }) } diff --git a/libs/remix-lib/src/code/codeManager.js b/libs/remix-lib/src/code/codeManager.js index 62e9ace35e..d665192a28 100644 --- a/libs/remix-lib/src/code/codeManager.js +++ b/libs/remix-lib/src/code/codeManager.js @@ -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) + } } /** diff --git a/libs/remix-lib/src/trace/traceManager.js b/libs/remix-lib/src/trace/traceManager.js index b065638d54..6ef9c8d9af 100644 --- a/libs/remix-lib/src/trace/traceManager.js +++ b/libs/remix-lib/src/trace/traceManager.js @@ -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) { diff --git a/libs/remix-lib/test/traceManager.js b/libs/remix-lib/test/traceManager.js index 8354da922f..a632125cae 100644 --- a/libs/remix-lib/test/traceManager.js +++ b/libs/remix-lib/test/traceManager.js @@ -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) + } }) })