turn property compilationResult into an async callback

pull/7/head
yann300 5 years ago
parent 8c6da69a8b
commit d72551df4d
  1. 12
      remix-debug/src/Ethdebugger.js
  2. 8
      remix-debug/src/cmdline/index.js
  3. 28
      remix-debug/src/debugger/debugger.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)

@ -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]
}

@ -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])

Loading…
Cancel
Save