[the pageforest.com blog] Back from PageForest Haitus

1 view
Skip to first unread message

Mike Koss

unread,
Jul 7, 2008, 5:09:10 PM7/7/08
to pagef...@googlegroups.com
That was a long time between posts. But StartPad.org is now up and running, and in the capable hands of Zach who's dealing with the day-to-day organization, so I'm getting to spend more time on PageForest.

I've also switched my application platform to Google AppEngine - I'm having a grand time learning Python and doing a bunch more JavaScript development.

I've spent quite a bit of time building on my JavaScript unit testing framework. I'm open-sourcing that code, I've made some significant improvements during PageForest development, so I should update the core project soon (hosted on Google Code).

I've been working so much in Firefox, I hadn't noticed that IE testing was getting stale. In general, the different browsers are very compatible when it comes to JavaScript - most of the platform differences are in HTML, CSS, and event models. The core language is very stanardized. But I have hit one major gottcha when it comes to IE: handling of empty elements at the end of an array definition.

As a (now) Python programmer, it's very common to define an (open ended) array as:
a = [1,2,3, ];
Note the dangling comma with no trailing element. In Firefox (and Python), this creates a 3 element array - the final comma is ignored. But, in IE, this creates a 4 element array with undefined as the 4th element.

An had used this paradigm extensively, w/o really realizing it. So when I switched to testing on IE recently, it took me quite a while to track down all these subtle bugs based on extra undefined elements added to my arrays.

JavaScript SHOULD be well enough defined that one of Firefox or IE is INCORRECT in their implementation of arrays (and I hope it's IE - since it's nice to be able to leave placeholders for future array elements in array definitions). Others have experience this problem too; the mozilla JavaScript documentation explicitly allows for it:
If you include a trailing comma at the end of the list of elements, the comma is ignored.
According to my reading of the ECMA-262 spec IE is non-conforming. Section 11.1.4 states:
Whenever a comma in the element list is not preceded by an AssignmentExpression (i.e., a comma at the beginning or after another comma), the missing array element contributes to the length of the Array and increases the index of subsequent elements. Elided array elements are not defined.
so, this definition:
a = [1,,2,];
should be equivalent to:
a = [1,undefined,2]; // Firefox - correct
but NOT:
a = [1,undefined,2,undefined]; // IE - incorrect
Your browser:






--
Posted By Mike Koss to the pageforest.com blog at 7/07/2008 01:33:00 PM
Reply all
Reply to author
Forward
0 new messages