refactor GetInstructionIndex

pull/5370/head
Iuri Matias 4 years ago
parent 10d41c2518
commit 3cb2ad02c3
  1. 15
      libs/remix-lib/src/code/codeManager.js
  2. 2
      libs/remix-lib/src/sourceLocationTracker.js
  3. 4
      libs/remix-lib/test/codeManager.js

@ -93,18 +93,7 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast)
* @param {String} step - vm trace step * @param {String} step - vm trace step
* @param {Function} callback - instruction index * @param {Function} callback - instruction index
*/ */
CodeManager.prototype.getInstructionIndex = function (address, step, callback) { CodeManager.prototype.getInstructionIndex = function (address, step) {
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)
}
}
CodeManager.prototype.newGetInstructionIndex = function (address, step) {
try { try {
const pc = this.traceManager.getCurrentPC(step) const pc = this.traceManager.getCurrentPC(step)
const itemIndex = this.codeResolver.getInstructionIndex(address, pc) const itemIndex = this.codeResolver.getInstructionIndex(address, pc)
@ -140,7 +129,7 @@ function retrieveCodeAndTrigger (codeMananger, address, stepIndex, tx) {
function retrieveIndexAndTrigger (codeMananger, address, step, code) { function retrieveIndexAndTrigger (codeMananger, address, step, code) {
let result let result
try { try {
result = codeMananger.newGetInstructionIndex(address, step) result = codeMananger.getInstructionIndex(address, step)
} catch (error) { } catch (error) {
return console.log(error) return console.log(error)
} }

@ -37,7 +37,7 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = async fu
*/ */
SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = async function (address, vmtraceStepIndex, contracts) { SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = async function (address, vmtraceStepIndex, contracts) {
const sourceMap = await extractSourceMap(this, this.codeManager, address, contracts) const sourceMap = await extractSourceMap(this, this.codeManager, address, contracts)
const index = this.codeManager.newGetInstructionIndex(address, vmtraceStepIndex) const index = this.codeManager.getInstructionIndex(address, vmtraceStepIndex)
return this.sourceMappingDecoder.atIndex(index, sourceMap) return this.sourceMappingDecoder.atIndex(index, sourceMap)
} }

@ -69,7 +69,7 @@ function continueTesting (t, codeManager) {
t.test('CodeManager.getInstructionIndex', function (st) { t.test('CodeManager.getInstructionIndex', function (st) {
st.plan(2) st.plan(2)
try { try {
const result = codeManager.newGetInstructionIndex('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', 16) const result = codeManager.getInstructionIndex('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', 16)
console.log(result) console.log(result)
st.ok(result === 25) st.ok(result === 25)
} catch (error) { } catch (error) {
@ -77,7 +77,7 @@ function continueTesting (t, codeManager) {
} }
try { try {
const result = codeManager.newGetInstructionIndex('(Contract Creation - Step 63)', 70) const result = codeManager.getInstructionIndex('(Contract Creation - Step 63)', 70)
console.log(result) console.log(result)
st.ok(result === 6) st.ok(result === 6)
} catch (error) { } catch (error) {

Loading…
Cancel
Save