1
0
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:
deoxxa 2015-12-03 15:37:01 +11:00
parent 8aa4915210
commit 7f15b1724e
4 changed files with 18 additions and 4 deletions

View File

@ -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:

View File

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

View File

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

View File

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