Don't fail on invalid JS syntax in event handlers.

Fixes #2862.