Ticket #8272 (closed bug: fixed)
Exceptions in plain JS object event handlers swallowed by jQuery
| Reported by: | josh3736 | Owned by: | dmethvin |
|---|---|---|---|
| Priority: | high | Milestone: | 1.6 |
| Component: | event | Version: | 1.5 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
The fix implemented for #3533 caused a regression in jQuery 1.4.1 (and remains in 1.5). JavaScript exceptions thrown within a plain JS object's on<event> handler get caught and swallowed by event.js:378.
var Test = function() { this.onclick = function(e) { throw new Error('This exception will be swallowed.'); } }; var obj = new Test(); $(obj).click();
Full test case here. Note that changing jQuery back to 1.3.2 yields the expected behavior.
The exception is swallowed because the fix for #3533 was to wrap the call to on<event> handlers in a try/empty catch. I've created a patch which instead checks if the element being triggered is a <table> and if so, skip calling the on<event> function if the event type contains a colon.
My double-checking of the IE bug corrected by #3533 shows that <table> is the only element that triggers the bug.
Change History
comment:2 Changed 2 years ago by jitter
- Keywords needsreview added
- Priority changed from undecided to low
- Component changed from unfiled to event
comment:3 Changed 2 years ago by dmethvin
- Status changed from new to open
Further verification by josh that colon is the only deathchar: http://jsfiddle.net/josh3736/GVKqD/
comment:5 Changed 2 years ago by dmethvin
- Owner set to dmethvin
- Priority changed from low to high
- Status changed from open to assigned
- Milestone changed from 1.next to 1.6
comment:6 follow-up: ↓ 7 Changed 2 years ago by dmethvin
- Status changed from assigned to closed
- Resolution set to fixed
Fixes #8722. Remove try/catch used by #3533 to fix the IE Table Colon Blow bug, and instead check for colon in the event name. Thanks to daguej for scoping this out -- a colonoscopy you might say.
Changeset: 98d83ef85f41fefb40a14eec24c6804c088bbeeb
comment:7 in reply to: ↑ 6 Changed 2 years ago by josh3736
Replying to dmethvin:
Fixes #8722. Remove try/catch used by #3533 to fix the IE Table Colon Blow bug, and instead check for colon in the event name. Thanks to daguej for scoping this out -- a colonoscopy you might say.
Changeset: 98d83ef85f41fefb40a14eec24c6804c088bbeeb
Looks like you got the bug number wrong in the commit message (8722 instead of 8272).
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Patch submitted as pull request #231.