Check for callback in makeAsyncHandler (#395)

This PR fixes regression from 3540972 and adds check for callback validity before putting it into event loop for sendAsync calls.
This commit is contained in:
Ivan Daniluk 2017-10-12 12:15:07 +03:00 committed by Ivan Tomilov
parent e6b426e094
commit d4496332f9
1 changed files with 5 additions and 3 deletions

View File

@ -75,10 +75,12 @@ func makeAsyncSendHandler(jail *Jail, cellInt common.JailCell) func(call otto.Fu
go func() {
response := jail.Send(call)
// run callback asyncronously with args (error, response)
callback := call.Argument(1)
err := otto.NullValue()
cell.CallAsync(callback, err, response)
if callback.Class() == "Function" {
// run callback asyncronously with args (error, response)
err := otto.NullValue()
cell.CallAsync(callback, err, response)
}
}()
return otto.UndefinedValue()
}