[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] TypedArray constructors and zero length



On Thu, Jun 10, 2010 at 02:29, Vladimir Vukicevic <vladimir@mozilla.com> wrote:
>
> A zero-length array still has a .buffer property, which has to be non-null -- thus it has to be of zero size if the array was created with 'new Int32Array(0);'.  The behaviour of malloc(0) isn't really relevant, though, as the underlying implementation can just have its raw data pointer be NULL without ever calling malloc; ArrayBuffer itself still needs additional metadata inside an implementation, so it can't ever just be a bare chunk of memory.

Okay, so this needs some minimal special casing in implementations
indeed, thanks!


About negative values I'm still confused about what to do however.

WebIDL ECMAscript conversion rules refers to ToUint32 in ECMA-262v5
(section 9.6) which does not appear to possibly generate an error (as
in C-style casting in some way).

Interestingly ECMA262 specifies "new Array(len)" with the following :
"""
If the argument len is a Number and ToUint32(len) is not equal to len,
a RangeError exception is thrown.
"""
Which certainly confirms ToUint32 does not generate an error, as the
case of negative value as well as NaN and other things is specified
here.


WebIDL Java conversion rules are clearer about this and indeed only
C-style casting is implied by WebIDL (section 5.2.8) :
"""
In Java this is the same as performing a bit-wise AND of the int value
with the long constant 0xffffffffL.
"""

This means that for instance passing -1 to a TypedArray constructor
would not generate an error and be equivalent to passing 268435455 as
length...


Should we replace type of length with "long" instead so that we can
generate an error in case a negative value is passed ?

Or perhaps this needs modification in WebIDL spec and/or addition of a
stricter conversion rule parameter attribute (ie. possibly raising
TYPE_ERR or OverflowException) ?


Regards,

-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: