fix: fixed vm locking

This commit is contained in:
Simone Margaritelli 2021-04-04 15:58:48 +02:00
commit 2b1ff7d59f
3 changed files with 35 additions and 31 deletions

View file

@ -1,9 +1,8 @@
package session
import (
"github.com/evilsocket/islazy/plugin"
_ "github.com/bettercap/bettercap/js"
"github.com/evilsocket/islazy/plugin"
)
type Script struct {

View file

@ -56,9 +56,12 @@ func jsOnEventFunc(call otto.FunctionCall) otto.Value {
for event := range listener {
if expr == "" || event.Tag == expr {
// lock vm
I.script.Lock()
if _, err := cb.Call(otto.NullValue(), event); err != nil {
I.Events.Log(log.ERROR, "error dispatching event %s: %v", event.Tag, err)
}
I.script.Unlock()
}
}
}(filterExpr, cb)