refactor extractSourceMap

pull/62/head
Iuri Matias 4 years ago committed by aniket-engg
parent 826855f379
commit 6f411db3f5
  1. 20
      libs/remix-lib/src/sourceLocationTracker.js

@ -40,8 +40,7 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function
*/
SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts) {
return new Promise((resolve, reject) => {
extractSourceMap(this, this.codeManager, address, contracts, (error, sourceMap) => {
if (!error) {
extractSourceMap(this, this.codeManager, address, contracts).then((sourceMap) => {
this.codeManager.getInstructionIndex(address, vmtraceStepIndex, (error, index) => {
if (error) {
reject(error)
@ -49,10 +48,7 @@ SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (ad
resolve(this.sourceMappingDecoder.atIndex(index, sourceMap))
}
})
} else {
reject(error)
}
})
}).catch(reject)
})
}
@ -78,22 +74,24 @@ function getSourceMap (address, code, contracts) {
return null
}
function extractSourceMap (self, codeManager, address, contracts, cb) {
if (self.sourceMapByAddress[address]) return cb(null, self.sourceMapByAddress[address])
function extractSourceMap (self, codeManager, address, contracts) {
return new Promise((resolve, reject) => {
if (self.sourceMapByAddress[address]) return resolve(self.sourceMapByAddress[address])
codeManager.getCode(address, (error, result) => {
if (!error) {
const sourceMap = getSourceMap(address, result.bytecode, contracts)
if (sourceMap) {
if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap
cb(null, sourceMap)
resolve(sourceMap)
} else {
cb('no sourcemap associated with the code ' + address)
reject('no sourcemap associated with the code ' + address)
}
} else {
cb(error)
reject(error)
}
})
})
}
module.exports = SourceLocationTracker

Loading…
Cancel
Save