On 2008.11.14., at 11:23, Hannes Wallnoefer wrote:

On Nov 14, 11:06 am, Attila Szegedi <[EMAIL PROTECTED]> wrote:
On 2008.11.14., at 10:58, Hannes Wallnoefer wrote:

It is true
that some of it is quirky, e.g getIds() returning strings for array
indices, but that's actually based on the ES spec IIRC.

Where does it do that? getIds() on NativeArray returns
java.lang.Integer instances, not java.lang.String.

Attila.

Sorry, I took David's word for it. But it sounded plausible to me
because in a JavaScript for-in loop, array indices _are_ enumerated as
strings. I remember vaguely finding an ES-spec based explanation for
that once, but I can't remember it, unfortunately :-)

js> var x = [1, 2, 3];
1,2,3
js> for (var i in x) print(typeof i, i);
string 0
string 1
string 2
js>

Oh, that's correct. According to ECMA-262 spec, JS arrays are associative arrays, and their property names are *still* strings, including the indices. It's just that there's a special invariant established between array indices (which are property names which happen to be decimal representations of nonnegative integer numbers) and the "length" property. The invariant states that the value of "length" is always numerically greater than (doesn't say by how much) the name of any other numeric-named property -- if you add a property whose name is not less than value of "length", length is increased to one greater. Conversely, if you set "length"'s value to be no greater than some existing numeric property names, those properties are deleted.

That arrays may have optimization for handling numeric indices is purely an implementation detail, and doesn't appear in the spec :-)

Attila.

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to