Commit 6f411db3 authored by Iuri Matias's avatar Iuri Matias Committed by aniket-engg

refactor extractSourceMap

parent 826855f3
...@@ -40,19 +40,15 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function ...@@ -40,19 +40,15 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function
*/ */
SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts) { SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extractSourceMap(this, this.codeManager, address, contracts, (error, sourceMap) => { extractSourceMap(this, this.codeManager, address, contracts).then((sourceMap) => {
if (!error) { this.codeManager.getInstructionIndex(address, vmtraceStepIndex, (error, index) => {
this.codeManager.getInstructionIndex(address, vmtraceStepIndex, (error, index) => { if (error) {
if (error) { reject(error)
reject(error) } else {
} else { resolve(this.sourceMappingDecoder.atIndex(index, sourceMap))
resolve(this.sourceMappingDecoder.atIndex(index, sourceMap)) }
} })
}) }).catch(reject)
} else {
reject(error)
}
})
}) })
} }
...@@ -78,21 +74,23 @@ function getSourceMap (address, code, contracts) { ...@@ -78,21 +74,23 @@ function getSourceMap (address, code, contracts) {
return null return null
} }
function extractSourceMap (self, codeManager, address, contracts, cb) { function extractSourceMap (self, codeManager, address, contracts) {
if (self.sourceMapByAddress[address]) return cb(null, self.sourceMapByAddress[address]) return new Promise((resolve, reject) => {
if (self.sourceMapByAddress[address]) return resolve(self.sourceMapByAddress[address])
codeManager.getCode(address, (error, result) => { codeManager.getCode(address, (error, result) => {
if (!error) { if (!error) {
const sourceMap = getSourceMap(address, result.bytecode, contracts) const sourceMap = getSourceMap(address, result.bytecode, contracts)
if (sourceMap) { if (sourceMap) {
if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap
cb(null, sourceMap) resolve(sourceMap)
} else {
reject('no sourcemap associated with the code ' + address)
}
} else { } else {
cb('no sourcemap associated with the code ' + address) reject(error)
} }
} else { })
cb(error)
}
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment