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

refactor extractSourceMap

parent 826855f3
...@@ -40,8 +40,7 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function ...@@ -40,8 +40,7 @@ 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)
...@@ -49,10 +48,7 @@ SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (ad ...@@ -49,10 +48,7 @@ SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (ad
resolve(this.sourceMappingDecoder.atIndex(index, sourceMap)) resolve(this.sourceMappingDecoder.atIndex(index, sourceMap))
} }
}) })
} else { }).catch(reject)
reject(error)
}
})
}) })
} }
...@@ -78,22 +74,24 @@ function getSourceMap (address, code, contracts) { ...@@ -78,22 +74,24 @@ 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 { } else {
cb('no sourcemap associated with the code ' + address) reject('no sourcemap associated with the code ' + address)
} }
} else { } else {
cb(error) reject(error)
} }
}) })
})
} }
module.exports = SourceLocationTracker module.exports = SourceLocationTracker
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