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?