Ticket #8008 (closed bug: invalid)
function each launch an error when the object is empty on verion 1.4.4
| Reported by: | sirio3mil@… | Owned by: | sirio3mil@… |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | misc | Version: | 1.4.4 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
The expression $.each(data, function(key, value) {}); launch an error in case of data is empty or null:
On Google Chrome 10 the error is: function length can´t be applied to a null value
On Mozilla Firefox 3.6.13 the error es: (jquery minified) variable j is null; (standard jquery) variable object is null
I think it not happend on jquery 1.4 cuz error appear only when I update to 1.4.4
Change History
comment:1 Changed 2 years ago by addyosmani
- Owner set to sirio3mil@…
- Status changed from new to pending
comment:2 Changed 2 years ago by sirio3mil@…
- Status changed from pending to new
Itís imposible reproduce exactly on jsFiddle cuz they validate when isn't a correct json
My case is like http://jsfiddle.net/sirio3mil/ndGsV/
But you cann´t see the error in that url so you can see the in something like this http://jsfiddle.net/sirio3mil/WqHX9/
Hoping to be usefull
comment:4 Changed 2 years ago by sirio3mil@…
the point isn´t that I send an invalid object (it was a problem in my code) the point is in jquery 1.4 the script don´t launch an error cuz the object is empty or null but in 1.4.4 the script launch an unexpected error, thats the point
comment:5 Changed 2 years ago by jitter
- Priority changed from undecided to low
- Resolution set to invalid
- Status changed from new to closed
- Component changed from unfiled to misc
This test case shows that jQuery.each always throws an error when it gets passed null as argument (in all 1.4.X versions and the current 1.5b1 release). So the behavior is consistent across versions.
Anyway this wouldn't be a bug as passing null to jQuery.each isn't a valid thing to do according to the API and is thus bound to trigger unspecified behavior or throw an exception.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Thanks for submitting a ticket to the jQuery Bug Tracker!. Please provide a reduced jsFiddle.net test case that reproduces the issue to help us fully evaluate your ticket.