archives

« Bugzilla Issues Index

#2830 — 6.1.7 The Object Type: Not necessary to special case "-0" for array indices


6.1.7 The Object Type

The def. for array indices special cases `-0`. This is not necessary because integer indices only include +0 and integers greater than +0.


Or does the definition is supposed to read:
---
An integer index is String-valued property key that is a canonical numeric string (see 7.1.16) and whose _canonical_ numeric value is either +0 or a positive integer.

An array index is an integer index whose numeric value i is in the range 0 ≤ i < 2^32 -1 and i ≠ -0.
---

Note: Changed "numeric value" to "canonical numeric value" in the integer index definition.


The distinction between "numeric value" and "canonical numeric value" is necessary to explain the (current) differences between `[7]["-0"]` and `new Int8Array([7])["-0"]`. The former expression evaluates to `undefined` whereas the latter evaluates to `7` according to the rev24 draft.


fixed in rev25 editor's draft

by redefining how "-0" is handled in CannonicalNumericString (now called CannonicalNumericIndexString) and its callers.

I think we want `[7]["-0"]` and `new Int8Array([7])["-0"]` to both consistently evaluate to undefined. However, we don't want `new Int8Array([7])["-0"]="foo"` to create a "-0" expando property; even though it must (backwards compat.) for `[7]["-0"]="foo";`

The rev25 changes address this.

Finally, remember that `x[0]` and `x[-0]` always mean the same thing because ToString(-0) is "0" and ToString is applied to property keys before invoking the [[Get]] or [[Set]] internal method.


fixed in rev25 editor's draft