Re: Type restriction of elements in Array

Speaking only for myself (although I am a member of TC39), as JS doesn't
allow this sort of restriction (without proxies, anyway), it's simply
non-sensical to enforce the behavior you're talking about in the generated
JS bindings. APIs that use/consume these array types should be what throw
errors.

Regards

On Tue, Oct 11, 2011 at 7:17 AM, Kisub Song <kisubs.song@samsung.com> wrote:

>  ECMAScript does not restricts the types of elements in arrays, in other
> words, any type value can be an element of native ECMAScript array.
>
> On the other hand, WebIDL allow to define arrays of specific data type.
>
> Even though the original ECMAScript does not support the type restriction
> of array, I can implement arrays that allow values of specific type as their
> elements. in case of platform array object.
>
>
>
> What I am wondering is that allowing only specific type value for an
> array is right policy or not.
>
> If it is right policy, what should happen if user try to assign wrong type
> value to an array?
>
>
>
> i.e.)
>
> <WebIDL>
>
> [NoInterfaceObject] interface TypeA {
>
>     attribute ...
>
> }
>
> [NoInterfaceObject] interface TypeB {
>
>     attribute ...
>
> }
>
> typedef TypeA[] TypeAArray;
>
>
>
> <ECMAScript>
>
> var as = getTypeAArray(); // returns array of TypeA.
>
> var b = getTypeB(); // returns value of TypeB.
>
>
>
> as[0] = b; // What should happen in this situation?
>
>            // exception? or silently ignoring?
>
>
>

Received on Monday, 17 October 2011 11:30:45 UTC