update test_ccall to not use a postrun hook

This resolves https://github.com/kripken/emscripten/issues/1378

test_ccall was relying on the runtime being initialized during a postrun hook, which it isn't. However, the current FS system doesn't destroy the streams during its teardown so it manages to work.

I've added JS interfaces for adding oninit, onpremain and onexit events, and updated test_ccall to using an onexit hook instead of a postrun hook.

Also to note, `return 0;` had to be replaced by a call to `exit(0);` to make the runtime actually exit when using callMain (as discussed https://github.com/kripken/emscripten/pull/1444).