Bug Tracker

Opened 8 years ago

Closed 8 years ago

#8513 closed bug (invalid)

Infinite loop when calling .each() on a null element

Reported by: adrian.silimon@… Owned by: adrian.silimon@…
Priority: undecided Milestone: 1.next
Component: core Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Description

I noticed then when you call a jQuery('.unexistent-selector').each(function(){ ... do smthing ...}); generates an infinite loop. I marked this as a bug, as I think this should not happen since the element does not exists in the DOM tree. I think it would be better to raise an "undefined" exception - so notice the user that the element(s) he wants to iterate through could't be found.

Change History (2)

comment:1 Changed 8 years ago by Rick Waldron

Component: unfiledcore
Owner: set to adrian.silimon@…
Status: newpending

I cannot reproduce the error.

http://jsfiddle.net/rwaldron/yKVW8/

If you believe this is an incorrect assessment, please provide a reduced jsFiddle test case!

Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.

comment:2 Changed 8 years ago by addyosmani

Resolution: invalid
Status: pendingclosed

Using rwaldron's test case above, I haven't been able to replicate this issue either. There doesn't seem to be any evidence of an infinite loop occurring. In addition, although there are a number of cases where we potentially could output an undefined exception internally, if you absolutely need this you could easily test for element existence prior to using $.each manually.

Note: See TracTickets for help on using tickets.