-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.go
More file actions
68 lines (59 loc) · 1.69 KB
/
Copy pathdebugger.go
File metadata and controls
68 lines (59 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package patchright
import "sync"
type debuggerImpl struct {
channelOwner
mu sync.RWMutex
pausedDetails *PausedDetail
}
func (d *debuggerImpl) OnPausedStateChanged(fn func()) {
d.On("pausedStateChanged", fn)
}
func (d *debuggerImpl) PausedDetails() (*PausedDetail, error) {
d.mu.RLock()
defer d.mu.RUnlock()
return d.pausedDetails, nil
}
func (d *debuggerImpl) RequestPause() error {
_, err := d.channel.Send("requestPause")
return err
}
func (d *debuggerImpl) Resume() error {
_, err := d.channel.Send("resume")
return err
}
func (d *debuggerImpl) Next() error {
_, err := d.channel.Send("next")
return err
}
func (d *debuggerImpl) RunTo(location DebuggerLocation) error {
_, err := d.channel.Send("runTo", map[string]any{"location": location})
return err
}
func newDebugger(parent *channelOwner, objectType string, guid string, initializer map[string]any) *debuggerImpl {
bt := &debuggerImpl{}
bt.createChannelOwner(bt, parent, objectType, guid, initializer)
bt.channel.On("pausedStateChanged", func(params map[string]any) {
bt.mu.Lock()
if pd, ok := params["pausedDetails"]; ok && pd != nil {
data := pd.(map[string]any)
detail := &PausedDetail{Title: data["title"].(string)}
if loc, ok := data["location"].(map[string]any); ok {
detail.Location = &PausedDetailLocation{File: loc["file"].(string)}
if line, ok := loc["line"]; ok && line != nil {
v := int(line.(float64))
detail.Location.Line = &v
}
if col, ok := loc["column"]; ok && col != nil {
v := int(col.(float64))
detail.Location.Column = &v
}
}
bt.pausedDetails = detail
} else {
bt.pausedDetails = nil
}
bt.mu.Unlock()
bt.Emit("pausedStateChanged")
})
return bt
}