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

Fixes #2862. r? @Ms2ger