fix segfault when onload and onerror are not function