fix segfault when Image::onload and Image::onerror are not function