Check JS callback errors. Fixes #9

Thanks to Osmo Salomaa for the original report and test case.