From 7339ab339959ebc22830867de41dc9e2117852ae Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 19 Mar 2018 12:22:19 +0100 Subject: [PATCH] Fix source map cache --- remix-lib/package.json | 2 +- remix-lib/src/sourceLocationTracker.js | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/remix-lib/package.json b/remix-lib/package.json index 5ce37eb7c8..f6097f26c2 100644 --- a/remix-lib/package.json +++ b/remix-lib/package.json @@ -1,6 +1,6 @@ { "name": "remix-lib", - "version": "0.1.7", + "version": "0.1.8", "description": "Ethereum IDE and tools for the web", "contributors": [ { diff --git a/remix-lib/src/sourceLocationTracker.js b/remix-lib/src/sourceLocationTracker.js index f3bf72f88f..0309faa2af 100644 --- a/remix-lib/src/sourceLocationTracker.js +++ b/remix-lib/src/sourceLocationTracker.js @@ -11,8 +11,7 @@ function SourceLocationTracker (_codeManager) { this.codeManager = _codeManager this.event = new EventManager() this.sourceMappingDecoder = new SourceMappingDecoder() - this.sourceMapCacheOfInstructionIndex = {} - this.sourceMapCacheOfVMTraceIndex = {} + this.sourceMapByAddress = {} } /** @@ -25,14 +24,10 @@ function SourceLocationTracker (_codeManager) { */ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function (address, index, contracts, cb) { var self = this - if (self.sourceMapCacheOfInstructionIndex[address]) { - return cb(null, self.sourceMappingDecoder.atIndex(index, self.sourceMapCacheOfInstructionIndex[address])) - } - extractSourceMap(this.codeManager, address, contracts, function (error, sourceMap) { + extractSourceMap(this, this.codeManager, address, contracts, function (error, sourceMap) { if (error) { cb(error) } else { - if (!helper.isContractCreation(address)) self.sourceMapCacheOfInstructionIndex[address] = sourceMap cb(null, self.sourceMappingDecoder.atIndex(index, sourceMap)) } }) @@ -48,16 +43,12 @@ SourceLocationTracker.prototype.getSourceLocationFromInstructionIndex = function */ SourceLocationTracker.prototype.getSourceLocationFromVMTraceIndex = function (address, vmtraceStepIndex, contracts, cb) { var self = this - if (self.sourceMapCacheOfVMTraceIndex[address]) { - return cb(null, self.sourceMappingDecoder.atIndex(vmtraceStepIndex, self.sourceMapCacheOfVMTraceIndex[address])) - } - extractSourceMap(this.codeManager, address, contracts, function (error, sourceMap) { + extractSourceMap(this, this.codeManager, address, contracts, function (error, sourceMap) { if (!error) { self.codeManager.getInstructionIndex(address, vmtraceStepIndex, function (error, index) { if (error) { cb(error) } else { - if (!helper.isContractCreation(address)) self.sourceMapCacheOfVMTraceIndex[address] = 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) { var isCreation = helper.isContractCreation(address) var bytes @@ -81,11 +76,14 @@ function getSourceMap (address, code, contracts) { 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) { if (!error) { var sourceMap = getSourceMap(address, result.bytecode, contracts) if (sourceMap) { + if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap cb(null, sourceMap) } else { cb('no sourcemap associated with the code ' + address)