On 1/26/2010 7:30 AM, Chris Marrin wrote:
It made the table ugly :-) The sentence right above the table stats that the size is equivalent to the BYTES_PER_ELEMENT constant -- is that enough?
Yeah, I wanted to wait until we saw where this would land, though I guess no matter what we'd have to have some WebIDL to describe the interface that the types should conform to..
My worry is that the semantics are different with this slice and normal Array.slice() -- Array.slice() will return a copy that you can then modify without changing the original, whereas this wouldn't.
It is, but pretty ugly and convoluted. Adding a slice() method to ArrayBuffer would work though, what do you think?
I was actually thinking about methods like fromLittleEndian(), fromBigEndian(), fromNetworkEndian(), and the opposite toLittleEndian etc. That would convert the data based on intent ("I have big endian data and I want it in the platform endian"). Though I'd once again fall back on a generic byteSwap(), since from/to don't give you a way to just say "I want data in opposite-endian to what it is now". fromOtherEndian/toOtherEndian? :-)
I don't really like having a constructor for it, because it would mean that the constructor actually does work -- all the other constructors just create a view and don't touch the actual data. Something like:
var ints1 = new Int32Array(bytes, NetworkOrder);
var ints2 = new Int32Array(bytes, NetworkOrder);
Would end up swapping the array twice, which seems unexpected to me.
Hmm, or are you suggesting that the byte swapping be done at access time? Now that I think about it, that might be required -- otherwise you couldn't access a complex data structure (e.g. packed ints, shorts, etc.) because you wouldn't be able to easily say "byte swap all the ints" or somesuch.
That's my concern as well -- Brendan and Arun suggested that we try ECMA first, and if it doesn't look like they're interested and/or if they can't move quickly, then look at alternatives. The problem was that it didn't really seem to fit into any of the W3C groups; the WebApps group is probably the closest as a catch-all, but I don't think its charter would encompass something like this. A new group could certainly be started, but that's even more time..