mirror of
https://github.com/robertkrimen/otto
synced 2025-10-05 19:19:10 +08:00
add a way to trigger something with debugger
This commit is contained in:
parent
8aa4915210
commit
7f15b1724e
|
@ -47,6 +47,9 @@ func (self *_runtime) cmpl_evaluate_nodeStatement(node _nodeStatement) Value {
|
|||
}
|
||||
|
||||
case *_nodeDebuggerStatement:
|
||||
if self.debugger != nil {
|
||||
self.debugger()
|
||||
}
|
||||
return emptyValue // Nothing happens.
|
||||
|
||||
case *_nodeDoWhileStatement:
|
||||
|
|
4
otto.go
4
otto.go
|
@ -341,6 +341,10 @@ func (self Otto) setValue(name string, value Value) {
|
|||
self.runtime.globalStash.setValue(name, value, false)
|
||||
}
|
||||
|
||||
func (self Otto) SetDebuggerHandler(fn func(vm *Otto)) {
|
||||
self.runtime.debugger = fn
|
||||
}
|
||||
|
||||
// Call the given JavaScript with a given this and arguments.
|
||||
//
|
||||
// If this is nil, then some special handling takes place to determine the proper
|
||||
|
|
|
@ -54,6 +54,7 @@ type _runtime struct {
|
|||
scope *_scope
|
||||
otto *Otto
|
||||
eval *_object // The builtin eval, for determine indirect versus direct invocation
|
||||
debugger func(*Otto)
|
||||
|
||||
labels []string // FIXME
|
||||
lck sync.Mutex
|
||||
|
|
|
@ -769,10 +769,16 @@ func TestClone(t *testing.T) {
|
|||
|
||||
func Test_debugger(t *testing.T) {
|
||||
tt(t, func() {
|
||||
test, _ := test()
|
||||
called := false
|
||||
|
||||
test(`
|
||||
debugger;
|
||||
`, "undefined")
|
||||
vm := New()
|
||||
vm.SetDebuggerHandler(func(o *Otto) {
|
||||
is(o, vm)
|
||||
called = true
|
||||
})
|
||||
|
||||
_, err := vm.Run(`debugger;`)
|
||||
is(err, nil)
|
||||
is(called, true)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user