on_close and on_error events fixed

 Enhaced/fixed js library. Now on_close and on_error events pass the event straight. Tests added and fixed for this too. :)