- From: Oliver Hunt <oliver@apple.com>
- Date: Mon, 2 Aug 2010 13:24:53 -0700
On Aug 2, 2010, at 12:57 PM, Garrett Smith wrote: > I also linked to the old "catchalls" proposal earlier in the thread. > That is because the host objects mentioned here have a specialized > "catchall" behavior that isn't yet defined by any specification, so > when the code has property access with an integer index, as: anObj[2] > - then it's supposed to be the same as a call to the `item` method. > That mostly works, but isn't specified isn't completely and isn't > completely interoperable due to variance in undefined vs null. > > I noticed that rather than define catchall, HTML5 copied the old DOM text: > > | In the ECMAScript DOM binding, objects implementing the > | HTMLFormControlsCollection interface must support being > | dereferenced using the square bracket notation, such that dereferencing > | with an integer index is equivalent to invoking the item() method with that > | index, and such that dereferencing with a string index is equivalent to > | invoking the namedItem() method with that index. > > The problem with that is that property access doesn't do any > typechecking, and so > obj[2] > - is equivalent to:- > obj["2"] > > Can it be argued as to what "integer index" means? And what is a "string index"? It does seem a little weird as EcmaScript does not distinguish between string and non-string property names, the special handling of "numeric" indices inside the [[GetOwnProperty]]/[[PutOwnProperty]] methods of those types that have special handling, in those types the special "numeric index" path is hit if the property name is an "Array index", which is defined as (pseudo code) bool isArrayIndex(String property) { unsigned index = ToUint32(property); return ToString(index) == property && index >= 0 && index < 0xFFFFFFFF; } > Garrett --Oliver
Received on Monday, 2 August 2010 13:24:53 UTC