From d72551df4d7d396b2e4fdf3d0698b5edb1cfdb79 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 22 Apr 2020 11:16:38 +0200 Subject: [PATCH] turn property compilationResult into an async callback --- remix-debug/src/Ethdebugger.js | 12 +++++------ remix-debug/src/cmdline/index.js | 8 ++++---- remix-debug/src/debugger/debugger.js | 30 +++++++++++++--------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/remix-debug/src/Ethdebugger.js b/remix-debug/src/Ethdebugger.js index 95b8cacba0..e6e17ecbaa 100644 --- a/remix-debug/src/Ethdebugger.js +++ b/remix-debug/src/Ethdebugger.js @@ -29,9 +29,7 @@ const EventManager = remixLib.EventManager * @param {Map} opts - { function compilationResult } // */ function Ethdebugger (opts) { - this.opts = opts || {} - if (!this.opts.compilationResult) this.opts.compilationResult = () => { return null } - + this.compilationResult = opts.compilationResult || function (contractAddress) { return null } this.web3 = opts.web3 this.event = new EventManager() @@ -60,8 +58,8 @@ Ethdebugger.prototype.resolveStep = function (index) { } Ethdebugger.prototype.setCompilationResult = function (compilationResult) { - if (compilationResult && compilationResult.sources && compilationResult.contracts) { - this.solidityProxy.reset(compilationResult) + if (compilationResult && compilationResult.data) { + this.solidityProxy.reset(compilationResult.data) } else { this.solidityProxy.reset({}) } @@ -173,10 +171,10 @@ Ethdebugger.prototype.debug = function (tx) { if (!tx.to) { tx.to = traceHelper.contractCreationToken('0') } - this.setCompilationResult(this.opts.compilationResult()) this.tx = tx - this.traceManager.resolveTrace(tx, (error, result) => { + this.traceManager.resolveTrace(tx, async (error, result) => { if (result) { + this.setCompilationResult(await this.compilationResult(tx.to)) this.event.trigger('newTraceLoaded', [this.traceManager.trace]) if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { this.breakpointManager.jumpNextBreakpoint(false) diff --git a/remix-debug/src/cmdline/index.js b/remix-debug/src/cmdline/index.js index c34f5596cc..041671c7fb 100644 --- a/remix-debug/src/cmdline/index.js +++ b/remix-debug/src/cmdline/index.js @@ -28,7 +28,7 @@ class CmdLine { loadCompilationResult (compilationResult) { this.compilation = {} - this.compilation.lastCompilationResult = compilationResult + this.compilation.compilationResult = compilationResult } initDebugger (cb) { @@ -36,7 +36,7 @@ class CmdLine { this.debugger = new Debugger({ web3: this.contextManager.getWeb3(), - compiler: this.compilation + compilationResult: () => { return this.compilation.compilationResult } }) this.contextManager.event.register('providerChanged', () => { @@ -54,7 +54,7 @@ class CmdLine { if (!lineColumnPos || !lineColumnPos.start) return [] - const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') + const content = this.compilation.compilationResult.source.sources[this.filename].content.split('\n') const source = [] @@ -85,7 +85,7 @@ class CmdLine { const lineColumnPos = this.lineColumnPos if (!lineColumnPos) return '' const currentLineNumber = lineColumnPos.start.line - const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') + const content = this.compilation.compilationResult.source.sources[this.filename].content.split('\n') return content[currentLineNumber] } diff --git a/remix-debug/src/debugger/debugger.js b/remix-debug/src/debugger/debugger.js index a6c795b745..f5caf802aa 100644 --- a/remix-debug/src/debugger/debugger.js +++ b/remix-debug/src/debugger/debugger.js @@ -12,21 +12,19 @@ function Debugger (options) { this.event = new EventManager() this.offsetToLineColumnConverter = options.offsetToLineColumnConverter || (new OffsetToColumnConverter()) - this.compiler = options.compiler + /* + Returns a compilation result for a given address or the last one available if none are found + */ + this.compilationResult = options.compilationResult || function (contractAddress) { return null } this.debugger = new Ethdebugger({ web3: options.web3, - compilationResult: () => { - var compilationResult = this.compiler.lastCompilationResult - if (compilationResult) { - return compilationResult.data - } - return null - } + compilationResult: this.compilationResult }) - this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => { - return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) + this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, async (sourceLocation) => { + const compilationResult = await this.compilationResult() + return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, compilationResult.source.sources, compilationResult.data.sources) }, (step) => { this.event.trigger('breakpointStep', [step]) }) @@ -48,12 +46,12 @@ function Debugger (options) { Debugger.prototype.registerAndHighlightCodeItem = function (index) { // register selected code item, highlight the corresponding source location - if (!this.compiler.lastCompilationResult) return - this.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { + this.debugger.traceManager.getCurrentCalledAddressAt(index, async (error, address) => { if (error) return console.log(error) - this.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, this.compiler.lastCompilationResult.data.contracts, (error, rawLocation) => { - if (!error && this.compiler.lastCompilationResult && this.compiler.lastCompilationResult.data) { - var lineColumnPos = this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) + const compilationResultForAddress = await this.compilationResult(address) + this.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, compilationResultForAddress.data.contracts, (error, rawLocation) => { + if (!error && compilationResultForAddress && compilationResultForAddress.data) { + var lineColumnPos = this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, compilationResultForAddress.source.sources, compilationResultForAddress.data.sources) this.event.trigger('newSourceLocation', [lineColumnPos, rawLocation]) } else { this.event.trigger('newSourceLocation', [null]) @@ -112,7 +110,7 @@ Debugger.prototype.debugTx = function (tx, loadingCb) { this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [sourceLocation]) } }) - }) + }) this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree) this.vmDebuggerLogic.start()