Bug Tracker

Ticket #9357 (closed bug: fixed)

Opened 4 years ago

Last modified 3 years ago

'mouseenter' event handling swallows exceptions on withinElement

Reported by: bryan@… Owned by:
Priority: high Milestone: 1.next
Component: event Version: 1.6.1
Keywords: Cc:
Blocking: Blocked by:

Description

This was previously reported 'fixed' in jquery 1.4: http://bugs.jquery.com/ticket/5514 but seems to have regressed.

Given the following code:

$('a#id').bind('mouseenter', function() {
    aler('bar');
});

JSFiddle:  http://jsfiddle.net/3X2tg/6/

When triggering the 'mouseenter' event, no error message is printed to console. It appears the exception is being simply being swallowed here:

// Checks if an event happened on an element within another element
// Used in jQuery.event.special.mouseenter and mouseleave handlers
var withinElement = function( event ) {
	// Check if mouse(over|out) are still within the same parent element
	var parent = event.relatedTarget;

	// set the correct event type
	event.type = event.data;

	// Firefox sometimes assigns relatedTarget a XUL element
	// which we cannot access the parentNode property of
	try {

		// Chrome does something similar, the parentNode property
		// can be accessed but is null.
		if ( parent && parent !== document && !parent.parentNode ) {
			return;
		}

		// Traverse up the tree
		while ( parent && parent !== this ) {
			parent = parent.parentNode;
		}

		if ( parent !== this ) {
			// handle event if we actually just moused on to a non sub-element
			jQuery.event.handle.apply( this, arguments );
		}

	// assuming we've left the element since we most likely mousedover a xul element
	} catch(e) { }
}

As detailed in the previous ticket, it appears the apply() call should probably be moved outside of the try/catch block.

Thanks.

Change History

comment:2 Changed 4 years ago by rwaldron

  • Priority changed from undecided to high
  • Status changed from new to open
  • Component changed from unfiled to event

comment:3 Changed 4 years ago by dmethvin

Thanks, Bryan! I agree that moving the event call out of the try/catch seems like the right solution.

comment:4 Changed 4 years ago by rwaldron

Tested this pull request, full pass.

 https://github.com/jquery/jquery/pull/395/

comment:5 Changed 3 years ago by rwldrn

  • Status changed from open to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.