Merge pull request #734 from ethereum/addAPISourceLocationTracker

Fix source map cache
pull/3094/head
yann300 7 years ago committed by GitHub
commit b9d8989e50
  1. 2
      remix-lib/package.json
  2. 24
      remix-lib/src/sourceLocationTracker.js

@ -1,6 +1,6 @@
{ {
"name": "remix-lib", "name": "remix-lib",
"version": "0.1.7", "version": "0.1.8",
"description": "Ethereum IDE and tools for the web", "description": "Ethereum IDE and tools for the web",
"contributors": [ "contributors": [
{ {

@ -11,8 +11,7 @@ function SourceLocationTracker (_codeManager) {
this.codeManager = _codeManager this.codeManager = _codeManager
this.event = new EventManager() this.event = new EventManager()
this.sourceMappingDecoder = new SourceMappingDecoder() this.sourceMappingDecoder = new SourceMappingDecoder()
this.sourceMapCacheOfInstructionIndex = {} this.sourceMapByAddress = {}
this.sourceMapCacheOfVMTraceIndex = {}
} }
/** /**
@ -25,14 +24,10 @@ function SourceLocationTracker (_codeManager) {
*/ */
SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function (address, index, contracts, cb) { SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function (address, index, contracts, cb) {
var self = this var self = this
if (self.sourceMapCacheOfInstructionIndex[address]) { extractSourceMap(this, this.codeManager, address, contracts, function (error, sourceMap) {
return cb(null, self.sourceMappingDecoder.atIndex(index, self.sourceMapCacheOfInstructionIndex[address]))
}
extractSourceMap(this.codeManager, address, contracts, function (error, sourceMap) {
if (error) { if (error) {
cb(error) cb(error)
} else { } else {
if (!helper.isContractCreation(address)) self.sourceMapCacheOfInstructionIndex[address] = sourceMap
cb(null, self.sourceMappingDecoder.atIndex(index, sourceMap)) cb(null, self.sourceMappingDecoder.atIndex(index, sourceMap))
} }
}) })
@ -48,16 +43,12 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function
*/ */
SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts, cb) { SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts, cb) {
var self = this var self = this
if (self.sourceMapCacheOfVMTraceIndex[address]) { extractSourceMap(this, this.codeManager, address, contracts, function (error, sourceMap) {
return cb(null, self.sourceMappingDecoder.atIndex(vmtraceStepIndex, self.sourceMapCacheOfVMTraceIndex[address]))
}
extractSourceMap(this.codeManager, address, contracts, function (error, sourceMap) {
if (!error) { if (!error) {
self.codeManager.getInstructionIndex(address, vmtraceStepIndex, function (error, index) { self.codeManager.getInstructionIndex(address, vmtraceStepIndex, function (error, index) {
if (error) { if (error) {
cb(error) cb(error)
} else { } else {
if (!helper.isContractCreation(address)) self.sourceMapCacheOfVMTraceIndex[address] = sourceMap
cb(null, self.sourceMappingDecoder.atIndex(index, sourceMap)) cb(null, self.sourceMappingDecoder.atIndex(index, sourceMap))
} }
}) })
@ -67,6 +58,10 @@ SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (ad
}) })
} }
SourceLocationTracker.prototype.clearCache = function () {
this.sourceMapByAddress = {}
}
function getSourceMap (address, code, contracts) { function getSourceMap (address, code, contracts) {
var isCreation = helper.isContractCreation(address) var isCreation = helper.isContractCreation(address)
var bytes var bytes
@ -81,11 +76,14 @@ function getSourceMap (address, code, contracts) {
return null return null
} }
function extractSourceMap (codeManager, address, contracts, cb) { function extractSourceMap (self, codeManager, address, contracts, cb) {
if (self.sourceMapByAddress[address]) return cb(null, self.sourceMapByAddress[address])
codeManager.getCode(address, function (error, result) { codeManager.getCode(address, function (error, result) {
if (!error) { if (!error) {
var sourceMap = getSourceMap(address, result.bytecode, contracts) var sourceMap = getSourceMap(address, result.bytecode, contracts)
if (sourceMap) { if (sourceMap) {
if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap
cb(null, sourceMap) cb(null, sourceMap)
} else { } else {
cb('no sourcemap associated with the code ' + address) cb('no sourcemap associated with the code ' + address)

Loading…
Cancel
Save