Technically all access works like that: a[4] looks up the property "4" in a exactly the same way it would look up "-1" or "foo". Javascript as it is today doesn't have a concept of out-of-range, and in the cases where it has something that resembles it it doesn't cause an error. For instance, if you have
Object.prototype[10000] = 10000; var x = [0, 1, 2]; then x[10000] = 10000, even though x.length = 3. It violates the principle of least surprise that canvas arrays behaves differently. On Wed, Oct 21, 2009 at 11:08 AM, Kenneth Russell <[email protected]> wrote: > I am going to take out this code altogether. When we specified in the WebGL > working group that out-of-range accesses raise exceptions for the new > CanvasArray types, we didn't realize that JavaScript defines array indices > to be unsigned. An access to index -1 causes -1 to be converted to a string > and resolved as a property lookup. It's portable at least between V8 and JSC > to write > canvas_float_array[-1] = 'foo'; > canvas_float_array[-1]; > and get "foo" as the result -- if this explicit check is removed. I've > raised this as a specification issue on the Khronos 3dweb mailing list and > will send out a review removing this code. > -Ken > --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
