From https://bugs.webkit.org/show_bug.cgi?id=28004, we can factor out the getEventListener function and use templates instead.