refactor GetInstructionIndex

pull/63/head
Iuri Matias 4 years ago
parent 245c48d2ec
commit 31ba1e8f37
  1. 24
      libs/remix-lib/src/code/codeManager.js
  2. 16
      libs/remix-lib/src/sourceLocationTracker.js
  3. 26
      libs/remix-lib/test/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

@ -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 () {

@ -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)
}
})
}

Loading…
Cancel
Save