Closed Bug 801988 Opened 13 years ago Closed 13 years ago

NaN error in Firefox 16 when trying to call parseInt(null) because old jQuery returned the microdata itemValue (null), not the itemValue attribute

Categories

(Core :: General, defect)

16 Branch
x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: eric, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0 Build ID: 20121010144125 Steps to reproduce: 1. Go to http://www.googleanalyticstest.com/setup.aspx?wo=tr 2. Check the Select All Categories checkbox or any of the individual category checkboxes. Actual results: In Firefox 16, NaN is showing instead of total questions available. Expected results: The number of questions available should appear at the bottom of the page. (Current total is 225.) Analytics for the past week is showing that users with previous versions of Firefox are still getting through this page at the normal rate while no Firefox 16 users are.
Last good nightly: 2012-06-05 First bad nightly: 2012-06-06 Pushlog: http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=a7a905fd70d5&tochange=6338a8988917
Status: UNCONFIRMED → NEW
Component: Untriaged → General
Ever confirmed: true
Product: Firefox → Core
microdata API landed in that range... Eric, is this your page? If so, what script runs when that checkbox is checked?
Oh, nevermind. What runs is the calculate() function in the main page. And the problem there is that it does this: countSelected += parseInt($(this).parent().attr('itemValue')); which is best described as "out-of-date jQuery just shot you in the foot". The problem is that attr() in jQuery 1.4.2 works like so: // If applicable, access the attribute via the DOM 0 way if ( name in elem && notxml && !special ) { // Some special-casing gunk here that doesn't apply in our case return elem[ name ]; } // Fall back on getAttribute And microdata API adds a property called "itemValue" on all elements. The return value of this property is defined by http://www.whatwg.org/specs/web-apps/current-work/multipage/microdata.html#dom-itemvalue and in particular the relevant bit is: If the element has no itemprop attribute The attribute must return null on getting and must throw an InvalidAccessError exception on setting. So the above code calls parseInt(null), which is the same thing as parseInt("null"), which is NaN. Hence countSelected ends up as NaN. I just checked the current jQuery version (1.8.2) and it looks like they have fixed attr() to use getAttribute if available, which incidentally makes this page work if that version of jQuery is used.
Blocks: 591467
Summary: NaN error in Firefox 16 → NaN error in Firefox 16 when trying to call parseInt(null) because old jQuery returned the microdata itemValue (null), not the itemValue attribute
Boris (and Matthias), thanks for the quick response. I'll make sure to upgrade to jQuery 1.8.2.
Thanks Boris, that saved me from bisecting...
Just want to confirm that jQuery 1.8.2 took care of the problem (in Firefox 16 and in Opera 11.64 as well). Thanks again for the very speedy help - I really appreciate it.
Eric, you're very welcome! Thank you for the bug report. Marking invalid, assuming the spec on this won't change...
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.