From 6f138454318ad9a0a8bdd30e6d685e528e547e1d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 19 Jul 2020 11:36:49 -0400 Subject: [PATCH] refactor getCallDataAt --- libs/remix-debug/src/debugger/VmDebugger.js | 12 ++++++------ libs/remix-lib/src/trace/traceManager.js | 10 ++++++---- libs/remix-lib/test/traceManager.js | 15 +++++++-------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/libs/remix-debug/src/debugger/VmDebugger.js b/libs/remix-debug/src/debugger/VmDebugger.js index 862d6637d0..ba8c15824e 100644 --- a/libs/remix-debug/src/debugger/VmDebugger.js +++ b/libs/remix-debug/src/debugger/VmDebugger.js @@ -60,14 +60,14 @@ class VmDebuggerLogic { this.event.trigger('functionsStackUpdate', [this._callTree.retrieveFunctionsStack(index)]) - this._traceManager.getCallDataAt(index, (error, calldata) => { - if (error) { - // console.log(error) - this.event.trigger('traceManagerCallDataUpdate', [{}]) - } else if (this.stepManager.currentStepIndex === index) { + try { + const calldata = this._traceManager.getCallDataAt(index) + if (this.stepManager.currentStepIndex === index) { this.event.trigger('traceManagerCallDataUpdate', [calldata]) } - }) + } catch (error) { + this.event.trigger('traceManagerCallDataUpdate', [{}]) + } try { const memory = this._traceManager.getMemoryAt(index) diff --git a/libs/remix-lib/src/trace/traceManager.js b/libs/remix-lib/src/trace/traceManager.js index 0d7bdf3c58..109b3b4ddf 100644 --- a/libs/remix-lib/src/trace/traceManager.js +++ b/libs/remix-lib/src/trace/traceManager.js @@ -88,15 +88,17 @@ TraceManager.prototype.getAddresses = function () { return this.traceCache.addresses } -TraceManager.prototype.getCallDataAt = function (stepIndex, callback) { +TraceManager.prototype.getCallDataAt = function (stepIndex) { try { this.checkRequestedStep(stepIndex) } catch (check) { - return callback(check, null) + throw new Error(check) } const callDataChange = util.findLowerBoundValue(stepIndex, this.traceCache.callDataChanges) - if (callDataChange === null) return callback('no calldata found', null) - callback(null, [this.traceCache.callsData[callDataChange]]) + if (callDataChange === null) { + throw new Error('no calldata found') + } + return [this.traceCache.callsData[callDataChange]] } TraceManager.prototype.buildCallPath = function (stepIndex, callback) { diff --git a/libs/remix-lib/test/traceManager.js b/libs/remix-lib/test/traceManager.js index 64a2b64055..326408aa69 100644 --- a/libs/remix-lib/test/traceManager.js +++ b/libs/remix-lib/test/traceManager.js @@ -61,14 +61,13 @@ tape('TraceManager', function (t) { }) t.test('TraceManager.getCallData', function (st) { - traceManager.getCallDataAt(0, function (error, result) { - if (error) { - st.fail(error) - } else { - st.ok(result[0] === '0x60fe47b10000000000000000000000000000000000000000000000000000000000000038') - st.end() - } - }) + try { + const result = traceManager.getCallDataAt(0) + st.ok(result[0] === '0x60fe47b10000000000000000000000000000000000000000000000000000000000000038') + st.end() + } catch (error) { + st.fail(error) + } }) t.test('TraceManager.getCallStackAt', function (st) {