diff --git a/libs/remix-lib/src/code/codeManager.js b/libs/remix-lib/src/code/codeManager.js index fb13172d11..1897d64b69 100644 --- a/libs/remix-lib/src/code/codeManager.js +++ b/libs/remix-lib/src/code/codeManager.js @@ -104,6 +104,17 @@ CodeManager.prototype.getInstructionIndex = function (address, step, callback) { } } +CodeManager.prototype.newGetInstructionIndex = function (address, step) { + try { + const pc = this.traceManager.getCurrentPC(step) + const itemIndex = this.codeResolver.getInstructionIndex(address, pc) + return itemIndex + } catch (error) { + console.log(error) + throw new Error('Cannot retrieve current PC for ' + step) + } +} + /** * Retrieve the called function for the given @arg pc and @arg address * @@ -127,12 +138,13 @@ function retrieveCodeAndTrigger (codeMananger, address, stepIndex, tx) { } function retrieveIndexAndTrigger (codeMananger, address, step, code) { - codeMananger.getInstructionIndex(address, step, (error, result) => { - if (error) { - return console.log(error) - } - codeMananger.event.trigger('changed', [code, address, result]) - }) + let result + try { + result = codeMananger.newGetInstructionIndex(address, step) + } catch (error) { + return console.log(error) + } + codeMananger.event.trigger('changed', [code, address, result]) } module.exports = CodeManager diff --git a/libs/remix-lib/src/sourceLocationTracker.js b/libs/remix-lib/src/sourceLocationTracker.js index f4b27b269e..5a2d133895 100644 --- a/libs/remix-lib/src/sourceLocationTracker.js +++ b/libs/remix-lib/src/sourceLocationTracker.js @@ -35,18 +35,10 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = async fu * @param {Object} contractDetails - AST of compiled contracts * @param {Function} cb - callback function */ -SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts) { - return new Promise((resolve, reject) => { - extractSourceMap(this, this.codeManager, address, contracts).then((sourceMap) => { - this.codeManager.getInstructionIndex(address, vmtraceStepIndex, (error, index) => { - if (error) { - reject(error) - } else { - resolve(this.sourceMappingDecoder.atIndex(index, sourceMap)) - } - }) - }).catch(reject) - }) +SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = async function (address, vmtraceStepIndex, contracts) { + const sourceMap = await extractSourceMap(this, this.codeManager, address, contracts) + const index = this.codeManager.newGetInstructionIndex(address, vmtraceStepIndex) + return this.sourceMappingDecoder.atIndex(index, sourceMap) } SourceLocationTracker.prototype.clearCache = function () { diff --git a/libs/remix-lib/test/codeManager.js b/libs/remix-lib/test/codeManager.js index 4a25225e1d..06d7e78efa 100644 --- a/libs/remix-lib/test/codeManager.js +++ b/libs/remix-lib/test/codeManager.js @@ -68,22 +68,20 @@ function continueTesting (t, codeManager) { t.test('CodeManager.getInstructionIndex', function (st) { st.plan(2) - codeManager.getInstructionIndex('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', 16, function (error, result) { + try { + const result = codeManager.newGetInstructionIndex('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', 16) console.log(result) - if (error) { - st.fail(error) - } else { - st.ok(result === 25) - } - }) + st.ok(result === 25) + } catch (error) { + st.fail(error) + } - codeManager.getInstructionIndex('(Contract Creation - Step 63)', 70, function (error, result) { + try { + const result = codeManager.newGetInstructionIndex('(Contract Creation - Step 63)', 70) console.log(result) - if (error) { - st.fail(error) - } else { - st.ok(result === 6) - } - }) + st.ok(result === 6) + } catch (error) { + st.fail(error) + } }) }