Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14481 closed bug (wontfix)

jQuery .trigger(event,args) barfs on {length:0} as handler argument

Reported by: marco@… Owned by:
Priority: low Milestone: None
Component: core Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:

Description

Hi!

jQuery 1.8.3 until at least jQuery 2.0.3 mess up the handling of event-handler parameters supplied via .trigger, when the parameter is an object with a "length" property.

In line 4556 (jquery-2.0.3.js, function "trigger", line jQuery.makeArray( data, [ event ])) jQuery makes an array out of the parameter object (why in fks name?)... and according to a painful single-step trace, the length property is extended onto the "new" data local variable... which causes the argument to vanish entirely and the handler not recieving it (setting a.length=0 will wipe the array clean!).

A test case is available at http://jsfiddle.net/MGxqT/1/ (see the JS console!). This behavior is neither mentioned on the docs of .trigger() nor on the docs of .on().

Marco

Change History (4)

comment:1 Changed 6 years ago by timmywil

Component: unfiledcore
Keywords: needsreview added
Priority: undecidedlow
Status: newopen

makeArray supports extending array-like objects (such as jQuery instances). However, we could ensure the object is not a plain object. I know we've gone round and round on this, but what are the team's thoughts?

comment:2 Changed 6 years ago by dmethvin

I'm not sure whether any code does .trigger("click", arguments) but if it did any "fix" would break that. So I'm inclined to leave it as-is and document it.

There's an easy workaround, always put the object in an Array, like [ {length: 0} ]. You have to pass an array if you pass multiple args, but it was made optional for the single-arg case and that has been a pain in the butt ever since because of things like this.

comment:3 Changed 6 years ago by timmywil

Keywords: needsreview removed
Resolution: wontfix
Status: openclosed

yea, agreed. Forgot about the arguments case.

Note: See TracTickets for help on using tickets.