Commit 55490eae authored by yann300's avatar yann300

add comment

parent 80b1017c
'use strict' 'use strict'
var EventManager = require('../lib/eventManager') var EventManager = require('../lib/eventManager')
/**
* allow to manage breakpoint
*
* Trigger events: breakpointHit, breakpointAdded, breakpointRemoved
*/
class breakpointManager { class breakpointManager {
/**
* constructor
*
* @param {Object} _debugger - type of EthDebugger
* @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location
*/
constructor (_debugger, _locationToRowConverter) { constructor (_debugger, _locationToRowConverter) {
this.event = new EventManager() this.event = new EventManager()
this.debugger = _debugger this.debugger = _debugger
...@@ -11,6 +22,10 @@ class breakpointManager { ...@@ -11,6 +22,10 @@ class breakpointManager {
this.currentLine this.currentLine
} }
/**
* start looking for the next breakpoint
*
*/
async play () { async play () {
this.isPlaying = true this.isPlaying = true
var sourceLocation var sourceLocation
...@@ -27,7 +42,7 @@ class breakpointManager { ...@@ -27,7 +42,7 @@ class breakpointManager {
} }
this.currentLine = lineColumn.start.line this.currentLine = lineColumn.start.line
} }
if (this.checkSourceLocation(sourceLocation, currentStep, this.currentLine)) { if (this.checkSourceLocation(sourceLocation.file, this.currentLine)) {
this.debugger.stepManager.jumpTo(currentStep) this.debugger.stepManager.jumpTo(currentStep)
this.event.trigger('breakpointHit', [sourceLocation]) this.event.trigger('breakpointHit', [sourceLocation])
break break
...@@ -35,12 +50,19 @@ class breakpointManager { ...@@ -35,12 +50,19 @@ class breakpointManager {
} }
} }
checkSourceLocation (sourceLocation, currentStep, currentLine) { /**
if (this.breakpoints[sourceLocation.file]) { * check the given pair fileIndex/line against registered breakpoints
var sources = this.breakpoints[sourceLocation.file] *
* @param {Int} fileIndex - index of the file content (from the compilation result)
* @param {Int} line - line number where looking for breakpoint
* @return {Bool} return true if the given @arg fileIndex @arg line refers to a breakpoint
*/
checkSourceLocation (fileIndex, line) {
if (this.breakpoints[fileIndex]) {
var sources = this.breakpoints[fileIndex]
for (var k in sources) { for (var k in sources) {
var source = sources[k] var source = sources[k]
if (currentLine === source.row) { if (line === source.row) {
return true return true
} }
} }
...@@ -48,6 +70,11 @@ class breakpointManager { ...@@ -48,6 +70,11 @@ class breakpointManager {
return false return false
} }
/**
* return true if current manager has breakpoint
*
* @return {Bool} true if breapoint registered
*/
hasBreakpoint () { hasBreakpoint () {
for (var k in this.breakpoints) { for (var k in this.breakpoints) {
if (this.breakpoints[k].length) { if (this.breakpoints[k].length) {
...@@ -57,20 +84,32 @@ class breakpointManager { ...@@ -57,20 +84,32 @@ class breakpointManager {
return false return false
} }
/**
* add a new breakpoint to the manager
*
* @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' }
*/
add (sourceLocation) { add (sourceLocation) {
if (!this.breakpoints[sourceLocation.file]) { if (!this.breakpoints[sourceLocation.file]) {
this.breakpoints[sourceLocation.file] = [] this.breakpoints[sourceLocation.file] = []
} }
this.breakpoints[sourceLocation.file].push(sourceLocation) this.breakpoints[sourceLocation.file].push(sourceLocation)
this.event.trigger('breakpointAdded', [sourceLocation])
} }
/**
* remove a breakpoint from the manager
*
* @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' }
*/
remove (sourceLocation) { remove (sourceLocation) {
if (this.breakpoints[sourceLocation.file]) { if (this.breakpoints[sourceLocation.file]) {
var sources = this.breakpoints[sourceLocation.file] var sources = this.breakpoints[sourceLocation.file]
for (var k in sources) { for (var k in sources) {
var source = sources[k] var source = sources[k]
if (sourceLocation.start === source.start && sourceLocation.length === source.length) { if (sourceLocation.row === source.row) {
sources.splice(k, 1) sources.splice(k, 1)
this.event.trigger('breakpointRemoved', [sourceLocation])
break break
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment