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 * 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) { function retrieveIndexAndTrigger (codeMananger, address, step, code) {
codeMananger.getInstructionIndex(address, step, (error, result) => { let result
if (error) { try {
return console.log(error) result = codeMananger.newGetInstructionIndex(address, step)
} } catch (error) {
codeMananger.event.trigger('changed', [code, address, result]) return console.log(error)
}) }
codeMananger.event.trigger('changed', [code, address, result])
} }
module.exports = CodeManager module.exports = CodeManager

@ -35,18 +35,10 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = async fu
* @param {Object} contractDetails - AST of compiled contracts * @param {Object} contractDetails - AST of compiled contracts
* @param {Function} cb - callback function * @param {Function} cb - callback function
*/ */
SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts) { SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = async function (address, vmtraceStepIndex, contracts) {
return new Promise((resolve, reject) => { const sourceMap = await extractSourceMap(this, this.codeManager, address, contracts)
extractSourceMap(this, this.codeManager, address, contracts).then((sourceMap) => { const index = this.codeManager.newGetInstructionIndex(address, vmtraceStepIndex)
this.codeManager.getInstructionIndex(address, vmtraceStepIndex, (error, index) => { return this.sourceMappingDecoder.atIndex(index, sourceMap)
if (error) {
reject(error)
} else {
resolve(this.sourceMappingDecoder.atIndex(index, sourceMap))
}
})
}).catch(reject)
})
} }
SourceLocationTracker.prototype.clearCache = function () { SourceLocationTracker.prototype.clearCache = function () {

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

Loading…
Cancel
Save