use same event libe as browser solidity

pull/7/head
yann300 8 years ago
parent 7a31cbf9f0
commit efa965b53c
  1. 7
      src/code/codeManager.js
  2. 3
      src/code/sourceLocationTracker.js
  3. 45
      src/lib/eventManager.js
  4. 55
      src/ui/ASMCode.js
  5. 13
      src/ui/ButtonNavigator.js
  6. 2
      src/ui/CalldataPanel.js
  7. 2
      src/ui/CallstackPanel.js
  8. 22
      src/ui/Ethdebugger.js
  9. 4
      src/ui/FullStoragesChanges.js
  10. 2
      src/ui/MemoryPanel.js
  11. 5
      src/ui/Slider.js
  12. 2
      src/ui/StackPanel.js
  13. 19
      src/ui/StepManager.js
  14. 2
      src/ui/StoragePanel.js
  15. 8
      src/ui/TxBrowser.js
  16. 6
      src/ui/VmDebugger.js
  17. 4
      test/codeManager.js

@ -1,7 +1,6 @@
'use strict'
var traceHelper = require('../helpers/traceHelper')
var codeResolver = require('./codeResolver')
var util = require('../helpers/global')
var EventManager = require('../lib/eventManager')
/*
@ -14,7 +13,7 @@ var EventManager = require('../lib/eventManager')
*/
function CodeManager (_traceManager) {
util.extend(this, new EventManager())
this.event = new EventManager()
this.isLoading = false
this.traceManager = _traceManager
this.codeResolver = codeResolver
@ -22,7 +21,7 @@ function CodeManager (_traceManager) {
CodeManager.prototype.resolveStep = function (stepIndex, tx) {
if (stepIndex < 0) return
this.trigger('resolvingStep')
this.event.trigger('resolvingStep')
var self = this
if (stepIndex === 0) {
self.retrieveCodeAndTrigger(tx.to, stepIndex, tx)
@ -72,7 +71,7 @@ CodeManager.prototype.retrieveIndexAndTrigger = function (address, step, code) {
var self = this
this.getInstructionIndex(address, step, function (error, result) {
if (!error) {
self.trigger('changed', [code, address, result])
self.event.trigger('changed', [code, address, result])
} else {
console.log(error)
}

@ -1,6 +1,5 @@
'use strict'
var EventManager = require('../lib/eventManager')
var util = require('../helpers/global')
var helper = require('../helpers/traceHelper')
var SourceMappingDecoder = require('../util/sourceMappingDecoder')
@ -9,7 +8,7 @@ var SourceMappingDecoder = require('../util/sourceMappingDecoder')
*/
function SourceLocationTracker (_codeManager) {
this.codeManager = _codeManager
util.extend(this, new EventManager())
this.event = new EventManager()
this.sourceMappingDecoder = new SourceMappingDecoder()
}

@ -1,32 +1,65 @@
'use strict'
function EventManager () {
function eventManager () {
this.registered = {}
}
EventManager.prototype.unregister = function (eventName, obj) {
/*
* Unregister a listenner.
* Note that if obj is a function. the unregistration will be applied to the dummy obj {}.
*
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listenners that will be executed
*/
eventManager.prototype.unregister = function (eventName, obj, func) {
if (obj instanceof Function) {
func = obj
obj = {}
}
for (var reg in this.registered[eventName]) {
if (this.registered[eventName][reg] && this.registered[eventName][reg].obj === obj) {
if (this.registered[eventName][reg] &&
this.registered[eventName][reg].obj === obj && (!func || this.registered[eventName][reg].func === func)) {
this.registered[eventName].splice(reg, 1)
return
}
}
}
EventManager.prototype.register = function (eventName, obj, func) {
/*
* Register a new listenner.
* Note that if obj is a function, the function registration will be associated with the dummy object {}
*
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listenners that will be executed
*/
eventManager.prototype.register = function (eventName, obj, func) {
if (!this.registered[eventName]) {
this.registered[eventName] = []
}
if (obj instanceof Function) {
func = obj
obj = {}
}
this.registered[eventName].push({
obj: obj,
func: func
})
}
EventManager.prototype.trigger = function (eventName, args) {
/*
* trigger event.
* Every listenner have their associated function executed
*
* @param {String} eventName - the event name
* @param {Array}j - argument that will be passed to the exectued function.
*/
eventManager.prototype.trigger = function (eventName, args) {
for (var listener in this.registered[eventName]) {
var l = this.registered[eventName][listener]
l.func.apply(l.obj, args)
}
}
module.exports = EventManager
module.exports = eventManager

@ -0,0 +1,55 @@
'use strict'
var style = require('./styles/basicStyles')
var yo = require('yo-yo')
var ui = require('../helpers/ui')
function ASMCode (_parent, _codeManager) {
this.parent = _parent
this.codeManager = _codeManager
this.code
this.address
this.codeView
this.init()
}
ASMCode.prototype.render = function () {
var view = (
yo`<select size='10' id='asmitems' ref='itemsList' style=${ui.formatCss(style.instructionsList)}>
${this.codeView}
</select>`
)
if (!this.view) {
this.view = view
}
return view
}
ASMCode.prototype.init = function () {
this.codeManager.event.register('changed', this, this.changed)
}
ASMCode.prototype.indexChanged = function (index) {
document.getElementById('asmitems').value = index
}
ASMCode.prototype.changed = function (code, address, index) {
if (this.address !== address) {
this.code = code
this.address = address
this.renderAssemblyItems()
yo.update(this.view, this.render())
}
this.indexChanged(index)
}
ASMCode.prototype.renderAssemblyItems = function () {
if (this.code) {
this.codeView = this.code.map(function (item, i) {
return yo`<option key=${i} value=${i}>${item}</option>`
})
return this.codeView
}
}
module.exports = ASMCode

@ -1,12 +1,11 @@
'use strict'
var util = require('../helpers/global')
var EventManager = require('../lib/eventManager')
var style = require('./styles/basicStyles')
var ui = require('../helpers/ui')
var yo = require('yo-yo')
function ButtonNavigator (_traceManager) {
util.extend(this, new EventManager())
this.event = new EventManager()
this.intoBackDisabled = true
this.overBackDisabled = true
this.intoForwardDisabled = true
@ -23,19 +22,19 @@ module.exports = ButtonNavigator
ButtonNavigator.prototype.render = function () {
var self = this
var view = yo`<div>
<button id='overback' style=${ui.formatCss(style.button)} onclick=${function () { self.trigger('stepOverBack') }} disabled=${this.overBackDisabled} >
<button id='overback' style=${ui.formatCss(style.button)} onclick=${function () { self.event.trigger('stepOverBack') }} disabled=${this.overBackDisabled} >
Step Over Back
</button>
<button id='intoback' style=${ui.formatCss(style.button)} onclick=${function () { self.trigger('stepIntoBack') }} disabled=${this.intoBackDisabled} >
<button id='intoback' style=${ui.formatCss(style.button)} onclick=${function () { self.event.trigger('stepIntoBack') }} disabled=${this.intoBackDisabled} >
Step Into Back
</button>
<button id='intoforward' style=${ui.formatCss(style.button)} onclick=${function () { self.trigger('stepIntoForward') }} disabled=${this.intoForwardDisabled} >
<button id='intoforward' style=${ui.formatCss(style.button)} onclick=${function () { self.event.trigger('stepIntoForward') }} disabled=${this.intoForwardDisabled} >
Step Into Forward
</button>
<button id='overforward' style=${ui.formatCss(style.button)} onclick=${function () { self.trigger('stepOverForward') }} disabled=${this.overForwardDisabled} >
<button id='overforward' style=${ui.formatCss(style.button)} onclick=${function () { self.event.trigger('stepOverForward') }} disabled=${this.overForwardDisabled} >
Step Over Forward
</button>
<button id='nextcall' style=${ui.formatCss(style.button)} onclick=${function () { self.trigger('jumpNextCall') }} disabled=${this.nextCallDisabled} >
<button id='nextcall' style=${ui.formatCss(style.button)} onclick=${function () { self.event.trigger('jumpNextCall') }} disabled=${this.nextCallDisabled} >
Jump Next Call
</button>
</div>`

@ -15,7 +15,7 @@ CalldataPanel.prototype.render = function () {
CalldataPanel.prototype.init = function () {
var self = this
this.parent.register('indexChanged', this, function (index) {
this.parent.event.register('indexChanged', this, function (index) {
if (index < 0) return
if (self.parent.currentStepIndex !== index) return

@ -15,7 +15,7 @@ CallstackPanel.prototype.render = function () {
CallstackPanel.prototype.init = function () {
var self = this
this.parent.register('indexChanged', this, function (index) {
this.parent.event.register('indexChanged', this, function (index) {
if (index < 0) return
if (self.parent.currentStepIndex !== index) return

@ -14,7 +14,7 @@ var CodeManager = require('../code/codeManager')
var SourceLocationTracker = require('../code/sourceLocationTracker')
function Ethdebugger () {
util.extend(this, new EventManager())
this.event = new EventManager()
this.currentStepIndex = -1
this.tx
@ -29,22 +29,22 @@ function Ethdebugger () {
this.sourceLocationTracker = new SourceLocationTracker(this.codeManager)
var self = this
this.register('indexChanged', this, function (index) {
this.event.register('indexChanged', this, function (index) {
self.codeManager.resolveStep(index, self.tx)
})
this.txBrowser = new TxBrowser(this)
this.txBrowser.register('newTxLoading', this, function () {
this.txBrowser.event.register('newTxLoading', this, function () {
self.unLoad()
})
this.txBrowser.register('newTraceRequested', this, function (blockNumber, txIndex, tx) {
this.txBrowser.event.register('newTraceRequested', this, function (blockNumber, txIndex, tx) {
self.startDebugging(blockNumber, txIndex, tx)
})
this.txBrowser.register('unloadRequested', this, function (blockNumber, txIndex, tx) {
this.txBrowser.event.register('unloadRequested', this, function (blockNumber, txIndex, tx) {
self.unLoad()
})
this.stepManager = new StepManager(this, this.traceManager)
this.stepManager.register('stepChanged', this, function (stepIndex) {
this.stepManager.event.register('stepChanged', this, function (stepIndex) {
self.stepChanged(stepIndex)
})
this.vmDebugger = new VmDebugger(this, this.traceManager, this.codeManager)
@ -56,7 +56,7 @@ Ethdebugger.prototype.web3 = function () {
Ethdebugger.prototype.addProvider = function (type, obj) {
this.web3Providers.addProvider(type, obj)
this.trigger('providerAdded', [type])
this.event.trigger('providerAdded', [type])
}
Ethdebugger.prototype.switchProvider = function (type) {
@ -66,7 +66,7 @@ Ethdebugger.prototype.switchProvider = function (type) {
console.log('provider ' + type + ' not defined')
} else {
util.web3 = obj
self.trigger('providerChanged', [type])
self.event.trigger('providerChanged', [type])
}
})
}
@ -97,12 +97,12 @@ Ethdebugger.prototype.render = function () {
Ethdebugger.prototype.unLoad = function () {
this.traceManager.init()
this.stepManager.reset()
this.trigger('traceUnloaded')
this.event.trigger('traceUnloaded')
}
Ethdebugger.prototype.stepChanged = function (stepIndex) {
this.currentStepIndex = stepIndex
this.trigger('indexChanged', [stepIndex])
this.event.trigger('indexChanged', [stepIndex])
}
Ethdebugger.prototype.startDebugging = function (blockNumber, txIndex, tx) {
@ -119,7 +119,7 @@ Ethdebugger.prototype.startDebugging = function (blockNumber, txIndex, tx) {
if (result) {
self.statusMessage = ''
yo.update(self.view, self.render())
self.trigger('newTraceLoaded')
self.event.trigger('newTraceLoaded')
} else {
self.statusMessage = error
yo.update(self.view, self.render())

@ -22,7 +22,7 @@ FullStoragesChanges.prototype.render = function () {
FullStoragesChanges.prototype.init = function () {
var self = this
this.parent.register('newTraceLoaded', this, function (length) {
this.parent.event.register('newTraceLoaded', this, function (length) {
self.panels = []
self.traceManager.getAddresses(function (error, addresses) {
if (!error) {
@ -38,7 +38,7 @@ FullStoragesChanges.prototype.init = function () {
})
})
this.parent.register('indexChanged', this, function (index) {
this.parent.event.register('indexChanged', this, function (index) {
if (index < 0) return
if (self.parent.currentStepIndex !== index) return

@ -16,7 +16,7 @@ MemoryPanel.prototype.render = function () {
MemoryPanel.prototype.init = function () {
var self = this
this.parent.register('indexChanged', this, function (index) {
this.parent.event.register('indexChanged', this, function (index) {
if (index < 0) return
if (self.parent.currentStepIndex !== index) return

@ -1,12 +1,11 @@
'use strict'
var style = require('./styles/sliderStyles')
var util = require('../helpers/global')
var EventManager = require('../lib/eventManager')
var yo = require('yo-yo')
var ui = require('../helpers/ui')
function Slider (_traceManager) {
util.extend(this, new EventManager())
this.event = new EventManager()
this.traceManager = _traceManager
this.max
this.disabled = true
@ -48,7 +47,7 @@ Slider.prototype.onChange = function (event) {
var value = parseInt(document.getElementById('slider').value)
if (value === this.previousValue) return
this.previousValue = value
this.trigger('moved', [value])
this.event.trigger('moved', [value])
}
Slider.prototype.setValue = function (value) {

@ -16,7 +16,7 @@ StackPanel.prototype.render = function () {
StackPanel.prototype.init = function () {
var self = this
this.parent.register('indexChanged', this, function (index) {
this.parent.event.register('indexChanged', this, function (index) {
if (index < 0) return
if (self.parent.currentStepIndex !== index) return

@ -1,17 +1,16 @@
'use strict'
var ButtonNavigator = require('./ButtonNavigator')
var Slider = require('./Slider')
var util = require('../helpers/global')
var EventManager = require('../lib/eventManager')
var yo = require('yo-yo')
function StepManager (_parent, _traceManager) {
util.extend(this, new EventManager())
this.event = new EventManager()
this.parent = _parent
this.traceManager = _traceManager
var self = this
this.parent.register('newTraceLoaded', this, function () {
this.parent.event.register('newTraceLoaded', this, function () {
self.traceManager.getLength(function (error, length) {
if (error) {
console.log(error)
@ -23,24 +22,24 @@ function StepManager (_parent, _traceManager) {
})
this.slider = new Slider(this.traceManager)
this.slider.register('moved', this, function (step) {
this.slider.event.register('moved', this, function (step) {
self.sliderMoved(step)
})
this.buttonNavigator = new ButtonNavigator(this.traceManager)
this.buttonNavigator.register('stepIntoBack', this, function () {
this.buttonNavigator.event.register('stepIntoBack', this, function () {
self.stepIntoBack()
})
this.buttonNavigator.register('stepIntoForward', this, function () {
this.buttonNavigator.event.register('stepIntoForward', this, function () {
self.stepIntoForward()
})
this.buttonNavigator.register('stepOverBack', this, function () {
this.buttonNavigator.event.register('stepOverBack', this, function () {
self.stepOverBack()
})
this.buttonNavigator.register('stepOverForward', this, function () {
this.buttonNavigator.event.register('stepOverForward', this, function () {
self.stepOverForward()
})
this.buttonNavigator.register('jumpNextCall', this, function () {
this.buttonNavigator.event.register('jumpNextCall', this, function () {
self.jumpNextCall()
})
}
@ -130,7 +129,7 @@ StepManager.prototype.jumpNextCall = function () {
StepManager.prototype.changeState = function (step) {
this.currentStepIndex = step
this.buttonNavigator.stepChanged(step)
this.trigger('stepChanged', [step])
this.event.trigger('stepChanged', [step])
}
module.exports = StepManager

@ -17,7 +17,7 @@ StoragePanel.prototype.render = function () {
StoragePanel.prototype.init = function () {
var self = this
this.parent.register('indexChanged', this, function (index) {
this.parent.event.register('indexChanged', this, function (index) {
if (self.disabled) return
if (index < 0) return
if (self.parent.currentStepIndex !== index) return

@ -8,7 +8,7 @@ var init = require('../helpers/init')
var DropdownPanel = require('./DropdownPanel')
function TxBrowser (_parent) {
util.extend(this, new EventManager())
this.event = new EventManager()
this.blockNumber
this.txNumber
@ -17,7 +17,7 @@ function TxBrowser (_parent) {
this.basicPanel = new DropdownPanel('Transaction')
this.basicPanel.data = {}
var self = this
_parent.register('providerChanged', this, function (provider) {
_parent.event.register('providerChanged', this, function (provider) {
self.displayConnectionSetting = provider === 'INTERNAL'
self.setDefaultValues()
if (self.view) {
@ -44,7 +44,7 @@ TxBrowser.prototype.submit = function () {
if (!this.txNumber) {
return
}
this.trigger('newTxLoading', [this.blockNumber, this.txNumber])
this.event.trigger('newTxLoading', [this.blockNumber, this.txNumber])
try {
var self = this
if (this.txNumber.indexOf('0x') !== -1) {
@ -124,7 +124,7 @@ TxBrowser.prototype.load = function (txHash) {
}
TxBrowser.prototype.unload = function (txHash) {
this.trigger('unloadRequested')
this.event.trigger('unloadRequested')
this.init()
}

@ -22,7 +22,7 @@ function VmDebugger (_parent, _traceManager, _codeManager) {
/* Return values - */
this.returnValuesPanel = new DropdownPanel('Return Value')
this.returnValuesPanel.data = {}
_parent.register('indexChanged', this.returnValuesPanel, function (index) {
_parent.event.register('indexChanged', this.returnValuesPanel, function (index) {
var self = this
_traceManager.getReturnValue(index, function (error, returnValue) {
if (error) {
@ -39,10 +39,10 @@ function VmDebugger (_parent, _traceManager, _codeManager) {
this.view
var self = this
_parent.register('newTraceLoaded', this, function () {
_parent.event.register('newTraceLoaded', this, function () {
self.view.style.display = 'block'
})
_parent.register('traceUnloaded', this, function () {
_parent.event.register('traceUnloaded', this, function () {
self.view.style.display = 'none'
})
}

@ -40,7 +40,7 @@ function continueTesting (t, codeManager) {
t.test('CodeManager.resolveStep', function (st) {
st.plan(6)
codeManager.register('changed', this, function (code, address, index) {
codeManager.event.register('changed', this, function (code, address, index) {
if (index === undefined || index === null) {
st.fail(index)
} else {
@ -48,7 +48,7 @@ function continueTesting (t, codeManager) {
}
})
codeManager.register('changed', this, function (code, address, index) {
codeManager.event.register('changed', this, function (code, address, index) {
if (!code) {
st.fail('no codes')
} else {

Loading…
Cancel
Save