1. make JS event handler can be changed during the dispatch routine
2. fix race condition for removing a running event handler.