src: use new loop API

uv_loop_new and uv_loop_delete are considered deprecated now.
src: emit 'beforeExit' event on process object

Unlike the 'exit' event, this event allows the user to schedule more
work and thereby postpone the exit.  That also means that the
'beforeExit' event may be emitted many times, see the attached test
case for an example.

Refs #6305.
doc: document `beforeExit` and add more tests
stream_wrap: don't write twice on uv_try_write err

fix #7155
Merge remote-tracking branch 'upstream/master'