The jQuery JavaScript Implementation Quality Metric
Wednesday, 16. January 2008, 23:08:44
It is a metric for the quality of a JavaScript implementation, and works on three assumptions:
- jQuery is a sizable and representative body of cross-browser JavaScript.
- It is documented in the jQuery source, when ever something will trip up, or surprise a JavaScript developer - quirks of the particular implementation.
- These quirks are bad, and therefor, the fewer the better.
In short: the fewer times a particular browsers name is mentioned in the jQuery source code, the better its JavaScript implementation is expected to be.
Bold claim? perhaps. Like all metrics, it should be taken with a grain of salt, and two grains of pepper.
Onwards! To the Numbers!
First contender is my favorite browser of them all: Opera. Let's see how it fares:
$ grep "Opera" jquery-1.2.2.js -c 7
Seven remarks. Well, eh. I suppose it could be worse. Let's keep an open mind for now, and remember that the upcoming version 9.5 has a completely revamped JavaScript engine that is rumored to be quite good.
Looking at market share, I'd say that Safari is probably Opera's closest contender. Safari also had its JavaScript engine revised in its version 3. Let's see if the boat floats.
$ grep "Safari" jquery-1.2.2.js -c 6
Woops! Looks like Safari is one-upping Opera on this test. Let's just hope that the Mac fanboys at work don't get hold of this data - I'd be havoc on my browser pride.
Scaling up on market share yet again, I think the Gekko browsers comes next. Mozilla and Firefox both have the same Spidermonkey JavaScript engine, so I'll consider them as one.
$ grep "Mozilla\|Firefox" jquery-1.2.2.js -c 8
Considering that Mozilla and namely Firefox has several truckloads more market share than Opera and Safari combined, I'd say that this result is quite encouraging.
Last on our list is the king of market share: Internet Explorer. It's been lambasted for almost a decade as the number one perpetrator in strangling innovation and holding the Internet back, but do these harsh claims stand a beatin'?
$ grep "IE" jquery-1.2.2.js -c 40
Woops. I suppose market share isn't the only area where IE is in the lead, it's pretty far ahead of the other browsers in quirk-count as well.
Since Opera, Safari and Mozilla/Firefox are so close to each other in this test, I don't think I'll declare a winner - if one of these browsers are your favorite, then feel free to think of it as a winner.
So now that we don't have any outstanding winners, it's time to ridicule the loser... by changing the "-c" to a "-n" in the grep command. Notice there's a couple of memory leaks mentioned in the output as well:
$ grep "IE" jquery-1.2.2.js -n|perl -p -e "s/\\s+/ /"
65: // Handle the case where IE and Opera return items
298: // IE copies events bound via attachEvent when
303: // attributes in IE that are actually only stored
317: // removeData doesn't work here, IE removes it from the original as well
318: // this is primarily for IE but the data expando shouldn't be copied over in any browser
697: // IE has trouble directly removing the expando
823: // We need to handle opacity special in IE
924: // !context.createElement fails in IE with an error but returns typeof 'object'
968: // IE can't serialize <link> and <script> tags normally
981: // Remove IE's autoinserted <tbody> from table fragments
997: // IE completely kills leading whitespace when innerHTML is used
1047: // IE elem.getAttribute passes even for style
1051: // We can't allow the type property to be changed (since it causes problems in IE)
1055: // convert the value to a string (all browsers do this but IE) see #1070
1066: // IE actually uses filters for opacity
1069: // IE has trouble with opacity if it does not have layout
1120: // We have to loop this way because IE & Opera overwrite the length
1124: // (IE returns comment nodes in a '*' query)
1566: // to avoid selecting by the name attribute in IE
1580: // Handle IE7 being really dumb about <object>s
1808: // For whatever reason, IE has trouble passing the window object
1852: // event in IE.
1889: // Nullify elem to prevent memory leaks in IE
2015: // prevent IE from throwing an error for some hidden elements
2060: // Clean up added properties in IE to prevent memory leak
2080: // otherwise set the returnValue property of the original event to false (IE)
2087: // otherwise set the cancelBubble property of the original event to true (IE)
2293: // If IE is used and is not in a frame
2298: // If IE is used, use the trick by Diego Perini
2299: // http://javascript.nwbox.com/IEContentLoaded/
2365:// Prevent memory leaks in IE
2417: // to avoid any 'Permission Denied' errors in IE
2595: // IE likes to send both get and post data, prevent this
2637: // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
2795: // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
3307: // IE adds the HTML element's border, by default it is medium which is 2px
3308: // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
3309: // IE 7 standards mode, the border is always 2px
3311: // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
3312: // Therefore this method will be off by 2px in IE while in quirksmode


