Fix handling of listeners added and removed mid-dispatch

Before, having the last event listener remove itself (to implement
EventEmitter.prototype.once-like semantics) threw an exception. Fix this by
making a copy of the listener list on dispatch. While we're at it, mimic the
semantics of the real DOM EventTarget interface. Event listeners added
mid-dispatch do not run until the next one, however listeners removed, if they
have not yet run, will not run in the current one.

Also adds a unit test to test this behavior.